diff --git a/PROMS/Formats/fmtall/BNPP1Newall.xml b/PROMS/Formats/fmtall/BNPP1Newall.xml index d13df054..a8c9c4b5 100644 Binary files a/PROMS/Formats/fmtall/BNPP1Newall.xml and b/PROMS/Formats/fmtall/BNPP1Newall.xml differ diff --git a/PROMS/Formats/genmacall/BNPP1new.svg b/PROMS/Formats/genmacall/BNPP1new.svg index 675ac04d..e32a19e5 100644 Binary files a/PROMS/Formats/genmacall/BNPP1new.svg and b/PROMS/Formats/genmacall/BNPP1new.svg differ diff --git a/PROMS/VEPROMS User Interface/frmBatchRefresh.Designer.cs b/PROMS/VEPROMS User Interface/frmBatchRefresh.Designer.cs index 022a0186..02bb7edd 100644 --- a/PROMS/VEPROMS User Interface/frmBatchRefresh.Designer.cs +++ b/PROMS/VEPROMS User Interface/frmBatchRefresh.Designer.cs @@ -200,6 +200,7 @@ this.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.txtResults.Size = new System.Drawing.Size(489, 473); this.txtResults.TabIndex = 4; + this.txtResults.TextChanged += new System.EventHandler(this.txtResults_TextChanged); // // panel1 // @@ -312,6 +313,7 @@ this.txtProcess.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.txtProcess.Size = new System.Drawing.Size(291, 375); this.txtProcess.TabIndex = 5; + this.txtProcess.TextChanged += new System.EventHandler(this.txtProcess_TextChanged); // // pbProcess // @@ -340,7 +342,7 @@ this.panel3.Dock = System.Windows.Forms.DockStyle.Top; this.panel3.Location = new System.Drawing.Point(0, 23); this.panel3.Name = "panel3"; - this.panel3.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.panel3.Padding = new System.Windows.Forms.Padding(6); this.panel3.Size = new System.Drawing.Size(291, 79); this.panel3.TabIndex = 2; // @@ -353,7 +355,7 @@ this.pnlLater.Enabled = false; this.pnlLater.Location = new System.Drawing.Point(6, 23); this.pnlLater.Name = "pnlLater"; - this.pnlLater.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.pnlLater.Padding = new System.Windows.Forms.Padding(6); this.pnlLater.Size = new System.Drawing.Size(279, 37); this.pnlLater.TabIndex = 3; // @@ -484,7 +486,7 @@ this.sideNavItmExit}); this.sideNav1.Location = new System.Drawing.Point(0, 0); this.sideNav1.Name = "sideNav1"; - this.sideNav1.Padding = new System.Windows.Forms.Padding(1, 1, 1, 1); + this.sideNav1.Padding = new System.Windows.Forms.Padding(1); this.sideNav1.Size = new System.Drawing.Size(385, 525); this.sideNav1.TabIndex = 3; this.sideNav1.Text = "sideNav1"; @@ -501,7 +503,7 @@ this.sideNavPanel4.Location = new System.Drawing.Point(81, 31); this.sideNavPanel4.MinimumSize = new System.Drawing.Size(0, 493); this.sideNavPanel4.Name = "sideNavPanel4"; - this.sideNavPanel4.Size = new System.Drawing.Size(300, 493); + this.sideNavPanel4.Size = new System.Drawing.Size(299, 493); this.sideNavPanel4.TabIndex = 27; // // swDeleteFolder @@ -572,7 +574,7 @@ this.myTVdel.Dock = System.Windows.Forms.DockStyle.Bottom; this.myTVdel.Location = new System.Drawing.Point(0, 126); this.myTVdel.Name = "myTVdel"; - this.myTVdel.Size = new System.Drawing.Size(300, 367); + this.myTVdel.Size = new System.Drawing.Size(299, 367); this.myTVdel.TabIndex = 34; this.myTVdel.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.myTV_AfterCheck_DelAnn); // @@ -585,7 +587,7 @@ this.btnDeleteItems.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; this.btnDeleteItems.Location = new System.Drawing.Point(39, 98); this.btnDeleteItems.Name = "btnDeleteItems"; - this.btnDeleteItems.Size = new System.Drawing.Size(221, 23); + this.btnDeleteItems.Size = new System.Drawing.Size(220, 23); this.btnDeleteItems.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; this.superTooltip1.SetSuperTooltip(this.btnDeleteItems, new DevComponents.DotNetBar.SuperTooltipInfo("Process Deletions", "", resources.GetString("btnDeleteItems.SuperTooltip"), null, null, DevComponents.DotNetBar.eTooltipColor.Gray, true, true, new System.Drawing.Size(200, 175))); this.btnDeleteItems.TabIndex = 35; @@ -649,7 +651,7 @@ this.warningBox5.CloseButtonVisible = false; this.warningBox5.Image = ((System.Drawing.Image)(resources.GetObject("warningBox5.Image"))); this.warningBox5.Location = new System.Drawing.Point(17, 145); - this.warningBox5.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.warningBox5.Margin = new System.Windows.Forms.Padding(4); this.warningBox5.Name = "warningBox5"; this.warningBox5.OptionsButtonVisible = false; this.warningBox5.Size = new System.Drawing.Size(262, 32); @@ -733,7 +735,7 @@ this.warningBox1.CloseButtonVisible = false; this.warningBox1.Image = ((System.Drawing.Image)(resources.GetObject("warningBox1.Image"))); this.warningBox1.Location = new System.Drawing.Point(17, 181); - this.warningBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.warningBox1.Margin = new System.Windows.Forms.Padding(4); this.warningBox1.Name = "warningBox1"; this.warningBox1.OptionsButtonVisible = false; this.warningBox1.Size = new System.Drawing.Size(262, 43); @@ -782,7 +784,7 @@ this.warningBox3.CloseButtonVisible = false; this.warningBox3.Image = ((System.Drawing.Image)(resources.GetObject("warningBox3.Image"))); this.warningBox3.Location = new System.Drawing.Point(17, 207); - this.warningBox3.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.warningBox3.Margin = new System.Windows.Forms.Padding(4); this.warningBox3.Name = "warningBox3"; this.warningBox3.OptionsButtonVisible = false; this.warningBox3.Size = new System.Drawing.Size(264, 32); @@ -986,7 +988,7 @@ this.warningBox4.CloseButtonVisible = false; this.warningBox4.Image = ((System.Drawing.Image)(resources.GetObject("warningBox4.Image"))); this.warningBox4.Location = new System.Drawing.Point(12, 264); - this.warningBox4.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.warningBox4.Margin = new System.Windows.Forms.Padding(4); this.warningBox4.Name = "warningBox4"; this.warningBox4.OptionsButtonVisible = false; this.warningBox4.Size = new System.Drawing.Size(264, 32); @@ -999,7 +1001,7 @@ this.warningBox2.CloseButtonVisible = false; this.warningBox2.Image = ((System.Drawing.Image)(resources.GetObject("warningBox2.Image"))); this.warningBox2.Location = new System.Drawing.Point(12, 302); - this.warningBox2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.warningBox2.Margin = new System.Windows.Forms.Padding(4); this.warningBox2.Name = "warningBox2"; this.warningBox2.OptionsButtonVisible = false; this.warningBox2.Size = new System.Drawing.Size(264, 43); diff --git a/PROMS/VEPROMS User Interface/frmBatchRefresh.cs b/PROMS/VEPROMS User Interface/frmBatchRefresh.cs index a5205909..95cf43ae 100644 --- a/PROMS/VEPROMS User Interface/frmBatchRefresh.cs +++ b/PROMS/VEPROMS User Interface/frmBatchRefresh.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; @@ -10,7 +8,6 @@ using System.IO; using Volian.Controls.Library; using DevComponents.DotNetBar; using JR.Utils.GUI.Forms; -using Volian.Controls.Library; using System.Linq; namespace VEPROMS @@ -342,6 +339,8 @@ namespace VEPROMS pbProcess.PerformStep(); Application.DoEvents(); } + + ClearCache(); } Application.DoEvents(); @@ -389,6 +388,23 @@ namespace VEPROMS this.Cursor = Cursors.Default; } + //C2025-011 RO Update Admin Tool Memory Enhancements + //Clear what we can from the cache + //runs after each section + private void ClearCache() + { + txtProcess.AppendText("Reclaiming memory used during previous sections."); + + PartInfo.ClearPartInfoCache(); + ItemInfo.ClearItemInfoCache(); + Item.ClearItemCache(); + ContentInfo.ClearContentInfoCache(); + GridInfo.ClearGridInfoCache(); + + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + //C2022-028 check for Bad RO Links - we will check all of the RO links found in procedure step text //B2022-144 Allow to check individual procedures for bad RO links private void CheckROLinks() @@ -1002,6 +1018,9 @@ namespace VEPROMS txtResults.AppendText(Environment.NewLine); txtResults.AppendText(Environment.NewLine); } + //C2025-011 RO Update Admin Tool Memory Enhancements + //clear the list since no longer using it + myItems.Clear(); DateTime pEnd = DateTime.Now; txtProcess.AppendText(string.Format("Completed: {0}", pEnd.ToString("MM/dd/yyyy @ HH:mm"))); txtProcess.AppendText(Environment.NewLine); @@ -1088,6 +1107,7 @@ namespace VEPROMS } roFstInfo.ROTableUpdate += new ROFstInfoROTableUpdateEvent(roFstInfo_ROTableUpdate); ROFst newrofst = ROFstInfo.RefreshROFst(dv, roFstInfo, DoProgressBarRefresh, txtProcess); + //ROFst newrofst = ROFstInfo.RefreshROFst(dv, roFstInfo, DoProgressBarRefresh, null); roFstInfo.ROTableUpdate -= new ROFstInfoROTableUpdateEvent(roFstInfo_ROTableUpdate); } @@ -1976,7 +1996,20 @@ namespace VEPROMS pil.Add(myProcedures[tn]); return pil; } - } + + //C2025-011 RO Update Admin Tool Memory Enhancements + private void txtProcess_TextChanged(object sender, EventArgs e) + { + //clears the stack to help with memory - should never need to undo text changes to this. + txtProcess.ClearUndo(); + } + + private void txtResults_TextChanged(object sender, EventArgs e) + { + //clears the stack to help with memory - should never need to undo text changes to this. + txtResults.ClearUndo(); + } + } } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs index d4cf5397..af4fe9a2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs @@ -49,29 +49,35 @@ namespace VEPROMS.CSLA.Library { if (DocVersionAssociations == null || DocVersionAssociations.Count == 0) return false; - ROFstInfo roFstInfo = ROFstInfo.GetJustROFst(DocVersionAssociations[0].ROFstID); + using (ROFstInfo roFstInfo = ROFstInfo.GetJustROFst(DocVersionAssociations[0].ROFstID)) + { + using (RODbInfo rdi = RODbInfo.GetJustRODB(roFstInfo.RODbID)) + { + string rofstPath = rdi.FolderPath + @"\ro.fst"; + if (!File.Exists(rofstPath)) return false; - RODbInfo rdi = RODbInfo.GetJustRODB(roFstInfo.RODbID); - string rofstPath = rdi.FolderPath + @"\ro.fst"; - if (!File.Exists(rofstPath)) return false; + FileInfo fiRofst = new FileInfo(rofstPath); - FileInfo fiRofst = new FileInfo(rofstPath); + // if the database Ro.Fst is newer or if the files have identical DTS, + // assume that they are the same file. + if (roFstInfo.DTS >= fiRofst.LastWriteTimeUtc) return false; - // if the database Ro.Fst is newer or if the files have identical DTS, - // assume that they are the same file. - if (roFstInfo.DTS >= fiRofst.LastWriteTimeUtc) return false; + // next see if the data is the same size, i.e. byte count of record and byte count + // of file. If different sizes, the date/time stamp check will hold. + // B2022-026 RO Memory reduction - new logic + var bytes = ROFSTLookup.GetRofstLookupBytes(roFstInfo.ROFstID); - // next see if the data is the same size, i.e. byte count of record and byte count - // of file. If different sizes, the date/time stamp check will hold. - // B2022-026 RO Memory reduction - new logic - var bytes = ROFSTLookup.GetRofstLookupBytes(roFstInfo.ROFstID); + if (bytes != null && fiRofst.Length != bytes.Length) + return fiRofst.LastWriteTimeUtc > roFstInfo.DTS; + + // if we can't tell by the DTS or size, compare the contents. Get all of the rodb's + // rofsts of the size of the file & compare bytes. + return ROFstInfoList.ROFstDiffBySize(rofstPath, rdi.RODbID, (int)fiRofst.Length); + } + + } - if (bytes != null && fiRofst.Length != bytes.Length) - return fiRofst.LastWriteTimeUtc > roFstInfo.DTS; - // if we can't tell by the DTS or size, compare the contents. Get all of the rodb's - // rofsts of the size of the file & compare bytes. - return ROFstInfoList.ROFstDiffBySize(rofstPath, rdi.RODbID, (int)fiRofst.Length); } } public bool ROfstLastCompleted diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 88810cfc..031ece04 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -40,6 +40,17 @@ namespace VEPROMS.CSLA.Library Console.WriteLine("- - - - - -"); } + //C2025-011 RO Update Admin Tool Memory Enhancements + //clears everything in cache - to run between sections in the Admin Tool to reclaim memory + public static void ClearItemCache() + { + _CacheByPrimaryKey.Clear(); + while (_CacheList.Count > 0) + { + _CacheList[0].DisposeOfContent = true; + _CacheList[0].Dispose(); + } + } public override string ToString() { return string.Format("{0} {1}", MyContent.Number, MyContent.Text).Trim(); @@ -326,6 +337,32 @@ namespace VEPROMS.CSLA.Library #region ItemInfo public partial class ItemInfo : IVEDrillDownReadOnly { + + //C2025-011 RO Update Admin Tool Memory Enhancements + //clears everything in cache - to run between sections in the Admin Tool to reclaim memory + public static void ClearItemInfoCache() + { + while (_CacheByPrimaryKey.Count > 0) + { + var ii = _CacheByPrimaryKey.FirstOrDefault(); + + while (ii.Value.Count > 0) + { + if (ii.Value[0]?.MyContent?.ContentParts != null) + { foreach (PartInfo pi in ii.Value[0]?.MyContent?.ContentParts) pi.Dispose(); } + ii.Value[0].Dispose(); + } + _CacheByPrimaryKey.Remove(ii.Key); + } + + while (_CacheList.Count > 0) + { + if (_CacheList[0]?.MyContent?.ContentParts != null) + {foreach (PartInfo pi in _CacheList[0]?.MyContent?.ContentParts) pi.Dispose(); } + _CacheList[0].Dispose(); + } + } + private bool _PrintAllAtOnce = false; public bool PrintAllAtOnce @@ -2491,15 +2528,19 @@ namespace VEPROMS.CSLA.Library } public ItemInfo LastChild(E_FromType partType) { - ItemInfoList myitems = Lookup((int)partType); - if (myitems != null) return myitems[myitems.Count - 1]; - return null; + using (ItemInfoList myitems = Lookup((int)partType)) + { + if (myitems != null) return myitems[myitems.Count - 1]; + return null; + } } public ItemInfo FirstChild(E_FromType partType) { - ItemInfoList myitems = Lookup((int)partType); - if (myitems != null) return myitems[0]; - return null; + using (ItemInfoList myitems = Lookup((int)partType)) + { + if (myitems != null) return myitems[0]; + return null; + } } public bool HasAncestor(ItemInfo ancestor) { @@ -3863,30 +3904,33 @@ namespace VEPROMS.CSLA.Library } #endregion #region IVEReadOnlyItem - PartInfoList _PartInfoList; public System.Collections.IList GetChildren() { - _PartInfoList = this.MyContent.ContentParts; - if (_PartInfoList.Count == 1 && ((IsProcedure && _PartInfoList[0].ToString() == "Sections") || _PartInfoList[0].ToString() == "Steps")) - return _PartInfoList[0].GetChildren(); - return _PartInfoList; - } - public System.Collections.IList GetChildren(bool allParts) - { - _PartInfoList = this.MyContent.ContentParts; - if (allParts) + using (PartInfoList _PartInfoList = this.MyContent.ContentParts) { if (_PartInfoList.Count == 1 && ((IsProcedure && _PartInfoList[0].ToString() == "Sections") || _PartInfoList[0].ToString() == "Steps")) - return _PartInfoList[0].GetChildren(); return _PartInfoList; } - else // Steps and Sections only - { - for (int i = 0; i < _PartInfoList.Count; i++) - if (_PartInfoList[i].ToString() == "Sections" || _PartInfoList[i].ToString() == "Steps") - return _PartInfoList[i].GetChildren(); - return null; + } + public System.Collections.IList GetChildren(bool allParts) + { + using (PartInfoList _PartInfoList = this.MyContent.ContentParts) + { + if (allParts) + { + if (_PartInfoList.Count == 1 && ((IsProcedure && _PartInfoList[0].ToString() == "Sections") || _PartInfoList[0].ToString() == "Steps")) + + return _PartInfoList[0].GetChildren(); + return _PartInfoList; + } + else // Steps and Sections only + { + for (int i = 0; i < _PartInfoList.Count; i++) + if (_PartInfoList[i].ToString() == "Sections" || _PartInfoList[i].ToString() == "Steps") + return _PartInfoList[i].GetChildren(); + return null; + } } } //public bool ChildrenAreLoaded @@ -6185,8 +6229,8 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new MoveItemCriteria(itemID, index)); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new MoveItemCriteria(itemID, index))) + { return tmp; } } catch (Exception ex) { @@ -6198,13 +6242,15 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListCriteria(itemID, type)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); -#if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList - ContentInfoList.GetList(itemID); // Performance - Load All Content -#endif - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListCriteria(itemID, type))) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + #if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList + ContentInfoList.GetList(itemID); // Performance - Load All Content + #endif + return tmp; + } } catch (Exception ex) { @@ -6215,13 +6261,16 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemTranToListCriteria()); - ItemInfo.AddList(tmp); - tmp.AddEvents(); -#if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList - ContentInfoList.GetList(itemID); // Performance - Load All Content -#endif - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemTranToListCriteria())) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + #if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList + ContentInfoList.GetList(itemID); // Performance - Load All Content + #endif + return tmp; + } + } catch (Exception ex) { @@ -6232,13 +6281,15 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemTranFromListCriteria()); - ItemInfo.AddList(tmp); - tmp.AddEvents(); -#if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList - ContentInfoList.GetList(itemID); // Performance - Load All Content -#endif - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemTranFromListCriteria())) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + #if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList + ContentInfoList.GetList(itemID); // Performance - Load All Content + #endif + return tmp; + } } catch (Exception ex) { @@ -6249,13 +6300,15 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListPartTypeCriteria(fromType)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); -#if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList - ContentInfoList.GetList(itemID); // Performance - Load All Content -#endif - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListPartTypeCriteria(fromType))) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + #if (!ItemWithContent) // If ItemWithContent is set, the content is returned with the ItemInfoList + ContentInfoList.GetList(itemID); // Performance - Load All Content + #endif + return tmp; + } } catch (Exception ex) { @@ -6740,8 +6793,8 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListEnhancedTextDifferencesCriteria(procItem.ItemID)); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListEnhancedTextDifferencesCriteria(procItem.ItemID))) + { return tmp; } } catch (Exception ex) { @@ -6809,8 +6862,8 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListEnhancedMissingCriteria(srcItem.ItemID, enhType)); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListEnhancedMissingCriteria(srcItem.ItemID, enhType))) + { return tmp; } } catch (Exception ex) { @@ -6879,11 +6932,13 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListSearchCriteria(docVersionList, stepTypeList, searchString, caseSensitive, includeLinks, includeRtfFormatting, includeSpecialCharacters, unitPrefix, byWordPrefix, byWordSuffix)); - tmp.SourceOfList = "Search"; - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListSearchCriteria(docVersionList, stepTypeList, searchString, caseSensitive, includeLinks, includeRtfFormatting, includeSpecialCharacters, unitPrefix, byWordPrefix, byWordSuffix))) + { + tmp.SourceOfList = "Search"; + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } } catch (Exception ex) { @@ -7038,10 +7093,12 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListROSearchCriteria(docVersionList, stepTypeList, roSearchString, unitPrefix)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListROSearchCriteria(docVersionList, stepTypeList, roSearchString, unitPrefix))) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } } catch (Exception ex) { @@ -7142,10 +7199,12 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListAnnotationSearchCriteria(docVersionList, stepTypeList, annotationTypeList, searchString, caseSensitive, unitPrefix)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListAnnotationSearchCriteria(docVersionList, stepTypeList, annotationTypeList, searchString, caseSensitive, unitPrefix))) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } } catch (Exception ex) { @@ -7266,10 +7325,12 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListTransitionSearchCriteria(docVersionList, tranType, tranCategory, stepTypeList)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListTransitionSearchCriteria(docVersionList, tranType, tranCategory, stepTypeList))) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } } catch (Exception ex) { @@ -7355,10 +7416,12 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListROReportCriteria(docVersionList, stepTypeList, roSearchString, unitPrefix)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListROReportCriteria(docVersionList, stepTypeList, roSearchString, unitPrefix))) + { + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } } catch (Exception ex) { @@ -7460,11 +7523,13 @@ namespace VEPROMS.CSLA.Library { try { - ItemInfoList tmp = DataPortal.Fetch(new ItemListApplicabilitySearchCriteria(docVersionList, stepTypeList, searchString, caseSensitive, includeLinks, includeRtfFormatting, includeSpecialCharacters, unitPrefix, applicSetting)); - tmp.SourceOfList = "Search"; - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; + using (ItemInfoList tmp = DataPortal.Fetch(new ItemListApplicabilitySearchCriteria(docVersionList, stepTypeList, searchString, caseSensitive, includeLinks, includeRtfFormatting, includeSpecialCharacters, unitPrefix, applicSetting))) + { + tmp.SourceOfList = "Search"; + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } } catch (Exception ex) { @@ -8114,27 +8179,30 @@ namespace VEPROMS.CSLA.Library // get list of differences from sql. This list does not resolve links and may have other rtf commands. // also this list is source items, not enhanced. - ItemInfoList iil = ItemInfoList.GetListEnhancedTextDifferences(this); - if (iil == null || iil.Count == 0) return null; // no differences were found. - // from sql list, get display text of source items & compare to this procedure's items. This - // will determine true 'text' differences. Then return this list. - ItemInfoList retiil = null; // new ItemInfoList(null); - foreach (ItemInfo ii in iil) + using (ItemInfoList iil = ItemInfoList.GetListEnhancedTextDifferences(this)) { - EnhancedDocuments seds = ii.GetMyEnhancedDocuments(); - if (seds != null && seds.Count != 0) + if (iil == null || iil.Count == 0) return null; // no differences were found. + + // from sql list, get display text of source items & compare to this procedure's items. This + // will determine true 'text' differences. Then return this list. + ItemInfoList retiil = null; // new ItemInfoList(null); + foreach (ItemInfo ii in iil) { + EnhancedDocuments seds = ii.GetMyEnhancedDocuments(); + if (seds != null && seds.Count != 0) + { ItemInfo srcItem = ItemInfo.Get(seds[0].ItemID); - // B2022-049: Copy/paste of enhanced procedure and bad links between source and enhanced. Null reference check - if (srcItem != null && srcItem.DisplayTextKeepSpecialChars != ii.DisplayTextKeepSpecialChars) + // B2022-049: Copy/paste of enhanced procedure and bad links between source and enhanced. Null reference check + if (srcItem != null && srcItem.DisplayTextKeepSpecialChars != ii.DisplayTextKeepSpecialChars) { if (retiil == null) retiil = new ItemInfoList(ii); else retiil.AddItem(ii); + } } } + return retiil; } - return retiil; } public void EnhancedProcedureRefreshTextDifferences(ItemInfoList iil) { diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs index 7e525bcc..ae52c60e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs @@ -84,7 +84,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("LastChanged", true); return _LastChanged; } set { _LastChanged = value; } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs.org b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs.org index 0941b5aa..8454e66f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs.org +++ b/PROMS/VEPROMS.CSLA.Library/Extension/MultiUserExt.cs.org @@ -80,7 +80,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("LastChanged", true); return _LastChanged; } set { _LastChanged = value; } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs index 96e47180..951a0cb2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Annotation.cs @@ -108,7 +108,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationID", true); return _AnnotationID; } } @@ -118,7 +117,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("ItemID", true); if (_MyItem != null) _ItemID = _MyItem.ItemID; return _ItemID; } @@ -129,14 +127,12 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyItem", true); if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); return _MyItem; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("MyItem", true); if (_MyItem != value) { _MyItem = value; @@ -151,7 +147,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("TypeID", true); if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; return _TypeID; } @@ -162,14 +157,12 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyAnnotationType", true); if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID); return _MyAnnotationType; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("MyAnnotationType", true); if (_MyAnnotationType != value) { _MyAnnotationType = value; @@ -184,13 +177,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("RtfText", true); return _RtfText; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("RtfText", true); if (value == null) value = string.Empty; if (_RtfText != value) { @@ -205,13 +196,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("SearchText", true); return _SearchText; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("SearchText", true); if (value == null) value = string.Empty; if (_SearchText != value) { @@ -226,13 +215,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Config", true); return _Config; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("Config", true); if (value == null) value = string.Empty; if (_Config != value) { @@ -247,13 +234,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("DTS", true); if (_DTS != value) { _DTS = value; @@ -267,13 +252,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UserID", true); return _UserID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("UserID", true); if (value == null) value = string.Empty; if (_UserID != value) { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs index 71accc3d..83dc13c2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAudit.cs @@ -106,7 +106,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AuditID", true); return _AuditID; } } @@ -116,13 +115,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationID", true); return _AnnotationID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("AnnotationID", true); if (_AnnotationID != value) { _AnnotationID = value; @@ -136,13 +133,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("ItemID", true); return _ItemID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("ItemID", true); if (_ItemID != value) { _ItemID = value; @@ -156,13 +151,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("TypeID", true); return _TypeID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("TypeID", true); if (_TypeID != value) { _TypeID = value; @@ -176,13 +169,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("RtfText", true); return _RtfText; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("RtfText", true); if (value == null) value = string.Empty; if (_RtfText != value) { @@ -197,13 +188,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("SearchText", true); return _SearchText; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("SearchText", true); if (value == null) value = string.Empty; if (_SearchText != value) { @@ -218,13 +207,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Config", true); return _Config; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("Config", true); if (value == null) value = string.Empty; if (_Config != value) { @@ -239,13 +226,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("DTS", true); if (_DTS != value) { _DTS = value; @@ -259,13 +244,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UserID", true); return _UserID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("UserID", true); if (value == null) value = string.Empty; if (_UserID != value) { @@ -280,13 +263,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DeleteStatus", true); return _DeleteStatus; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("DeleteStatus", true); if (_DeleteStatus != value) { _DeleteStatus = value; diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfo.cs index 68b445de..60dd29ae 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationAuditInfo.cs @@ -96,7 +96,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AuditID", true); return _AuditID; } } @@ -106,7 +105,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationID", true); return _AnnotationID; } } @@ -116,7 +114,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("ItemID", true); return _ItemID; } } @@ -126,7 +123,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("TypeID", true); return _TypeID; } } @@ -136,7 +132,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("RtfText", true); return _RtfText; } } @@ -146,7 +141,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("SearchText", true); return _SearchText; } } @@ -156,7 +150,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Config", true); return _Config; } } @@ -166,7 +159,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } } @@ -176,7 +168,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UserID", true); return _UserID; } } @@ -186,7 +177,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DeleteStatus", true); return _DeleteStatus; } } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs index 5b1df1ca..203e1f5d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationInfo.cs @@ -109,7 +109,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationID", true); return _AnnotationID; } } @@ -119,7 +118,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("ItemID", true); if (_MyItem != null) _ItemID = _MyItem.ItemID; return _ItemID; } @@ -130,7 +128,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyItem", true); if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID); return _MyItem; } @@ -141,7 +138,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("TypeID", true); if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; return _TypeID; } @@ -152,7 +148,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyAnnotationType", true); if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationTypeInfo.Get(_TypeID); return _MyAnnotationType; } @@ -163,7 +158,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("RtfText", true); return _RtfText; } } @@ -173,7 +167,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("SearchText", true); return _SearchText; } } @@ -183,7 +176,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Config", true); return _Config; } } @@ -193,7 +185,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } } @@ -203,7 +194,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UserID", true); return _UserID; } } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs index 2c6cd277..d586f302 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs @@ -129,7 +129,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("TypeID", true); return _TypeID; } } @@ -139,13 +138,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Name", true); return _Name; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("Name", true); if (value == null) value = string.Empty; if (_Name != value) { @@ -160,13 +157,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Config", true); return _Config; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("Config", true); if (value == null) value = string.Empty; if (_Config != value) { @@ -181,13 +176,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("DTS", true); if (_DTS != value) { _DTS = value; @@ -201,13 +194,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UserID", true); return _UserID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("UserID", true); if (value == null) value = string.Empty; if (_UserID != value) { @@ -226,7 +217,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationTypeAnnotationCount", true); return _AnnotationTypeAnnotationCount; } } @@ -240,7 +230,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationTypeAnnotations", true); if (_AnnotationTypeAnnotationCount < 0 || (_AnnotationTypeAnnotationCount > 0 && _AnnotationTypeAnnotations == null)) _AnnotationTypeAnnotations = AnnotationTypeAnnotations.GetByTypeID(TypeID); if (_AnnotationTypeAnnotationCount < 0 ) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotation.cs index ea302bd0..82292ba7 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeAnnotation.cs @@ -43,7 +43,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationID", true); if (_MyAnnotation != null) _AnnotationID = _MyAnnotation.AnnotationID; return _AnnotationID; } @@ -55,7 +54,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyAnnotation", true); if (_MyAnnotation == null && _AnnotationID != 0) _MyAnnotation = Annotation.Get(_AnnotationID); return _MyAnnotation; } @@ -66,7 +64,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("ItemID", true); if (_MyItem != null) _ItemID = _MyItem.ItemID; return _ItemID; } @@ -77,14 +74,12 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyItem", true); if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); return _MyItem; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("MyItem", true); if (_MyItem != value) { _MyItem = value; @@ -99,13 +94,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("RtfText", true); return _RtfText; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("RtfText", true); if (value == null) value = string.Empty; if (_RtfText != value) { @@ -120,13 +113,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("SearchText", true); return _SearchText; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("SearchText", true); if (value == null) value = string.Empty; if (_SearchText != value) { @@ -141,13 +132,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Config", true); return _Config; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("Config", true); if (value == null) value = string.Empty; if (_Config != value) { @@ -162,13 +151,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("DTS", true); if (_DTS != value) { _DTS = value; @@ -182,13 +169,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UserID", true); return _UserID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("UserID", true); if (value == null) value = string.Empty; if (_UserID != value) { @@ -204,7 +189,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Item_PreviousID", true); return _Item_PreviousID; } } @@ -214,7 +198,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Item_ContentID", true); return _Item_ContentID; } } @@ -224,7 +207,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Item_DTS", true); return _Item_DTS; } } @@ -234,7 +216,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Item_UserID", true); return _Item_UserID; } } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfo.cs index a001a331..a82473e1 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationTypeInfo.cs @@ -96,7 +96,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("TypeID", true); return _TypeID; } } @@ -106,7 +105,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Name", true); return _Name; } } @@ -116,7 +114,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("Config", true); return _Config; } } @@ -126,7 +123,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } } @@ -136,7 +132,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UserID", true); return _UserID; } } @@ -149,7 +144,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationTypeAnnotationCount", true); if (_AnnotationTypeAnnotationCount < 0) _AnnotationTypeAnnotationCount = AnnotationTypeAnnotations.Count; return _AnnotationTypeAnnotationCount; @@ -162,7 +156,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AnnotationTypeAnnotations", true); if (_AnnotationTypeAnnotationCount < 0 || (_AnnotationTypeAnnotationCount > 0 && _AnnotationTypeAnnotations == null)) _AnnotationTypeAnnotations = AnnotationInfoList.GetByTypeID(_TypeID); if (_AnnotationTypeAnnotationCount < 0) diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Assignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Assignment.cs index b94f643d..a9eb3a2e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Assignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Assignment.cs @@ -109,7 +109,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("AID", true); return _AID; } } @@ -119,7 +118,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("GID", true); if (_MyGroup != null) _GID = _MyGroup.GID; return _GID; } @@ -130,14 +128,12 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyGroup", true); if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); return _MyGroup; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("MyGroup", true); if (_MyGroup != value) { _MyGroup = value; @@ -152,7 +148,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("RID", true); if (_MyRole != null) _RID = _MyRole.RID; return _RID; } @@ -163,14 +158,12 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyRole", true); if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); return _MyRole; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("MyRole", true); if (_MyRole != value) { _MyRole = value; @@ -185,7 +178,6 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("FolderID", true); if (_MyFolder != null) _FolderID = _MyFolder.FolderID; return _FolderID; } @@ -196,14 +188,12 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("MyFolder", true); if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); return _MyFolder; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("MyFolder", true); if (_MyFolder != value) { _MyFolder = value; @@ -218,13 +208,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("StartDate", true); return _StartDate; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("StartDate", true); if (value == null) value = string.Empty; _StartDate = value; try @@ -248,13 +236,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("EndDate", true); return _EndDate; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("EndDate", true); if (value == null) value = string.Empty; _EndDate = value; try @@ -278,13 +264,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("DTS", true); return _DTS; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("DTS", true); if (_DTS != value) { _DTS = value; @@ -298,13 +282,11 @@ namespace VEPROMS.CSLA.Library [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] get { - CanReadProperty("UsrID", true); return _UsrID; } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] set { - CanWriteProperty("UsrID", true); if (value == null) value = string.Empty; if (_UsrID != value) { diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfo.cs index dbfeb802..2a11cca5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AssignmentInfo.cs @@ -19,520 +19,509 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void AssignmentInfoEvent(object sender); - /// - /// AssignmentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AssignmentInfoConverter))] - public partial class AssignmentInfo : ReadOnlyBase, IDisposable - { - public event AssignmentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AssignmentInfo assignmentInfo) - { - if (!_CacheList.Contains(assignmentInfo)) _CacheList.Add(assignmentInfo); // In AddToCache - } - protected static void RemoveFromCache(AssignmentInfo assignmentInfo) - { - while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move AssignmentInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - AssignmentInfo tmp = _CacheList[0]; // Get the first AssignmentInfo - string pKey = tmp.AID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first AssignmentInfo - } - } - internal static void AddList(AssignmentInfoList lst) - { - foreach (AssignmentInfo item in lst) AddToCache(item); - } - protected static AssignmentInfo GetCachedByPrimaryKey(int aid) - { - ConvertListToDictionary(); - string key = aid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Assignment _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - return _AID; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private GroupInfo _MyGroup; - public GroupInfo MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); - return _MyGroup; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private RoleInfo _MyRole; - public RoleInfo MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); - return _MyRole; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private FolderInfo _MyFolder; - public FolderInfo MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); - return _MyFolder; - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - // CSLATODO: Replace base AssignmentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AssignmentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check AssignmentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AssignmentInfo - protected override object GetIdValue() - { - return MyAssignmentInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _AssignmentInfoUnique = 0; - private static int AssignmentInfoUnique - { get { return ++_AssignmentInfoUnique; } } - private int _MyAssignmentInfoUnique = AssignmentInfoUnique; - public int MyAssignmentInfoUnique // Absolutely Unique ID - Info - { get { return _MyAssignmentInfoUnique; } } - protected AssignmentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~AssignmentInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AID.ToString())) return; - List listAssignmentInfo = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items - while (listAssignmentInfo.Contains(this)) listAssignmentInfo.Remove(this); // Remove the item from the list - if (listAssignmentInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AID.ToString()); // remove the list - } - public virtual Assignment Get() - { - return _Editable = Assignment.Get(_AID); - } - public static void Refresh(Assignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Assignment tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(FolderAssignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FolderAssignment tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(GroupAssignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(GroupAssignment tmp) - { - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RoleAssignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RoleAssignment tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static AssignmentInfo Get(int aid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Assignment"); - try - { - AssignmentInfo tmp = GetCachedByPrimaryKey(aid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(aid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AssignmentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AssignmentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal AssignmentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.Constructor", ex); - throw new DbCslaException("AssignmentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _AID; - public int AID - { get { return _AID; } } - public PKCriteria(int aid) - { - _AID = aid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.ReadData", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _GID = dr.GetInt32("GID"); - _RID = dr.GetInt32("RID"); - _FolderID = dr.GetInt32("FolderID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AssignmentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAssignment"; - cm.Parameters.AddWithValue("@AID", criteria.AID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AssignmentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - AssignmentInfoExtension _AssignmentInfoExtension = new AssignmentInfoExtension(); - [Serializable()] - partial class AssignmentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(AssignmentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class AssignmentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AssignmentInfo) - { - // Return the ToString value - return ((AssignmentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void AssignmentInfoEvent(object sender); + /// + /// AssignmentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AssignmentInfoConverter))] + public partial class AssignmentInfo : ReadOnlyBase, IDisposable + { + public event AssignmentInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AssignmentInfo assignmentInfo) + { + if (!_CacheList.Contains(assignmentInfo)) _CacheList.Add(assignmentInfo); // In AddToCache + } + protected static void RemoveFromCache(AssignmentInfo assignmentInfo) + { + while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move AssignmentInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + AssignmentInfo tmp = _CacheList[0]; // Get the first AssignmentInfo + string pKey = tmp.AID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first AssignmentInfo + } + } + internal static void AddList(AssignmentInfoList lst) + { + foreach (AssignmentInfo item in lst) AddToCache(item); + } + protected static AssignmentInfo GetCachedByPrimaryKey(int aid) + { + ConvertListToDictionary(); + string key = aid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Assignment _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AID; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private GroupInfo _MyGroup; + public GroupInfo MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); + return _MyGroup; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private RoleInfo _MyRole; + public RoleInfo MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); + return _MyRole; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private FolderInfo _MyFolder; + public FolderInfo MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); + return _MyFolder; + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + // CSLATODO: Replace base AssignmentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AssignmentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check AssignmentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AssignmentInfo + protected override object GetIdValue() + { + return MyAssignmentInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _AssignmentInfoUnique = 0; + private static int AssignmentInfoUnique + { get { return ++_AssignmentInfoUnique; } } + private int _MyAssignmentInfoUnique = AssignmentInfoUnique; + public int MyAssignmentInfoUnique // Absolutely Unique ID - Info + { get { return _MyAssignmentInfoUnique; } } + protected AssignmentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~AssignmentInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AID.ToString())) return; + List listAssignmentInfo = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items + while (listAssignmentInfo.Contains(this)) listAssignmentInfo.Remove(this); // Remove the item from the list + if (listAssignmentInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AID.ToString()); // remove the list + } + public virtual Assignment Get() + { + return _Editable = Assignment.Get(_AID); + } + public static void Refresh(Assignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Assignment tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(FolderAssignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FolderAssignment tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(GroupAssignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(GroupAssignment tmp) + { + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RoleAssignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RoleAssignment tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static AssignmentInfo Get(int aid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Assignment"); + try + { + AssignmentInfo tmp = GetCachedByPrimaryKey(aid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(aid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AssignmentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AssignmentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal AssignmentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.Constructor", ex); + throw new DbCslaException("AssignmentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _AID; + public int AID + { get { return _AID; } } + public PKCriteria(int aid) + { + _AID = aid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.ReadData", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _GID = dr.GetInt32("GID"); + _RID = dr.GetInt32("RID"); + _FolderID = dr.GetInt32("FolderID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AssignmentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignment"; + cm.Parameters.AddWithValue("@AID", criteria.AID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AssignmentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + AssignmentInfoExtension _AssignmentInfoExtension = new AssignmentInfoExtension(); + [Serializable()] + partial class AssignmentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(AssignmentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class AssignmentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AssignmentInfo) + { + // Return the ToString value + return ((AssignmentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Association.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Association.cs index 57e63fb7..c796a700 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Association.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Association.cs @@ -20,1156 +20,1145 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Association Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AssociationConverter))] - public partial class Association : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshAssociations = new List(); - private void AddToRefreshList(List refreshAssociations) - { - if (IsDirty) - refreshAssociations.Add(this); - } - private void ClearRefreshList() - { - _RefreshAssociations = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshAssociations); - } - private void ProcessRefreshList() - { - foreach (Association tmp in _RefreshAssociations) - { - AssociationInfo.Refresh(tmp); - if (tmp._MyDocVersion != null) DocVersionInfo.Refresh(tmp._MyDocVersion); - if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Association association) - { - if (!_CacheList.Contains(association)) _CacheList.Add(association); // In AddToCache - } - protected static void RemoveFromCache(Association association) - { - while (_CacheList.Contains(association)) _CacheList.Remove(association); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByVersionID_ROFstID = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Association(s) from temporary _CacheList to _CacheByPrimaryKey - { - Association tmp = _CacheList[0]; // Get the first Association - string pKey = tmp.AssociationID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByVersionID_ROFstID[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()] = new List(); // Add new list for VersionID_ROFstID - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByVersionID_ROFstID[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first Association - } - } - protected static Association GetCachedByPrimaryKey(int associationID) - { - ConvertListToDictionary(); - string key = associationID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Association GetCachedByVersionID_ROFstID(int versionID, int rOFstID) - { - ConvertListToDictionary(); - string key = versionID.ToString() + "_" + rOFstID.ToString(); - if (_CacheByVersionID_ROFstID.ContainsKey(key)) return _CacheByVersionID_ROFstID[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAssociationID = -1; - public static int NextAssociationID - { - get { return _nextAssociationID--; } - } - private int _AssociationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AssociationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AssociationID", true); - return _AssociationID; - } - } - private int _VersionID; - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyDocVersion", true); - if (_MyDocVersion != value) - { - _MyDocVersion = value; - _VersionID = value.VersionID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _ROFstID; - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyROFst", true); - if (_MyROFst != value) - { - _MyROFst = value; - _ROFstID = value.ROFstID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirtyList(list)) || (_MyROFst == null ? false : _MyROFst.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocVersion == null ? true : _MyDocVersion.IsValidList(list)) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)); - } - // CSLATODO: Replace base Association.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Association - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Association.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Association - protected override object GetIdValue() - { - return MyAssociationUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyDocVersion != null && (hasBrokenRules = _MyDocVersion.HasBrokenRules) != null) return hasBrokenRules; - if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyDocVersionRequired, "MyDocVersion"); - ValidationRules.AddRule(MyROFstRequired, "MyROFst"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _AssociationExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _AssociationExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyDocVersionRequired(Association target, Csla.Validation.RuleArgs e) - { - if (target._VersionID == 0 && target._MyDocVersion == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyROFstRequired(Association target, Csla.Validation.RuleArgs e) - { - if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(VersionID, ""); - //AuthorizationRules.AllowWrite(ROFstID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _AssociationExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _AssociationExtension.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; } } - private static int _AssociationUnique = 0; - protected static int AssociationUnique - { get { return ++_AssociationUnique; } } - private int _MyAssociationUnique = AssociationUnique; - public int MyAssociationUnique // Absolutely Unique ID - Editable - { get { return _MyAssociationUnique; } } - protected Association() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Association() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AssociationID.ToString())) - { - List listAssociation = _CacheByPrimaryKey[AssociationID.ToString()]; // Get the list of items - while (listAssociation.Contains(this)) listAssociation.Remove(this); // Remove the item from the list - if (listAssociation.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AssociationID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByVersionID_ROFstID.Keys) - if (_CacheByVersionID_ROFstID[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listAssociation = _CacheByVersionID_ROFstID[myKey]; // Get the list of items - listAssociation.Remove(this); // Remove the item from the list - if (listAssociation.Count == 0) //If there are no items left in the list - _CacheByVersionID_ROFstID.Remove(myKey); // remove the list - } - } - public static Association New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Association"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Association.New", ex); - } - } - public static Association New(DocVersion myDocVersion, ROFst myROFst) - { - Association tmp = Association.New(); - tmp.MyDocVersion = myDocVersion; - tmp.MyROFst = myROFst; - return tmp; - } - public static Association New(DocVersion myDocVersion, ROFst myROFst, string config, DateTime dts, string userID) - { - Association tmp = Association.New(); - tmp.MyDocVersion = myDocVersion; - tmp.MyROFst = myROFst; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Association MakeAssociation(DocVersion myDocVersion, ROFst myROFst, string config, DateTime dts, string userID) - { - Association tmp = Association.New(myDocVersion, myROFst, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Association New(DocVersion myDocVersion, ROFst myROFst, string config) - { - Association tmp = Association.New(); - tmp.MyDocVersion = myDocVersion; - tmp.MyROFst = myROFst; - tmp.Config = config; - return tmp; - } - public static Association MakeAssociation(DocVersion myDocVersion, ROFst myROFst, string config) - { - Association tmp = Association.New(myDocVersion, myROFst, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Association Get(int associationID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Association"); - try - { - Association tmp = GetCachedByPrimaryKey(associationID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(associationID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Association - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Association.Get", ex); - } - } - public static Association GetByVersionID_ROFstID(int versionID, int rOFstID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Association"); - try - { - Association tmp = GetCachedByVersionID_ROFstID(versionID, rOFstID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new VersionID_ROFstIDCriteria(versionID, rOFstID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Association - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Association.GetByVersionID_ROFstID", ex); - } - } - public static Association Get(SafeDataReader dr) - { - if (dr.Read()) return new Association(dr); - return null; - } - internal Association(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int associationID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Association"); - try - { - DataPortal.Delete(new PKCriteria(associationID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Association.Delete", ex); - } - } - public override Association Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Association"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Association"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Association"); - try - { - BuildRefreshList(); - Association association = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(association);//Refresh the item in AllList - ProcessRefreshList(); - return association; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _AssociationID; - public int AssociationID - { get { return _AssociationID; } } - public PKCriteria(int associationID) - { - _AssociationID = associationID; - } - } - [Serializable()] - private class VersionID_ROFstIDCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public VersionID_ROFstIDCriteria(int versionID, int rOFstID) - { - _VersionID = versionID; - _ROFstID = rOFstID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AssociationID = NextAssociationID; - // Database Defaults - _DTS = _AssociationExtension.DefaultDTS; - _UserID = _AssociationExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.ReadData", GetHashCode()); - try - { - _AssociationID = dr.GetInt32("AssociationID"); - _VersionID = dr.GetInt32("VersionID"); - _ROFstID = dr.GetInt32("ROFstID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Association.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAssociation"; - cm.Parameters.AddWithValue("@AssociationID", criteria.AssociationID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Association.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(VersionID_ROFstIDCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAssociationByVersionID_ROFstID"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Association.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Association.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyDocVersion != null) _MyDocVersion.Update(); - if (_MyROFst != null) _MyROFst.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addAssociation"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@VersionID", VersionID); - cm.Parameters.AddWithValue("@ROFstID", ROFstID); - 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_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int); - param_AssociationID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_AssociationID); - 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 - _AssociationID = (int)cm.Parameters["@newAssociationID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addAssociation"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@VersionID", myDocVersion.VersionID); - cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); - 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_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int); - param_AssociationID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_AssociationID); - 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 - associationID = (int)cm.Parameters["@newAssociationID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.Add", ex); - throw new DbCslaException("Association.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Association.SQLUpdate", GetHashCode()); - try - { - if (_MyDocVersion != null) _MyDocVersion.Update(); - if (_MyROFst != null) _MyROFst.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateAssociation"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AssociationID", _AssociationID); - cm.Parameters.AddWithValue("@VersionID", VersionID); - cm.Parameters.AddWithValue("@ROFstID", ROFstID); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Association.Add(cn, ref _AssociationID, _MyDocVersion, _MyROFst, _Config, _DTS, _UserID); - else - _LastChanged = Association.Update(cn, ref _AssociationID, _VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateAssociation"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AssociationID", associationID); - cm.Parameters.AddWithValue("@VersionID", versionID); - cm.Parameters.AddWithValue("@ROFstID", rOFstID); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteAssociation"; - cm.Parameters.AddWithValue("@AssociationID", criteria.AssociationID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteAssociation"; - // Input PK Fields - cm.Parameters.AddWithValue("@AssociationID", associationID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.Remove", ex); - throw new DbCslaException("Association.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int associationID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(associationID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Association.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _AssociationID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int associationID) - { - _AssociationID = associationID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsAssociation"; - cm.Parameters.AddWithValue("@AssociationID", _AssociationID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Execute", ex); - throw new DbCslaException("Association.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - AssociationExtension _AssociationExtension = new AssociationExtension(); - [Serializable()] - partial class AssociationExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class AssociationConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Association) - { - // Return the ToString value - return ((Association)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Association Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AssociationConverter))] + public partial class Association : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshAssociations = new List(); + private void AddToRefreshList(List refreshAssociations) + { + if (IsDirty) + refreshAssociations.Add(this); + } + private void ClearRefreshList() + { + _RefreshAssociations = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshAssociations); + } + private void ProcessRefreshList() + { + foreach (Association tmp in _RefreshAssociations) + { + AssociationInfo.Refresh(tmp); + if (tmp._MyDocVersion != null) DocVersionInfo.Refresh(tmp._MyDocVersion); + if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Association association) + { + if (!_CacheList.Contains(association)) _CacheList.Add(association); // In AddToCache + } + protected static void RemoveFromCache(Association association) + { + while (_CacheList.Contains(association)) _CacheList.Remove(association); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByVersionID_ROFstID = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Association(s) from temporary _CacheList to _CacheByPrimaryKey + { + Association tmp = _CacheList[0]; // Get the first Association + string pKey = tmp.AssociationID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByVersionID_ROFstID[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()] = new List(); // Add new list for VersionID_ROFstID + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByVersionID_ROFstID[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first Association + } + } + protected static Association GetCachedByPrimaryKey(int associationID) + { + ConvertListToDictionary(); + string key = associationID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Association GetCachedByVersionID_ROFstID(int versionID, int rOFstID) + { + ConvertListToDictionary(); + string key = versionID.ToString() + "_" + rOFstID.ToString(); + if (_CacheByVersionID_ROFstID.ContainsKey(key)) return _CacheByVersionID_ROFstID[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAssociationID = -1; + public static int NextAssociationID + { + get { return _nextAssociationID--; } + } + private int _AssociationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AssociationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AssociationID; + } + } + private int _VersionID; + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyDocVersion != value) + { + _MyDocVersion = value; + _VersionID = value.VersionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _ROFstID; + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyROFst != value) + { + _MyROFst = value; + _ROFstID = value.ROFstID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirtyList(list)) || (_MyROFst == null ? false : _MyROFst.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocVersion == null ? true : _MyDocVersion.IsValidList(list)) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)); + } + // CSLATODO: Replace base Association.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Association + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Association.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Association + protected override object GetIdValue() + { + return MyAssociationUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyDocVersion != null && (hasBrokenRules = _MyDocVersion.HasBrokenRules) != null) return hasBrokenRules; + if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyDocVersionRequired, "MyDocVersion"); + ValidationRules.AddRule(MyROFstRequired, "MyROFst"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _AssociationExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _AssociationExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyDocVersionRequired(Association target, Csla.Validation.RuleArgs e) + { + if (target._VersionID == 0 && target._MyDocVersion == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyROFstRequired(Association target, Csla.Validation.RuleArgs e) + { + if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(VersionID, ""); + //AuthorizationRules.AllowWrite(ROFstID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _AssociationExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _AssociationExtension.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; } } + private static int _AssociationUnique = 0; + protected static int AssociationUnique + { get { return ++_AssociationUnique; } } + private int _MyAssociationUnique = AssociationUnique; + public int MyAssociationUnique // Absolutely Unique ID - Editable + { get { return _MyAssociationUnique; } } + protected Association() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Association() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AssociationID.ToString())) + { + List listAssociation = _CacheByPrimaryKey[AssociationID.ToString()]; // Get the list of items + while (listAssociation.Contains(this)) listAssociation.Remove(this); // Remove the item from the list + if (listAssociation.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AssociationID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByVersionID_ROFstID.Keys) + if (_CacheByVersionID_ROFstID[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listAssociation = _CacheByVersionID_ROFstID[myKey]; // Get the list of items + listAssociation.Remove(this); // Remove the item from the list + if (listAssociation.Count == 0) //If there are no items left in the list + _CacheByVersionID_ROFstID.Remove(myKey); // remove the list + } + } + public static Association New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Association"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Association.New", ex); + } + } + public static Association New(DocVersion myDocVersion, ROFst myROFst) + { + Association tmp = Association.New(); + tmp.MyDocVersion = myDocVersion; + tmp.MyROFst = myROFst; + return tmp; + } + public static Association New(DocVersion myDocVersion, ROFst myROFst, string config, DateTime dts, string userID) + { + Association tmp = Association.New(); + tmp.MyDocVersion = myDocVersion; + tmp.MyROFst = myROFst; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Association MakeAssociation(DocVersion myDocVersion, ROFst myROFst, string config, DateTime dts, string userID) + { + Association tmp = Association.New(myDocVersion, myROFst, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Association New(DocVersion myDocVersion, ROFst myROFst, string config) + { + Association tmp = Association.New(); + tmp.MyDocVersion = myDocVersion; + tmp.MyROFst = myROFst; + tmp.Config = config; + return tmp; + } + public static Association MakeAssociation(DocVersion myDocVersion, ROFst myROFst, string config) + { + Association tmp = Association.New(myDocVersion, myROFst, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Association Get(int associationID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Association"); + try + { + Association tmp = GetCachedByPrimaryKey(associationID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(associationID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Association + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Association.Get", ex); + } + } + public static Association GetByVersionID_ROFstID(int versionID, int rOFstID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Association"); + try + { + Association tmp = GetCachedByVersionID_ROFstID(versionID, rOFstID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new VersionID_ROFstIDCriteria(versionID, rOFstID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Association + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Association.GetByVersionID_ROFstID", ex); + } + } + public static Association Get(SafeDataReader dr) + { + if (dr.Read()) return new Association(dr); + return null; + } + internal Association(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int associationID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Association"); + try + { + DataPortal.Delete(new PKCriteria(associationID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Association.Delete", ex); + } + } + public override Association Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Association"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Association"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Association"); + try + { + BuildRefreshList(); + Association association = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(association);//Refresh the item in AllList + ProcessRefreshList(); + return association; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _AssociationID; + public int AssociationID + { get { return _AssociationID; } } + public PKCriteria(int associationID) + { + _AssociationID = associationID; + } + } + [Serializable()] + private class VersionID_ROFstIDCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + public VersionID_ROFstIDCriteria(int versionID, int rOFstID) + { + _VersionID = versionID; + _ROFstID = rOFstID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AssociationID = NextAssociationID; + // Database Defaults + _DTS = _AssociationExtension.DefaultDTS; + _UserID = _AssociationExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.ReadData", GetHashCode()); + try + { + _AssociationID = dr.GetInt32("AssociationID"); + _VersionID = dr.GetInt32("VersionID"); + _ROFstID = dr.GetInt32("ROFstID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Association.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssociation"; + cm.Parameters.AddWithValue("@AssociationID", criteria.AssociationID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Association.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(VersionID_ROFstIDCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssociationByVersionID_ROFstID"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Association.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Association.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyDocVersion != null) _MyDocVersion.Update(); + if (_MyROFst != null) _MyROFst.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addAssociation"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", VersionID); + cm.Parameters.AddWithValue("@ROFstID", ROFstID); + 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_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int); + param_AssociationID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AssociationID); + 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 + _AssociationID = (int)cm.Parameters["@newAssociationID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addAssociation"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", myDocVersion.VersionID); + cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); + 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_AssociationID = new SqlParameter("@newAssociationID", SqlDbType.Int); + param_AssociationID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AssociationID); + 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 + associationID = (int)cm.Parameters["@newAssociationID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.Add", ex); + throw new DbCslaException("Association.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Association.SQLUpdate", GetHashCode()); + try + { + if (_MyDocVersion != null) _MyDocVersion.Update(); + if (_MyROFst != null) _MyROFst.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateAssociation"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AssociationID", _AssociationID); + cm.Parameters.AddWithValue("@VersionID", VersionID); + cm.Parameters.AddWithValue("@ROFstID", ROFstID); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Association.Add(cn, ref _AssociationID, _MyDocVersion, _MyROFst, _Config, _DTS, _UserID); + else + _LastChanged = Association.Update(cn, ref _AssociationID, _VersionID, _ROFstID, _Config, _DTS, _UserID, ref _LastChanged); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateAssociation"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AssociationID", associationID); + cm.Parameters.AddWithValue("@VersionID", versionID); + cm.Parameters.AddWithValue("@ROFstID", rOFstID); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteAssociation"; + cm.Parameters.AddWithValue("@AssociationID", criteria.AssociationID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteAssociation"; + // Input PK Fields + cm.Parameters.AddWithValue("@AssociationID", associationID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.Remove", ex); + throw new DbCslaException("Association.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int associationID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(associationID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Association.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _AssociationID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int associationID) + { + _AssociationID = associationID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Association.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsAssociation"; + cm.Parameters.AddWithValue("@AssociationID", _AssociationID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Association.DataPortal_Execute", ex); + throw new DbCslaException("Association.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + AssociationExtension _AssociationExtension = new AssociationExtension(); + [Serializable()] + partial class AssociationExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class AssociationConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Association) + { + // Return the ToString value + return ((Association)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AssociationInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AssociationInfo.cs index 13e877df..6715d67a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AssociationInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AssociationInfo.cs @@ -19,432 +19,424 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void AssociationInfoEvent(object sender); - /// - /// AssociationInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AssociationInfoConverter))] - public partial class AssociationInfo : ReadOnlyBase, IDisposable - { - public event AssociationInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AssociationInfo associationInfo) - { - if (!_CacheList.Contains(associationInfo)) _CacheList.Add(associationInfo); // In AddToCache - } - protected static void RemoveFromCache(AssociationInfo associationInfo) - { - while (_CacheList.Contains(associationInfo)) _CacheList.Remove(associationInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move AssociationInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - AssociationInfo tmp = _CacheList[0]; // Get the first AssociationInfo - string pKey = tmp.AssociationID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first AssociationInfo - } - } - internal static void AddList(AssociationInfoList lst) - { - foreach (AssociationInfo item in lst) AddToCache(item); - } - protected static AssociationInfo GetCachedByPrimaryKey(int associationID) - { - ConvertListToDictionary(); - string key = associationID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Association _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _AssociationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AssociationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AssociationID", true); - return _AssociationID; - } - } - private int _VersionID; - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersionInfo _MyDocVersion; - public DocVersionInfo MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersionInfo.Get(_VersionID); - return _MyDocVersion; - } - } - private int _ROFstID; - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFstInfo _MyROFst; - public ROFstInfo MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - //if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.GetJustROFst(_ROFstID);// Improve performance by not loading all ROImages - return _MyROFst; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base AssociationInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AssociationInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check AssociationInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AssociationInfo - protected override object GetIdValue() - { - return MyAssociationInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _AssociationInfoUnique = 0; - private static int AssociationInfoUnique - { get { return ++_AssociationInfoUnique; } } - private int _MyAssociationInfoUnique = AssociationInfoUnique; - public int MyAssociationInfoUnique // Absolutely Unique ID - Info - { get { return _MyAssociationInfoUnique; } } - protected AssociationInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~AssociationInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AssociationID.ToString())) return; - List listAssociationInfo = _CacheByPrimaryKey[AssociationID.ToString()]; // Get the list of items - while (listAssociationInfo.Contains(this)) listAssociationInfo.Remove(this); // Remove the item from the list - if (listAssociationInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AssociationID.ToString()); // remove the list - } - public virtual Association Get() - { - return _Editable = Association.Get(_AssociationID); - } - public static void Refresh(Association tmp) - { - string key = tmp.AssociationID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssociationInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Association tmp) - { - if (_VersionID != tmp.VersionID) - { - if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for old value - _VersionID = tmp.VersionID; // Update the value - } - _MyDocVersion = null; // Reset list so that the next line gets a new list - if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for new value - if (_ROFstID != tmp.ROFstID) - { - if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // 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.RefreshROFstAssociations(); // Update List for new value - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _AssociationInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(DocVersionAssociation tmp) - { - string key = tmp.AssociationID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssociationInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocVersionAssociation tmp) - { - if (_ROFstID != tmp.ROFstID) - { - if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // 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.RefreshROFstAssociations(); // Update List for new value - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _AssociationInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ROFstAssociation tmp) - { - string key = tmp.AssociationID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssociationInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROFstAssociation tmp) - { - if (_VersionID != tmp.VersionID) - { - if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for old value - _VersionID = tmp.VersionID; // Update the value - } - _MyDocVersion = null; // Reset list so that the next line gets a new list - if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for new value - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _AssociationInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static AssociationInfo Get(int associationID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Association"); - try - { - AssociationInfo tmp = GetCachedByPrimaryKey(associationID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(associationID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AssociationInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AssociationInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal AssociationInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssociationInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssociationInfo.Constructor", ex); - throw new DbCslaException("AssociationInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _AssociationID; - public int AssociationID - { get { return _AssociationID; } } - public PKCriteria(int associationID) - { - _AssociationID = associationID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssociationInfo.ReadData", GetHashCode()); - try - { - _AssociationID = dr.GetInt32("AssociationID"); - _VersionID = dr.GetInt32("VersionID"); - _ROFstID = dr.GetInt32("ROFstID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssociationInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AssociationInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssociationInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAssociation"; - cm.Parameters.AddWithValue("@AssociationID", criteria.AssociationID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssociationInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AssociationInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - AssociationInfoExtension _AssociationInfoExtension = new AssociationInfoExtension(); - [Serializable()] - partial class AssociationInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(AssociationInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class AssociationInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AssociationInfo) - { - // Return the ToString value - return ((AssociationInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void AssociationInfoEvent(object sender); + /// + /// AssociationInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AssociationInfoConverter))] + public partial class AssociationInfo : ReadOnlyBase, IDisposable + { + public event AssociationInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AssociationInfo associationInfo) + { + if (!_CacheList.Contains(associationInfo)) _CacheList.Add(associationInfo); // In AddToCache + } + protected static void RemoveFromCache(AssociationInfo associationInfo) + { + while (_CacheList.Contains(associationInfo)) _CacheList.Remove(associationInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move AssociationInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + AssociationInfo tmp = _CacheList[0]; // Get the first AssociationInfo + string pKey = tmp.AssociationID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first AssociationInfo + } + } + internal static void AddList(AssociationInfoList lst) + { + foreach (AssociationInfo item in lst) AddToCache(item); + } + protected static AssociationInfo GetCachedByPrimaryKey(int associationID) + { + ConvertListToDictionary(); + string key = associationID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Association _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _AssociationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AssociationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AssociationID; + } + } + private int _VersionID; + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersionInfo _MyDocVersion; + public DocVersionInfo MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersionInfo.Get(_VersionID); + return _MyDocVersion; + } + } + private int _ROFstID; + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFstInfo _MyROFst; + public ROFstInfo MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + //if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.GetJustROFst(_ROFstID);// Improve performance by not loading all ROImages + return _MyROFst; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base AssociationInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AssociationInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check AssociationInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AssociationInfo + protected override object GetIdValue() + { + return MyAssociationInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _AssociationInfoUnique = 0; + private static int AssociationInfoUnique + { get { return ++_AssociationInfoUnique; } } + private int _MyAssociationInfoUnique = AssociationInfoUnique; + public int MyAssociationInfoUnique // Absolutely Unique ID - Info + { get { return _MyAssociationInfoUnique; } } + protected AssociationInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~AssociationInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AssociationID.ToString())) return; + List listAssociationInfo = _CacheByPrimaryKey[AssociationID.ToString()]; // Get the list of items + while (listAssociationInfo.Contains(this)) listAssociationInfo.Remove(this); // Remove the item from the list + if (listAssociationInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AssociationID.ToString()); // remove the list + } + public virtual Association Get() + { + return _Editable = Association.Get(_AssociationID); + } + public static void Refresh(Association tmp) + { + string key = tmp.AssociationID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssociationInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Association tmp) + { + if (_VersionID != tmp.VersionID) + { + if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for old value + _VersionID = tmp.VersionID; // Update the value + } + _MyDocVersion = null; // Reset list so that the next line gets a new list + if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for new value + if (_ROFstID != tmp.ROFstID) + { + if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // 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.RefreshROFstAssociations(); // Update List for new value + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AssociationInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(DocVersionAssociation tmp) + { + string key = tmp.AssociationID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssociationInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocVersionAssociation tmp) + { + if (_ROFstID != tmp.ROFstID) + { + if (MyROFst != null) MyROFst.RefreshROFstAssociations(); // 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.RefreshROFstAssociations(); // Update List for new value + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AssociationInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ROFstAssociation tmp) + { + string key = tmp.AssociationID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssociationInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROFstAssociation tmp) + { + if (_VersionID != tmp.VersionID) + { + if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for old value + _VersionID = tmp.VersionID; // Update the value + } + _MyDocVersion = null; // Reset list so that the next line gets a new list + if (MyDocVersion != null) MyDocVersion.RefreshDocVersionAssociations(); // Update List for new value + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AssociationInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static AssociationInfo Get(int associationID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Association"); + try + { + AssociationInfo tmp = GetCachedByPrimaryKey(associationID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(associationID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AssociationInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AssociationInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal AssociationInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssociationInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssociationInfo.Constructor", ex); + throw new DbCslaException("AssociationInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _AssociationID; + public int AssociationID + { get { return _AssociationID; } } + public PKCriteria(int associationID) + { + _AssociationID = associationID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssociationInfo.ReadData", GetHashCode()); + try + { + _AssociationID = dr.GetInt32("AssociationID"); + _VersionID = dr.GetInt32("VersionID"); + _ROFstID = dr.GetInt32("ROFstID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssociationInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AssociationInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssociationInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssociation"; + cm.Parameters.AddWithValue("@AssociationID", criteria.AssociationID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssociationInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AssociationInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + AssociationInfoExtension _AssociationInfoExtension = new AssociationInfoExtension(); + [Serializable()] + partial class AssociationInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(AssociationInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class AssociationInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AssociationInfo) + { + // Return the ToString value + return ((AssociationInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Check.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Check.cs index 87fc3879..01d5a961 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Check.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Check.cs @@ -20,1058 +20,1045 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Check Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(CheckConverter))] - public partial class Check : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshChecks = new List(); - private void AddToRefreshList(List refreshChecks) - { - if (IsDirty) - refreshChecks.Add(this); - } - private void ClearRefreshList() - { - _RefreshChecks = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshChecks); - } - private void ProcessRefreshList() - { - foreach (Check tmp in _RefreshChecks) - { - CheckInfo.Refresh(tmp); - if (tmp._MyRevision != null) RevisionInfo.Refresh(tmp._MyRevision); - if (tmp._MyStage != null) StageInfo.Refresh(tmp._MyStage); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Check check) - { - if (!_CacheList.Contains(check)) _CacheList.Add(check); // In AddToCache - } - protected static void RemoveFromCache(Check check) - { - while (_CacheList.Contains(check)) _CacheList.Remove(check); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Check(s) from temporary _CacheList to _CacheByPrimaryKey - { - Check tmp = _CacheList[0]; // Get the first Check - string pKey = tmp.CheckID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Check - } - } - protected static Check GetCachedByPrimaryKey(int checkID) - { - ConvertListToDictionary(); - string key = checkID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextCheckID = -1; - public static int NextCheckID - { - get { return _nextCheckID--; } - } - private int _CheckID; - [System.ComponentModel.DataObjectField(true, true)] - public int CheckID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CheckID", true); - return _CheckID; - } - } - private int _RevisionID; - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; - return _RevisionID; - } - } - private Revision _MyRevision; - public Revision MyRevision - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRevision", true); - if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); - return _MyRevision; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRevision", true); - if (_MyRevision != value) - { - _MyRevision = value; - _RevisionID = value.RevisionID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _StageID; - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - if (_MyStage != null) _StageID = _MyStage.StageID; - return _StageID; - } - } - private Stage _MyStage; - public Stage MyStage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyStage", true); - if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); - return _MyStage; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyStage", true); - if (_MyStage != value) - { - _MyStage = value; - _StageID = value.StageID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _ConsistencyChecks = string.Empty; - public string ConsistencyChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConsistencyChecks", true); - return _ConsistencyChecks; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ConsistencyChecks", true); - if (value == null) value = string.Empty; - if (_ConsistencyChecks != value) - { - _ConsistencyChecks = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)) || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)) && (_MyStage == null ? true : _MyStage.IsValidList(list)); - } - // CSLATODO: Replace base Check.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Check - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Check.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Check - protected override object GetIdValue() - { - return MyCheckUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; - if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); - ValidationRules.AddRule(MyStageRequired, "MyStage"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _CheckExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _CheckExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyRevisionRequired(Check target, Csla.Validation.RuleArgs e) - { - if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyStageRequired(Check target, Csla.Validation.RuleArgs e) - { - if (target._StageID == 0 && target._MyStage == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(CheckID, ""); - //AuthorizationRules.AllowRead(RevisionID, ""); - //AuthorizationRules.AllowRead(StageID, ""); - //AuthorizationRules.AllowRead(ConsistencyChecks, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RevisionID, ""); - //AuthorizationRules.AllowWrite(StageID, ""); - //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _CheckExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _CheckExtension.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; } } - private static int _CheckUnique = 0; - protected static int CheckUnique - { get { return ++_CheckUnique; } } - private int _MyCheckUnique = CheckUnique; - public int MyCheckUnique // Absolutely Unique ID - Editable - { get { return _MyCheckUnique; } } - protected Check() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Check() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(CheckID.ToString())) - { - List listCheck = _CacheByPrimaryKey[CheckID.ToString()]; // Get the list of items - while (listCheck.Contains(this)) listCheck.Remove(this); // Remove the item from the list - if (listCheck.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list - } - } - public static Check New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Check"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Check.New", ex); - } - } - public static Check New(Revision myRevision, Stage myStage) - { - Check tmp = Check.New(); - tmp.MyRevision = myRevision; - tmp.MyStage = myStage; - return tmp; - } - public static Check New(Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID) - { - Check tmp = Check.New(); - tmp.MyRevision = myRevision; - tmp.MyStage = myStage; - tmp.ConsistencyChecks = consistencyChecks; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Check MakeCheck(Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID) - { - Check tmp = Check.New(myRevision, myStage, consistencyChecks, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Check New(Revision myRevision, Stage myStage, string consistencyChecks) - { - Check tmp = Check.New(); - tmp.MyRevision = myRevision; - tmp.MyStage = myStage; - tmp.ConsistencyChecks = consistencyChecks; - return tmp; - } - public static Check MakeCheck(Revision myRevision, Stage myStage, string consistencyChecks) - { - Check tmp = Check.New(myRevision, myStage, consistencyChecks); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Check Get(int checkID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Check"); - try - { - Check tmp = GetCachedByPrimaryKey(checkID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(checkID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Check - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Check.Get", ex); - } - } - public static Check Get(SafeDataReader dr) - { - if (dr.Read()) return new Check(dr); - return null; - } - internal Check(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int checkID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Check"); - try - { - DataPortal.Delete(new PKCriteria(checkID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Check.Delete", ex); - } - } - public override Check Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Check"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Check"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Check"); - try - { - BuildRefreshList(); - Check check = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(check);//Refresh the item in AllList - ProcessRefreshList(); - return check; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _CheckID; - public int CheckID - { get { return _CheckID; } } - public PKCriteria(int checkID) - { - _CheckID = checkID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _CheckID = NextCheckID; - // Database Defaults - _DTS = _CheckExtension.DefaultDTS; - _UserID = _CheckExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.ReadData", GetHashCode()); - try - { - _CheckID = dr.GetInt32("CheckID"); - _RevisionID = dr.GetInt32("RevisionID"); - _StageID = dr.GetInt32("StageID"); - _ConsistencyChecks = dr.GetString("ConsistencyChecks"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Check.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getCheck"; - cm.Parameters.AddWithValue("@CheckID", criteria.CheckID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Check.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Check.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRevision != null) _MyRevision.Update(); - if (_MyStage != null) _MyStage.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addCheck"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RevisionID", RevisionID); - cm.Parameters.AddWithValue("@StageID", StageID); - cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - // Output Calculated Columns - SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int); - param_CheckID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_CheckID); - 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 - _CheckID = (int)cm.Parameters["@newCheckID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addCheck"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RevisionID", myRevision.RevisionID); - cm.Parameters.AddWithValue("@StageID", myStage.StageID); - cm.Parameters.AddWithValue("@ConsistencyChecks", consistencyChecks); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UserID", userID); - // Output Calculated Columns - SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int); - param_CheckID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_CheckID); - 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 - checkID = (int)cm.Parameters["@newCheckID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Add", ex); - throw new DbCslaException("Check.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Check.SQLUpdate", GetHashCode()); - try - { - if (_MyRevision != null) _MyRevision.Update(); - if (_MyStage != null) _MyStage.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateCheck"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@CheckID", _CheckID); - cm.Parameters.AddWithValue("@RevisionID", RevisionID); - cm.Parameters.AddWithValue("@StageID", StageID); - cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); - else - _LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateCheck"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@CheckID", checkID); - cm.Parameters.AddWithValue("@RevisionID", revisionID); - cm.Parameters.AddWithValue("@StageID", stageID); - cm.Parameters.AddWithValue("@ConsistencyChecks", consistencyChecks); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteCheck"; - cm.Parameters.AddWithValue("@CheckID", criteria.CheckID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteCheck"; - // Input PK Fields - cm.Parameters.AddWithValue("@CheckID", checkID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Remove", ex); - throw new DbCslaException("Check.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int checkID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(checkID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Check.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _CheckID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int checkID) - { - _CheckID = checkID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsCheck"; - cm.Parameters.AddWithValue("@CheckID", _CheckID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Execute", ex); - throw new DbCslaException("Check.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - CheckExtension _CheckExtension = new CheckExtension(); - [Serializable()] - partial class CheckExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class CheckConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Check) - { - // Return the ToString value - return ((Check)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Check Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(CheckConverter))] + public partial class Check : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshChecks = new List(); + private void AddToRefreshList(List refreshChecks) + { + if (IsDirty) + refreshChecks.Add(this); + } + private void ClearRefreshList() + { + _RefreshChecks = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshChecks); + } + private void ProcessRefreshList() + { + foreach (Check tmp in _RefreshChecks) + { + CheckInfo.Refresh(tmp); + if (tmp._MyRevision != null) RevisionInfo.Refresh(tmp._MyRevision); + if (tmp._MyStage != null) StageInfo.Refresh(tmp._MyStage); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Check check) + { + if (!_CacheList.Contains(check)) _CacheList.Add(check); // In AddToCache + } + protected static void RemoveFromCache(Check check) + { + while (_CacheList.Contains(check)) _CacheList.Remove(check); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Check(s) from temporary _CacheList to _CacheByPrimaryKey + { + Check tmp = _CacheList[0]; // Get the first Check + string pKey = tmp.CheckID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Check + } + } + protected static Check GetCachedByPrimaryKey(int checkID) + { + ConvertListToDictionary(); + string key = checkID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextCheckID = -1; + public static int NextCheckID + { + get { return _nextCheckID--; } + } + private int _CheckID; + [System.ComponentModel.DataObjectField(true, true)] + public int CheckID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CheckID; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConsistencyChecks; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ConsistencyChecks != value) + { + _ConsistencyChecks = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)) || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + // CSLATODO: Replace base Check.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Check + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Check.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Check + protected override object GetIdValue() + { + return MyCheckUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; + if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _CheckExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _CheckExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(Check target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyStageRequired(Check target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(CheckID, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowRead(ConsistencyChecks, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _CheckExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _CheckExtension.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; } } + private static int _CheckUnique = 0; + protected static int CheckUnique + { get { return ++_CheckUnique; } } + private int _MyCheckUnique = CheckUnique; + public int MyCheckUnique // Absolutely Unique ID - Editable + { get { return _MyCheckUnique; } } + protected Check() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Check() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(CheckID.ToString())) + { + List listCheck = _CacheByPrimaryKey[CheckID.ToString()]; // Get the list of items + while (listCheck.Contains(this)) listCheck.Remove(this); // Remove the item from the list + if (listCheck.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list + } + } + public static Check New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Check"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.New", ex); + } + } + public static Check New(Revision myRevision, Stage myStage) + { + Check tmp = Check.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + return tmp; + } + public static Check New(Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID) + { + Check tmp = Check.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.ConsistencyChecks = consistencyChecks; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Check MakeCheck(Revision myRevision, Stage myStage, string consistencyChecks, DateTime dts, string userID) + { + Check tmp = Check.New(myRevision, myStage, consistencyChecks, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Check New(Revision myRevision, Stage myStage, string consistencyChecks) + { + Check tmp = Check.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.ConsistencyChecks = consistencyChecks; + return tmp; + } + public static Check MakeCheck(Revision myRevision, Stage myStage, string consistencyChecks) + { + Check tmp = Check.New(myRevision, myStage, consistencyChecks); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Check Get(int checkID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Check"); + try + { + Check tmp = GetCachedByPrimaryKey(checkID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(checkID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Check + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.Get", ex); + } + } + public static Check Get(SafeDataReader dr) + { + if (dr.Read()) return new Check(dr); + return null; + } + internal Check(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int checkID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Check"); + try + { + DataPortal.Delete(new PKCriteria(checkID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.Delete", ex); + } + } + public override Check Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Check"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Check"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Check"); + try + { + BuildRefreshList(); + Check check = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(check);//Refresh the item in AllList + ProcessRefreshList(); + return check; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _CheckID; + public int CheckID + { get { return _CheckID; } } + public PKCriteria(int checkID) + { + _CheckID = checkID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _CheckID = NextCheckID; + // Database Defaults + _DTS = _CheckExtension.DefaultDTS; + _UserID = _CheckExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.ReadData", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getCheck"; + cm.Parameters.AddWithValue("@CheckID", criteria.CheckID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Check.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addCheck"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int); + param_CheckID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_CheckID); + 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 + _CheckID = (int)cm.Parameters["@newCheckID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addCheck"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", myRevision.RevisionID); + cm.Parameters.AddWithValue("@StageID", myStage.StageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", consistencyChecks); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_CheckID = new SqlParameter("@newCheckID", SqlDbType.Int); + param_CheckID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_CheckID); + 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 + checkID = (int)cm.Parameters["@newCheckID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Add", ex); + throw new DbCslaException("Check.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Check.SQLUpdate", GetHashCode()); + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateCheck"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@CheckID", _CheckID); + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", _ConsistencyChecks); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); + else + _LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateCheck"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@CheckID", checkID); + cm.Parameters.AddWithValue("@RevisionID", revisionID); + cm.Parameters.AddWithValue("@StageID", stageID); + cm.Parameters.AddWithValue("@ConsistencyChecks", consistencyChecks); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteCheck"; + cm.Parameters.AddWithValue("@CheckID", criteria.CheckID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteCheck"; + // Input PK Fields + cm.Parameters.AddWithValue("@CheckID", checkID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.Remove", ex); + throw new DbCslaException("Check.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int checkID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(checkID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Check.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _CheckID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int checkID) + { + _CheckID = checkID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Check.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsCheck"; + cm.Parameters.AddWithValue("@CheckID", _CheckID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Check.DataPortal_Execute", ex); + throw new DbCslaException("Check.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + CheckExtension _CheckExtension = new CheckExtension(); + [Serializable()] + partial class CheckExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class CheckConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Check) + { + // Return the ToString value + return ((Check)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs index 373e6a9b..41514fce 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/CheckInfo.cs @@ -19,431 +19,423 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void CheckInfoEvent(object sender); - /// - /// CheckInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(CheckInfoConverter))] - public partial class CheckInfo : ReadOnlyBase, IDisposable - { - public event CheckInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(CheckInfo checkInfo) - { - if (!_CacheList.Contains(checkInfo)) _CacheList.Add(checkInfo); // In AddToCache - } - protected static void RemoveFromCache(CheckInfo checkInfo) - { - while (_CacheList.Contains(checkInfo)) _CacheList.Remove(checkInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move CheckInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - CheckInfo tmp = _CacheList[0]; // Get the first CheckInfo - string pKey = tmp.CheckID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first CheckInfo - } - } - internal static void AddList(CheckInfoList lst) - { - foreach (CheckInfo item in lst) AddToCache(item); - } - protected static CheckInfo GetCachedByPrimaryKey(int checkID) - { - ConvertListToDictionary(); - string key = checkID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Check _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _CheckID; - [System.ComponentModel.DataObjectField(true, true)] - public int CheckID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CheckID", true); - return _CheckID; - } - } - private int _RevisionID; - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; - return _RevisionID; - } - } - private RevisionInfo _MyRevision; - public RevisionInfo MyRevision - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRevision", true); - if (_MyRevision == null && _RevisionID != 0) _MyRevision = RevisionInfo.Get(_RevisionID); - return _MyRevision; - } - } - private int _StageID; - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - if (_MyStage != null) _StageID = _MyStage.StageID; - return _StageID; - } - } - private StageInfo _MyStage; - public StageInfo MyStage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyStage", true); - if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.GetJustStage(_StageID); - return _MyStage; - } - } - private string _ConsistencyChecks = string.Empty; - public string ConsistencyChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConsistencyChecks", true); - return _ConsistencyChecks; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base CheckInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current CheckInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check CheckInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current CheckInfo - protected override object GetIdValue() - { - return MyCheckInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _CheckInfoUnique = 0; - private static int CheckInfoUnique - { get { return ++_CheckInfoUnique; } } - private int _MyCheckInfoUnique = CheckInfoUnique; - public int MyCheckInfoUnique // Absolutely Unique ID - Info - { get { return _MyCheckInfoUnique; } } - protected CheckInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~CheckInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(CheckID.ToString())) return; - List listCheckInfo = _CacheByPrimaryKey[CheckID.ToString()]; // Get the list of items - while (listCheckInfo.Contains(this)) listCheckInfo.Remove(this); // Remove the item from the list - if (listCheckInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list - } - public virtual Check Get() - { - return _Editable = Check.Get(_CheckID); - } - public static void Refresh(Check tmp) - { - string key = tmp.CheckID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Check tmp) - { - if (_RevisionID != tmp.RevisionID) - { - if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value - _RevisionID = tmp.RevisionID; // Update the value - } - _MyRevision = null; // Reset list so that the next line gets a new list - if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value - if (_StageID != tmp.StageID) - { - if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value - _StageID = tmp.StageID; // Update the value - } - _MyStage = null; // Reset list so that the next line gets a new list - if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value - _ConsistencyChecks = tmp.ConsistencyChecks; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _CheckInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RevisionCheck tmp) - { - string key = tmp.CheckID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RevisionCheck tmp) - { - if (_StageID != tmp.StageID) - { - if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value - _StageID = tmp.StageID; // Update the value - } - _MyStage = null; // Reset list so that the next line gets a new list - if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value - _ConsistencyChecks = tmp.ConsistencyChecks; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _CheckInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(StageCheck tmp) - { - string key = tmp.CheckID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(StageCheck tmp) - { - if (_RevisionID != tmp.RevisionID) - { - if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value - _RevisionID = tmp.RevisionID; // Update the value - } - _MyRevision = null; // Reset list so that the next line gets a new list - if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value - _ConsistencyChecks = tmp.ConsistencyChecks; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _CheckInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static CheckInfo Get(int checkID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Check"); - try - { - CheckInfo tmp = GetCachedByPrimaryKey(checkID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(checkID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up CheckInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CheckInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal CheckInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.Constructor", ex); - throw new DbCslaException("CheckInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _CheckID; - public int CheckID - { get { return _CheckID; } } - public PKCriteria(int checkID) - { - _CheckID = checkID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.ReadData", GetHashCode()); - try - { - _CheckID = dr.GetInt32("CheckID"); - _RevisionID = dr.GetInt32("RevisionID"); - _StageID = dr.GetInt32("StageID"); - _ConsistencyChecks = dr.GetString("ConsistencyChecks"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("CheckInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getCheck"; - cm.Parameters.AddWithValue("@CheckID", criteria.CheckID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("CheckInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - CheckInfoExtension _CheckInfoExtension = new CheckInfoExtension(); - [Serializable()] - partial class CheckInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(CheckInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class CheckInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is CheckInfo) - { - // Return the ToString value - return ((CheckInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void CheckInfoEvent(object sender); + /// + /// CheckInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(CheckInfoConverter))] + public partial class CheckInfo : ReadOnlyBase, IDisposable + { + public event CheckInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(CheckInfo checkInfo) + { + if (!_CacheList.Contains(checkInfo)) _CacheList.Add(checkInfo); // In AddToCache + } + protected static void RemoveFromCache(CheckInfo checkInfo) + { + while (_CacheList.Contains(checkInfo)) _CacheList.Remove(checkInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move CheckInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + CheckInfo tmp = _CacheList[0]; // Get the first CheckInfo + string pKey = tmp.CheckID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first CheckInfo + } + } + internal static void AddList(CheckInfoList lst) + { + foreach (CheckInfo item in lst) AddToCache(item); + } + protected static CheckInfo GetCachedByPrimaryKey(int checkID) + { + ConvertListToDictionary(); + string key = checkID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Check _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _CheckID; + [System.ComponentModel.DataObjectField(true, true)] + public int CheckID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CheckID; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private RevisionInfo _MyRevision; + public RevisionInfo MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision == null && _RevisionID != 0) _MyRevision = RevisionInfo.Get(_RevisionID); + return _MyRevision; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private StageInfo _MyStage; + public StageInfo MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.GetJustStage(_StageID); + return _MyStage; + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConsistencyChecks; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base CheckInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current CheckInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check CheckInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current CheckInfo + protected override object GetIdValue() + { + return MyCheckInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _CheckInfoUnique = 0; + private static int CheckInfoUnique + { get { return ++_CheckInfoUnique; } } + private int _MyCheckInfoUnique = CheckInfoUnique; + public int MyCheckInfoUnique // Absolutely Unique ID - Info + { get { return _MyCheckInfoUnique; } } + protected CheckInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~CheckInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(CheckID.ToString())) return; + List listCheckInfo = _CacheByPrimaryKey[CheckID.ToString()]; // Get the list of items + while (listCheckInfo.Contains(this)) listCheckInfo.Remove(this); // Remove the item from the list + if (listCheckInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(CheckID.ToString()); // remove the list + } + public virtual Check Get() + { + return _Editable = Check.Get(_CheckID); + } + public static void Refresh(Check tmp) + { + string key = tmp.CheckID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Check tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value + _ConsistencyChecks = tmp.ConsistencyChecks; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _CheckInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RevisionCheck tmp) + { + string key = tmp.CheckID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RevisionCheck tmp) + { + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageChecks(); // Update List for new value + _ConsistencyChecks = tmp.ConsistencyChecks; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _CheckInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(StageCheck tmp) + { + string key = tmp.CheckID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (CheckInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(StageCheck tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionChecks(); // Update List for new value + _ConsistencyChecks = tmp.ConsistencyChecks; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _CheckInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static CheckInfo Get(int checkID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Check"); + try + { + CheckInfo tmp = GetCachedByPrimaryKey(checkID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(checkID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up CheckInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CheckInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal CheckInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.Constructor", ex); + throw new DbCslaException("CheckInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _CheckID; + public int CheckID + { get { return _CheckID; } } + public PKCriteria(int checkID) + { + _CheckID = checkID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.ReadData", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("CheckInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] CheckInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getCheck"; + cm.Parameters.AddWithValue("@CheckID", criteria.CheckID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("CheckInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("CheckInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + CheckInfoExtension _CheckInfoExtension = new CheckInfoExtension(); + [Serializable()] + partial class CheckInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(CheckInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class CheckInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is CheckInfo) + { + // Return the ToString value + return ((CheckInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs index 0ae7f8eb..784492cd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Connection.cs @@ -20,1238 +20,1221 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Connection Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ConnectionConverter))] - public partial class Connection : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshConnections = new List(); - private List _RefreshConnectionFolders = new List(); - private void AddToRefreshList(List refreshConnections, List refreshConnectionFolders) - { - if (IsDirty) - refreshConnections.Add(this); - if (_ConnectionFolders != null && _ConnectionFolders.IsDirty) - { - foreach (ConnectionFolder tmp in _ConnectionFolders) - { - if (tmp.IsDirty) refreshConnectionFolders.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshConnections = new List(); - _RefreshConnectionFolders = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshConnections, _RefreshConnectionFolders); - } - private void ProcessRefreshList() - { - foreach (Connection tmp in _RefreshConnections) - { - ConnectionInfo.Refresh(tmp); - } - foreach (ConnectionFolder tmp in _RefreshConnectionFolders) - { - FolderInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Connection connection) - { - if (!_CacheList.Contains(connection)) _CacheList.Add(connection); // In AddToCache - } - protected static void RemoveFromCache(Connection connection) - { - while (_CacheList.Contains(connection)) _CacheList.Remove(connection); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByName = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Connection(s) from temporary _CacheList to _CacheByPrimaryKey - { - Connection tmp = _CacheList[0]; // Get the first Connection - string pKey = tmp.DBID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first Connection - } - } - protected static Connection GetCachedByPrimaryKey(int dbid) - { - ConvertListToDictionary(); - string key = dbid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Connection GetCachedByName(string name) - { - ConvertListToDictionary(); - string key = name.ToString(); - if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextDBID = -1; - public static int NextDBID - { - get { return _nextDBID--; } - } - private int _DBID; - [System.ComponentModel.DataObjectField(true, true)] - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - return _DBID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ConnectionString = string.Empty; - public string ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionString", true); - return _ConnectionString; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ConnectionString", true); - if (value == null) value = string.Empty; - if (_ConnectionString != value) - { - _ConnectionString = value; - PropertyHasChanged(); - } - } - } - private int _ServerType; - /// - /// 0 SQL Server - /// - public int ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ServerType", true); - return _ServerType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ServerType", true); - if (_ServerType != value) - { - _ServerType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ConnectionFolderCount = 0; - /// - /// Count of ConnectionFolders for this Connection - /// - public int ConnectionFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolderCount", true); - return _ConnectionFolderCount; - } - } - private ConnectionFolders _ConnectionFolders = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ConnectionFoldersConverter))] - public ConnectionFolders ConnectionFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolders", true); - if (_ConnectionFolderCount < 0 || (_ConnectionFolderCount > 0 && _ConnectionFolders == null)) - _ConnectionFolders = ConnectionFolders.GetByDBID(DBID); - if (_ConnectionFolderCount < 0 ) - _ConnectionFolderCount = _ConnectionFolders == null ? 0 : _ConnectionFolders.Count; - if (_ConnectionFolders == null) - _ConnectionFolders = ConnectionFolders.New(); - return _ConnectionFolders; - } - } - public void Reset_ConnectionFolders() - { - _ConnectionFolderCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_ConnectionFolders == null ? false : _ConnectionFolders.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ConnectionFolders == null ? true : _ConnectionFolders.IsValidList(list)); - } - // CSLATODO: Replace base Connection.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Connection - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Connection.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Connection - protected override object GetIdValue() - { - return MyConnectionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ConnectionFolders != null && (hasBrokenRules = _ConnectionFolders.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConnectionString", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ConnectionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ConnectionExtension.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(DBID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ConnectionString, ""); - //AuthorizationRules.AllowRead(ServerType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ConnectionString, ""); - //AuthorizationRules.AllowWrite(ServerType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _ConnectionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ConnectionExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ConnectionFolderCount; - 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; } } - private static int _ConnectionUnique = 0; - protected static int ConnectionUnique - { get { return ++_ConnectionUnique; } } - private int _MyConnectionUnique = ConnectionUnique; - public int MyConnectionUnique // Absolutely Unique ID - Editable - { get { return _MyConnectionUnique; } } - protected Connection() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Connection() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DBID.ToString())) - { - List listConnection = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items - while (listConnection.Contains(this)) listConnection.Remove(this); // Remove the item from the list - if (listConnection.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByName.Keys) - if (_CacheByName[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listConnection = _CacheByName[myKey]; // Get the list of items - listConnection.Remove(this); // Remove the item from the list - if (listConnection.Count == 0) //If there are no items left in the list - _CacheByName.Remove(myKey); // remove the list - } - } - public static Connection New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Connection"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.New", ex); - } - } - public static Connection New(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) - { - Connection tmp = Connection.New(); - tmp.Name = name; - tmp.Title = title; - tmp.ConnectionString = connectionString; - tmp.ServerType = serverType; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Connection MakeConnection(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) - { - Connection tmp = Connection.New(name, title, connectionString, serverType, config, dts, usrID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Connection New(string name, string title, string connectionString, string config) - { - Connection tmp = Connection.New(); - tmp.Name = name; - tmp.Title = title; - tmp.ConnectionString = connectionString; - tmp.Config = config; - return tmp; - } - public static Connection MakeConnection(string name, string title, string connectionString, string config) - { - Connection tmp = Connection.New(name, title, connectionString, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Connection Get(int dbid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Connection"); - try - { - Connection tmp = GetCachedByPrimaryKey(dbid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(dbid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Connection - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.Get", ex); - } - } - public static Connection GetByName(string name) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Connection"); - try - { - Connection tmp = GetCachedByName(name); - if (tmp == null) - { - tmp = DataPortal.Fetch(new NameCriteria(name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Connection - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.GetByName", ex); - } - } - public static Connection Get(SafeDataReader dr) - { - if (dr.Read()) return new Connection(dr); - return null; - } - internal Connection(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int dbid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Connection"); - try - { - DataPortal.Delete(new PKCriteria(dbid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.Delete", ex); - } - } - public override Connection Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Connection"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Connection"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Connection"); - try - { - BuildRefreshList(); - Connection connection = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(connection);//Refresh the item in AllList - ProcessRefreshList(); - return connection; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DBID; - public int DBID - { get { return _DBID; } } - public PKCriteria(int dbid) - { - _DBID = dbid; - } - } - [Serializable()] - private class NameCriteria - { - private string _Name; - public string Name - { get { return _Name; } } - public NameCriteria(string name) - { - _Name = name; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _DBID = NextDBID; - // Database Defaults - _ServerType = _ConnectionExtension.DefaultServerType; - _DTS = _ConnectionExtension.DefaultDTS; - _UsrID = _ConnectionExtension.DefaultUsrID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.ReadData", GetHashCode()); - try - { - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ConnectionString = dr.GetString("ConnectionString"); - _ServerType = dr.GetInt32("ServerType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ConnectionFolderCount = dr.GetInt32("FolderCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getConnection"; - cm.Parameters.AddWithValue("@DBID", criteria.DBID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ConnectionFolders = ConnectionFolders.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getConnectionByName"; - cm.Parameters.AddWithValue("@Name", criteria.Name); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addConnection"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); - cm.Parameters.AddWithValue("@ServerType", _ServerType); - 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); - param_DBID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_DBID); - 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 - _DBID = (int)cm.Parameters["@newDBID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_ConnectionFolders != null) _ConnectionFolders.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addConnection"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - cm.Parameters.AddWithValue("@ConnectionString", connectionString); - cm.Parameters.AddWithValue("@ServerType", serverType); - 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); - param_DBID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_DBID); - 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 - dbid = (int)cm.Parameters["@newDBID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Add", ex); - throw new DbCslaException("Connection.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateConnection"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@DBID", _DBID); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); - cm.Parameters.AddWithValue("@ServerType", _ServerType); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_ConnectionFolders != null) _ConnectionFolders.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Connection.Add(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID); - else - _LastChanged = Connection.Update(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - if (_ConnectionFolders != null) _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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateConnection"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DBID", dbid); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - cm.Parameters.AddWithValue("@ConnectionString", connectionString); - cm.Parameters.AddWithValue("@ServerType", serverType); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteConnection"; - cm.Parameters.AddWithValue("@DBID", criteria.DBID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteConnection"; - // Input PK Fields - cm.Parameters.AddWithValue("@DBID", dbid); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Remove", ex); - throw new DbCslaException("Connection.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int dbid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(dbid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DBID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int dbid) - { - _DBID = dbid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsConnection"; - cm.Parameters.AddWithValue("@DBID", _DBID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Execute", ex); - throw new DbCslaException("Connection.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ConnectionExtension _ConnectionExtension = new ConnectionExtension(); - [Serializable()] - partial class ConnectionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultServerType - { - get { return 1; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ConnectionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Connection) - { - // Return the ToString value - return ((Connection)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Connection Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionConverter))] + public partial class Connection : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshConnections = new List(); + private List _RefreshConnectionFolders = new List(); + private void AddToRefreshList(List refreshConnections, List refreshConnectionFolders) + { + if (IsDirty) + refreshConnections.Add(this); + if (_ConnectionFolders != null && _ConnectionFolders.IsDirty) + { + foreach (ConnectionFolder tmp in _ConnectionFolders) + { + if (tmp.IsDirty) refreshConnectionFolders.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshConnections = new List(); + _RefreshConnectionFolders = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshConnections, _RefreshConnectionFolders); + } + private void ProcessRefreshList() + { + foreach (Connection tmp in _RefreshConnections) + { + ConnectionInfo.Refresh(tmp); + } + foreach (ConnectionFolder tmp in _RefreshConnectionFolders) + { + FolderInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Connection connection) + { + if (!_CacheList.Contains(connection)) _CacheList.Add(connection); // In AddToCache + } + protected static void RemoveFromCache(Connection connection) + { + while (_CacheList.Contains(connection)) _CacheList.Remove(connection); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByName = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Connection(s) from temporary _CacheList to _CacheByPrimaryKey + { + Connection tmp = _CacheList[0]; // Get the first Connection + string pKey = tmp.DBID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first Connection + } + } + protected static Connection GetCachedByPrimaryKey(int dbid) + { + ConvertListToDictionary(); + string key = dbid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Connection GetCachedByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextDBID = -1; + public static int NextDBID + { + get { return _nextDBID--; } + } + private int _DBID; + [System.ComponentModel.DataObjectField(true, true)] + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ConnectionString = string.Empty; + public string ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConnectionString; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ConnectionString != value) + { + _ConnectionString = value; + PropertyHasChanged(); + } + } + } + private int _ServerType; + /// + /// 0 SQL Server + /// + public int ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ServerType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ServerType != value) + { + _ServerType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ConnectionFolderCount = 0; + /// + /// Count of ConnectionFolders for this Connection + /// + public int ConnectionFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConnectionFolderCount; + } + } + private ConnectionFolders _ConnectionFolders = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ConnectionFoldersConverter))] + public ConnectionFolders ConnectionFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ConnectionFolderCount < 0 || (_ConnectionFolderCount > 0 && _ConnectionFolders == null)) + _ConnectionFolders = ConnectionFolders.GetByDBID(DBID); + if (_ConnectionFolderCount < 0) + _ConnectionFolderCount = _ConnectionFolders == null ? 0 : _ConnectionFolders.Count; + if (_ConnectionFolders == null) + _ConnectionFolders = ConnectionFolders.New(); + return _ConnectionFolders; + } + } + public void Reset_ConnectionFolders() + { + _ConnectionFolderCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_ConnectionFolders == null ? false : _ConnectionFolders.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ConnectionFolders == null ? true : _ConnectionFolders.IsValidList(list)); + } + // CSLATODO: Replace base Connection.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Connection + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Connection.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Connection + protected override object GetIdValue() + { + return MyConnectionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ConnectionFolders != null && (hasBrokenRules = _ConnectionFolders.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConnectionString", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ConnectionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ConnectionExtension.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(DBID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(ConnectionString, ""); + //AuthorizationRules.AllowRead(ServerType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(ConnectionString, ""); + //AuthorizationRules.AllowWrite(ServerType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _ConnectionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ConnectionExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ConnectionFolderCount; + 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; } } + private static int _ConnectionUnique = 0; + protected static int ConnectionUnique + { get { return ++_ConnectionUnique; } } + private int _MyConnectionUnique = ConnectionUnique; + public int MyConnectionUnique // Absolutely Unique ID - Editable + { get { return _MyConnectionUnique; } } + protected Connection() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Connection() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DBID.ToString())) + { + List listConnection = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items + while (listConnection.Contains(this)) listConnection.Remove(this); // Remove the item from the list + if (listConnection.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByName.Keys) + if (_CacheByName[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listConnection = _CacheByName[myKey]; // Get the list of items + listConnection.Remove(this); // Remove the item from the list + if (listConnection.Count == 0) //If there are no items left in the list + _CacheByName.Remove(myKey); // remove the list + } + } + public static Connection New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Connection"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.New", ex); + } + } + public static Connection New(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) + { + Connection tmp = Connection.New(); + tmp.Name = name; + tmp.Title = title; + tmp.ConnectionString = connectionString; + tmp.ServerType = serverType; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Connection MakeConnection(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) + { + Connection tmp = Connection.New(name, title, connectionString, serverType, config, dts, usrID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Connection New(string name, string title, string connectionString, string config) + { + Connection tmp = Connection.New(); + tmp.Name = name; + tmp.Title = title; + tmp.ConnectionString = connectionString; + tmp.Config = config; + return tmp; + } + public static Connection MakeConnection(string name, string title, string connectionString, string config) + { + Connection tmp = Connection.New(name, title, connectionString, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Connection Get(int dbid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Connection"); + try + { + Connection tmp = GetCachedByPrimaryKey(dbid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dbid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Connection + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.Get", ex); + } + } + public static Connection GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Connection"); + try + { + Connection tmp = GetCachedByName(name); + if (tmp == null) + { + tmp = DataPortal.Fetch(new NameCriteria(name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Connection + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.GetByName", ex); + } + } + public static Connection Get(SafeDataReader dr) + { + if (dr.Read()) return new Connection(dr); + return null; + } + internal Connection(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int dbid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Connection"); + try + { + DataPortal.Delete(new PKCriteria(dbid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.Delete", ex); + } + } + public override Connection Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Connection"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Connection"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Connection"); + try + { + BuildRefreshList(); + Connection connection = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(connection);//Refresh the item in AllList + ProcessRefreshList(); + return connection; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DBID; + public int DBID + { get { return _DBID; } } + public PKCriteria(int dbid) + { + _DBID = dbid; + } + } + [Serializable()] + private class NameCriteria + { + private string _Name; + public string Name + { get { return _Name; } } + public NameCriteria(string name) + { + _Name = name; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _DBID = NextDBID; + // Database Defaults + _ServerType = _ConnectionExtension.DefaultServerType; + _DTS = _ConnectionExtension.DefaultDTS; + _UsrID = _ConnectionExtension.DefaultUsrID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.ReadData", GetHashCode()); + try + { + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ConnectionString = dr.GetString("ConnectionString"); + _ServerType = dr.GetInt32("ServerType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ConnectionFolderCount = dr.GetInt32("FolderCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnection"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ConnectionFolders = ConnectionFolders.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnectionByName"; + cm.Parameters.AddWithValue("@Name", criteria.Name); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addConnection"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); + cm.Parameters.AddWithValue("@ServerType", _ServerType); + 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); + param_DBID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_DBID); + 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 + _DBID = (int)cm.Parameters["@newDBID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_ConnectionFolders != null) _ConnectionFolders.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addConnection"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + cm.Parameters.AddWithValue("@ConnectionString", connectionString); + cm.Parameters.AddWithValue("@ServerType", serverType); + 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); + param_DBID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_DBID); + 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 + dbid = (int)cm.Parameters["@newDBID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Add", ex); + throw new DbCslaException("Connection.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateConnection"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@DBID", _DBID); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); + cm.Parameters.AddWithValue("@ServerType", _ServerType); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_ConnectionFolders != null) _ConnectionFolders.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Connection.Add(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID); + else + _LastChanged = Connection.Update(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + if (_ConnectionFolders != null) _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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateConnection"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DBID", dbid); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + cm.Parameters.AddWithValue("@ConnectionString", connectionString); + cm.Parameters.AddWithValue("@ServerType", serverType); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteConnection"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteConnection"; + // Input PK Fields + cm.Parameters.AddWithValue("@DBID", dbid); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Remove", ex); + throw new DbCslaException("Connection.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int dbid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(dbid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DBID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int dbid) + { + _DBID = dbid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsConnection"; + cm.Parameters.AddWithValue("@DBID", _DBID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Execute", ex); + throw new DbCslaException("Connection.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ConnectionExtension _ConnectionExtension = new ConnectionExtension(); + [Serializable()] + partial class ConnectionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultServerType + { + get { return 1; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ConnectionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Connection) + { + // Return the ToString value + return ((Connection)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs index 7f4b2076..09227cdd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionFolder.cs @@ -20,618 +20,596 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ConnectionFolder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ConnectionFolderConverter))] - public partial class ConnectionFolder : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _FolderID; - [System.ComponentModel.DataObjectField(true, true)] - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - [System.ComponentModel.DataObjectField(true, true)] - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private Folder _MyParent; - public Folder MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - _ParentID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ShortName", true); - if (value == null) value = string.Empty; - if (_ShortName != value) - { - _ShortName = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ManualOrder", true); - if (_ManualOrder != value) - { - _ManualOrder = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check ConnectionFolder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ConnectionFolder - protected override object GetIdValue() - { - return MyConnectionFolderUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ConnectionFolder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ConnectionFolder - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ShortName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyFolderRequired(ConnectionFolder target, Csla.Validation.RuleArgs e) - { - if (target._ParentID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ShortName, ""); - //AuthorizationRules.AllowWrite(ShortName, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowRead(ManualOrder, ""); - //AuthorizationRules.AllowWrite(ManualOrder, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - private static int _ConnectionFolderUnique = 0; - private static int ConnectionFolderUnique - { get { return ++_ConnectionFolderUnique; } } - private int _MyConnectionFolderUnique = ConnectionFolderUnique; - public int MyConnectionFolderUnique // Absolutely Unique ID - Editable FK - { get { return _MyConnectionFolderUnique; } } - internal static ConnectionFolder New(Folder myParent, string name, string shortName) - { - return new ConnectionFolder(myParent, name, shortName); - } - internal static ConnectionFolder Get(SafeDataReader dr) - { - return new ConnectionFolder(dr); - } - public ConnectionFolder() - { - MarkAsChild(); - _FolderID = Folder.NextFolderID; - _ParentID = _ConnectionFolderExtension.DefaultParentID; - _DTS = _ConnectionFolderExtension.DefaultDTS; - _UsrID = _ConnectionFolderExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private ConnectionFolder(Folder myParent, string name, string shortName) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _FolderID = Folder.NextFolderID; - _ParentID = _ConnectionFolderExtension.DefaultParentID; - _DTS = _ConnectionFolderExtension.DefaultDTS; - _UsrID = _ConnectionFolderExtension.DefaultUsrID; - _MyParent = myParent; - _Name = name; - _ShortName = shortName; - ValidationRules.CheckRules(); - } - internal ConnectionFolder(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ConnectionFolder() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionFolder.FetchDR", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _FormatID = (int?)dr.GetValue("FormatID"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionFolder.FetchDR", ex); - throw new DbCslaException("ConnectionFolder.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Connection myConnection) - { - // 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); - MarkOld(); - } - internal void Update(Connection myConnection) - { - // 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, myConnection.DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Connection myConnection) - { - // 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"]; - Folder.Remove(cn, _FolderID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ConnectionFolderExtension _ConnectionFolderExtension = new ConnectionFolderExtension(); - [Serializable()] - partial class ConnectionFolderExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ConnectionFolderConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ConnectionFolder) - { - // Return the ToString value - return ((ConnectionFolder)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ConnectionFolder Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionFolderConverter))] + public partial class ConnectionFolder : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _FolderID; + [System.ComponentModel.DataObjectField(true, true)] + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + [System.ComponentModel.DataObjectField(true, true)] + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private Folder _MyParent; + public Folder MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + _ParentID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ShortName != value) + { + _ShortName = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ManualOrder != value) + { + _ManualOrder = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check ConnectionFolder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ConnectionFolder + protected override object GetIdValue() + { + return MyConnectionFolderUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ConnectionFolder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ConnectionFolder + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ShortName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyFolderRequired(ConnectionFolder target, Csla.Validation.RuleArgs e) + { + if (target._ParentID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ShortName, ""); + //AuthorizationRules.AllowWrite(ShortName, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + private static int _ConnectionFolderUnique = 0; + private static int ConnectionFolderUnique + { get { return ++_ConnectionFolderUnique; } } + private int _MyConnectionFolderUnique = ConnectionFolderUnique; + public int MyConnectionFolderUnique // Absolutely Unique ID - Editable FK + { get { return _MyConnectionFolderUnique; } } + internal static ConnectionFolder New(Folder myParent, string name, string shortName) + { + return new ConnectionFolder(myParent, name, shortName); + } + internal static ConnectionFolder Get(SafeDataReader dr) + { + return new ConnectionFolder(dr); + } + public ConnectionFolder() + { + MarkAsChild(); + _FolderID = Folder.NextFolderID; + _ParentID = _ConnectionFolderExtension.DefaultParentID; + _DTS = _ConnectionFolderExtension.DefaultDTS; + _UsrID = _ConnectionFolderExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private ConnectionFolder(Folder myParent, string name, string shortName) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _FolderID = Folder.NextFolderID; + _ParentID = _ConnectionFolderExtension.DefaultParentID; + _DTS = _ConnectionFolderExtension.DefaultDTS; + _UsrID = _ConnectionFolderExtension.DefaultUsrID; + _MyParent = myParent; + _Name = name; + _ShortName = shortName; + ValidationRules.CheckRules(); + } + internal ConnectionFolder(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ConnectionFolder() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionFolder.FetchDR", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionFolder.FetchDR", ex); + throw new DbCslaException("ConnectionFolder.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Connection myConnection) + { + // 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); + MarkOld(); + } + internal void Update(Connection myConnection) + { + // 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, myConnection.DBID, _Name, _Title, _ShortName, _FormatID, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Connection myConnection) + { + // 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"]; + Folder.Remove(cn, _FolderID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ConnectionFolderExtension _ConnectionFolderExtension = new ConnectionFolderExtension(); + [Serializable()] + partial class ConnectionFolderExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ConnectionFolderConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ConnectionFolder) + { + // Return the ToString value + return ((ConnectionFolder)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs index 9939a2cd..58f53517 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ConnectionInfo.cs @@ -19,415 +19,405 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ConnectionInfoEvent(object sender); - /// - /// ConnectionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ConnectionInfoConverter))] - public partial class ConnectionInfo : ReadOnlyBase, IDisposable - { - public event ConnectionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ConnectionInfo connectionInfo) - { - if (!_CacheList.Contains(connectionInfo)) _CacheList.Add(connectionInfo); // In AddToCache - } - protected static void RemoveFromCache(ConnectionInfo connectionInfo) - { - while (_CacheList.Contains(connectionInfo)) _CacheList.Remove(connectionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ConnectionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ConnectionInfo tmp = _CacheList[0]; // Get the first ConnectionInfo - string pKey = tmp.DBID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ConnectionInfo - } - } - internal static void AddList(ConnectionInfoList lst) - { - foreach (ConnectionInfo item in lst) AddToCache(item); - } - protected static ConnectionInfo GetCachedByPrimaryKey(int dbid) - { - ConvertListToDictionary(); - string key = dbid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Connection _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _DBID; - [System.ComponentModel.DataObjectField(true, true)] - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - return _DBID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private string _ConnectionString = string.Empty; - public string ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionString", true); - return _ConnectionString; - } - } - private int _ServerType; - /// - /// 0 SQL Server - /// - public int ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ServerType", true); - return _ServerType; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _ConnectionFolderCount = 0; - /// - /// Count of ConnectionFolders for this Connection - /// - public int ConnectionFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolderCount", true); - if (_ConnectionFolderCount < 0) - _ConnectionFolderCount = ConnectionFolders.Count; - return _ConnectionFolderCount; - } - } - private FolderInfoList _ConnectionFolders = null; - [TypeConverter(typeof(FolderInfoListConverter))] - public FolderInfoList ConnectionFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolders", true); - if (_ConnectionFolderCount < 0 || (_ConnectionFolderCount > 0 && _ConnectionFolders == null)) - _ConnectionFolders = FolderInfoList.GetByDBID(_DBID); - if (_ConnectionFolderCount < 0) - _ConnectionFolderCount = _ConnectionFolders.Count; - return _ConnectionFolders; - } - } - public void RefreshConnectionFolders() - { - _ConnectionFolderCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_DBID.ToString())) - foreach (ConnectionInfo tmp in _CacheByPrimaryKey[_DBID.ToString()]) - tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base ConnectionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ConnectionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ConnectionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ConnectionInfo - protected override object GetIdValue() - { - return MyConnectionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ConnectionInfoUnique = 0; - private static int ConnectionInfoUnique - { get { return ++_ConnectionInfoUnique; } } - private int _MyConnectionInfoUnique = ConnectionInfoUnique; - public int MyConnectionInfoUnique // Absolutely Unique ID - Info - { get { return _MyConnectionInfoUnique; } } - protected ConnectionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ConnectionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DBID.ToString())) return; - List listConnectionInfo = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items - while (listConnectionInfo.Contains(this)) listConnectionInfo.Remove(this); // Remove the item from the list - if (listConnectionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list - } - public virtual Connection Get() - { - return _Editable = Connection.Get(_DBID); - } - public static void Refresh(Connection tmp) - { - string key = tmp.DBID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ConnectionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Connection tmp) - { - _Name = tmp.Name; - _Title = tmp.Title; - _ConnectionString = tmp.ConnectionString; - _ServerType = tmp.ServerType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _ConnectionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ConnectionInfo Get(int dbid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Connection"); - try - { - ConnectionInfo tmp = GetCachedByPrimaryKey(dbid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(dbid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ConnectionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ConnectionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ConnectionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.Constructor", ex); - throw new DbCslaException("ConnectionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DBID; - public int DBID - { get { return _DBID; } } - public PKCriteria(int dbid) - { - _DBID = dbid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.ReadData", GetHashCode()); - try - { - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ConnectionString = dr.GetString("ConnectionString"); - _ServerType = dr.GetInt32("ServerType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _ConnectionFolderCount = dr.GetInt32("FolderCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ConnectionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getConnection"; - cm.Parameters.AddWithValue("@DBID", criteria.DBID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ConnectionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ConnectionInfoExtension _ConnectionInfoExtension = new ConnectionInfoExtension(); - [Serializable()] - partial class ConnectionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ConnectionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ConnectionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ConnectionInfo) - { - // Return the ToString value - return ((ConnectionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ConnectionInfoEvent(object sender); + /// + /// ConnectionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionInfoConverter))] + public partial class ConnectionInfo : ReadOnlyBase, IDisposable + { + public event ConnectionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ConnectionInfo connectionInfo) + { + if (!_CacheList.Contains(connectionInfo)) _CacheList.Add(connectionInfo); // In AddToCache + } + protected static void RemoveFromCache(ConnectionInfo connectionInfo) + { + while (_CacheList.Contains(connectionInfo)) _CacheList.Remove(connectionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ConnectionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ConnectionInfo tmp = _CacheList[0]; // Get the first ConnectionInfo + string pKey = tmp.DBID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ConnectionInfo + } + } + internal static void AddList(ConnectionInfoList lst) + { + foreach (ConnectionInfo item in lst) AddToCache(item); + } + protected static ConnectionInfo GetCachedByPrimaryKey(int dbid) + { + ConvertListToDictionary(); + string key = dbid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Connection _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _DBID; + [System.ComponentModel.DataObjectField(true, true)] + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private string _ConnectionString = string.Empty; + public string ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConnectionString; + } + } + private int _ServerType; + /// + /// 0 SQL Server + /// + public int ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ServerType; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _ConnectionFolderCount = 0; + /// + /// Count of ConnectionFolders for this Connection + /// + public int ConnectionFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ConnectionFolderCount < 0) + _ConnectionFolderCount = ConnectionFolders.Count; + return _ConnectionFolderCount; + } + } + private FolderInfoList _ConnectionFolders = null; + [TypeConverter(typeof(FolderInfoListConverter))] + public FolderInfoList ConnectionFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ConnectionFolderCount < 0 || (_ConnectionFolderCount > 0 && _ConnectionFolders == null)) + _ConnectionFolders = FolderInfoList.GetByDBID(_DBID); + if (_ConnectionFolderCount < 0) + _ConnectionFolderCount = _ConnectionFolders.Count; + return _ConnectionFolders; + } + } + public void RefreshConnectionFolders() + { + _ConnectionFolderCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_DBID.ToString())) + foreach (ConnectionInfo tmp in _CacheByPrimaryKey[_DBID.ToString()]) + tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base ConnectionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ConnectionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ConnectionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ConnectionInfo + protected override object GetIdValue() + { + return MyConnectionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ConnectionInfoUnique = 0; + private static int ConnectionInfoUnique + { get { return ++_ConnectionInfoUnique; } } + private int _MyConnectionInfoUnique = ConnectionInfoUnique; + public int MyConnectionInfoUnique // Absolutely Unique ID - Info + { get { return _MyConnectionInfoUnique; } } + protected ConnectionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ConnectionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DBID.ToString())) return; + List listConnectionInfo = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items + while (listConnectionInfo.Contains(this)) listConnectionInfo.Remove(this); // Remove the item from the list + if (listConnectionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list + } + public virtual Connection Get() + { + return _Editable = Connection.Get(_DBID); + } + public static void Refresh(Connection tmp) + { + string key = tmp.DBID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ConnectionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Connection tmp) + { + _Name = tmp.Name; + _Title = tmp.Title; + _ConnectionString = tmp.ConnectionString; + _ServerType = tmp.ServerType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _ConnectionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ConnectionInfo Get(int dbid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Connection"); + try + { + ConnectionInfo tmp = GetCachedByPrimaryKey(dbid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dbid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ConnectionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ConnectionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ConnectionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.Constructor", ex); + throw new DbCslaException("ConnectionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DBID; + public int DBID + { get { return _DBID; } } + public PKCriteria(int dbid) + { + _DBID = dbid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.ReadData", GetHashCode()); + try + { + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ConnectionString = dr.GetString("ConnectionString"); + _ServerType = dr.GetInt32("ServerType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _ConnectionFolderCount = dr.GetInt32("FolderCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ConnectionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnection"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ConnectionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ConnectionInfoExtension _ConnectionInfoExtension = new ConnectionInfoExtension(); + [Serializable()] + partial class ConnectionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ConnectionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ConnectionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ConnectionInfo) + { + // Return the ToString value + return ((ConnectionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs index a106880d..743a7fdd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs @@ -20,1618 +20,1583 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Content Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentConverter))] - public partial class Content : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshContents = new List(); - private List _RefreshContentDetails = new List(); - private List _RefreshContentItems = new List(); - private List _RefreshContentParts = new List(); - private List _RefreshContentRoUsages = new List(); - private List _RefreshContentTransitions = new List(); - private void AddToRefreshList(List refreshContents, List refreshContentDetails, List refreshContentItems, List refreshContentParts, List refreshContentRoUsages, List refreshContentTransitions) - { - if (IsDirty) - refreshContents.Add(this); - if (_ContentDetails != null && _ContentDetails.IsDirty) - { - foreach (ContentDetail tmp in _ContentDetails) - { - if (tmp.IsDirty) refreshContentDetails.Add(tmp); - } - } - if (_ContentItems != null && _ContentItems.IsDirty) - { - foreach (ContentItem tmp in _ContentItems) - { - if (tmp.IsDirty) refreshContentItems.Add(tmp); - } - } - if (_ContentParts != null && _ContentParts.IsDirty) - { - foreach (ContentPart tmp in _ContentParts) - { - if (tmp.IsDirty) refreshContentParts.Add(tmp); - } - } - if (_ContentRoUsages != null && _ContentRoUsages.IsDirty) - { - foreach (ContentRoUsage tmp in _ContentRoUsages) - { - if (tmp.IsDirty) refreshContentRoUsages.Add(tmp); - } - } - if (_ContentTransitions != null && _ContentTransitions.IsDirty) - { - foreach (ContentTransition tmp in _ContentTransitions) - { - if (tmp.IsDirty) refreshContentTransitions.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshContents = new List(); - _RefreshContentDetails = new List(); - _RefreshContentItems = new List(); - _RefreshContentParts = new List(); - _RefreshContentRoUsages = new List(); - _RefreshContentTransitions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshContents, _RefreshContentDetails, _RefreshContentItems, _RefreshContentParts, _RefreshContentRoUsages, _RefreshContentTransitions); - } - private void ProcessRefreshList() - { - foreach (Content tmp in _RefreshContents) - { - ContentInfo.Refresh(tmp); - if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); - } - foreach (ContentDetail tmp in _RefreshContentDetails) - { - DetailInfo.Refresh(tmp); - } - foreach (ContentItem tmp in _RefreshContentItems) - { - ItemInfo.Refresh(tmp); - } - foreach (ContentPart tmp in _RefreshContentParts) - { - PartInfo.Refresh(this, tmp); - } - foreach (ContentRoUsage tmp in _RefreshContentRoUsages) - { - RoUsageInfo.Refresh(tmp); - } - foreach (ContentTransition tmp in _RefreshContentTransitions) - { - TransitionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Content content) - { - if (!_CacheList.Contains(content)) _CacheList.Add(content); // In AddToCache - } - protected static void RemoveFromCache(Content content) - { - while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Content(s) from temporary _CacheList to _CacheByPrimaryKey - { - Content tmp = _CacheList[0]; // Get the first Content - if (!tmp.Disposed) - { - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - } - _CacheList.RemoveAt(0); // Remove the first Content - } - } - protected static Content GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextContentID = -1; - public static int NextContentID - { - get { return _nextContentID--; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private string _Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Number", true); - if (value == null) value = string.Empty; - if (_Number != value) - { - _Number = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - if (Disposed) throw new Exception("Attempt to access Disposed Object"); - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - if (Disposed) throw new Exception("Attempt to access Disposed Object"); - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private int? _Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Type", true); - if (_Type != value) - { - _Type = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public byte[] LastChanged - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LastChanged", true); - return _LastChanged; - } - set { _LastChanged = value; } - } - private int _ContentDetailCount = 0; - /// - /// Count of ContentDetails for this Content - /// - public int ContentDetailCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetailCount", true); - return _ContentDetailCount; - } - } - private ContentDetails _ContentDetails = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentDetailsConverter))] - public ContentDetails ContentDetails - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetails", true); - if (_ContentDetailCount < 0 || (_ContentDetailCount > 0 && _ContentDetails == null)) - _ContentDetails = ContentDetails.GetByContentID(ContentID); - if (_ContentDetailCount < 0 ) - _ContentDetailCount = _ContentDetails == null ? 0 : _ContentDetails.Count; - if (_ContentDetails == null) - _ContentDetails = ContentDetails.New(); - return _ContentDetails; - } - } - public void Reset_ContentDetails() - { - _ContentDetailCount = -1; - } - private int _ContentEntryCount = 0; - /// - /// Count of ContentEntries for this Content - /// - public int ContentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentEntryCount", true); - return _ContentEntryCount; - } - } - private Entry _MyEntry = null; - /// - /// Related Field - /// - [TypeConverter(typeof(EntryConverter))] - public Entry MyEntry - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyEntry", true); - if (_MyEntry == null) _MyEntry = Entry.New(this); - return _MyEntry; - } - } - [TypeConverter(typeof(EntryConverter))] - public Entry LocalEntry - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get { return _MyEntry; } - } - private int _ContentGridCount = 0; - /// - /// Count of ContentGrids for this Content - /// - public int ContentGridCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentGridCount", true); - return _ContentGridCount; - } - } - private Grid _MyGrid = null; - /// - /// Related Field - /// - [TypeConverter(typeof(GridConverter))] - public Grid MyGrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGrid", true); - if (_MyGrid == null) _MyGrid = Grid.New(this); - return _MyGrid; - } - set - { - _MyGrid = value; - } - } - private int _ContentImageCount = 0; - /// - /// Count of ContentImages for this Content - /// - public int ContentImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentImageCount", true); - return _ContentImageCount; - } - } - private Image _MyImage = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ImageConverter))] - public Image MyImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyImage", true); - if (_MyImage == null) _MyImage = Image.New(this); - return _MyImage; - } - } - private int _ContentItemCount = 0; - /// - /// Count of ContentItems for this Content - /// - public int ContentItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItemCount", true); - return _ContentItemCount; - } - } - private ContentItems _ContentItems = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentItemsConverter))] - public ContentItems ContentItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItems", true); - if (_ContentItemCount < 0 || (_ContentItemCount > 0 && _ContentItems == null)) - _ContentItems = ContentItems.GetByContentID(ContentID); - if (_ContentItemCount < 0 ) - _ContentItemCount = _ContentItems == null ? 0 : _ContentItems.Count; - if (_ContentItems == null) - _ContentItems = ContentItems.New(); - return _ContentItems; - } - } - public void Reset_ContentItems() - { - _ContentItemCount = -1; - } - private int _ContentPartCount = 0; - /// - /// Count of ContentParts for this Content - /// - public int ContentPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentPartCount", true); - return _ContentPartCount; - } - } - private ContentParts _ContentParts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentPartsConverter))] - public ContentParts ContentParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentParts", true); - if (_ContentPartCount < 0 || (_ContentPartCount > 0 && _ContentParts == null)) - _ContentParts = ContentParts.GetByContentID(ContentID); - if (_ContentPartCount < 0 ) - _ContentPartCount = _ContentParts == null ? 0 : _ContentParts.Count; - if (_ContentParts == null) - _ContentParts = ContentParts.New(); - return _ContentParts; - } - } - public void Reset_ContentParts() - { - _ContentPartCount = -1; - } - private int _ContentRoUsageCount = 0; - /// - /// Count of ContentRoUsages for this Content - /// - public int ContentRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsageCount", true); - if (_ContentRoUsageCount < 0) - _ContentRoUsageCount = ContentRoUsages.Count; - return _ContentRoUsageCount; - } - } - private ContentRoUsages _ContentRoUsages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentRoUsagesConverter))] - public ContentRoUsages ContentRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsages", true); - if (_ContentRoUsageCount < 0 || (_ContentRoUsageCount > 0 && _ContentRoUsages == null)) - _ContentRoUsages = ContentRoUsages.GetByContentID(ContentID); - if (_ContentRoUsageCount < 0 ) - _ContentRoUsageCount = _ContentRoUsages == null ? 0 : _ContentRoUsages.Count; - if (_ContentRoUsages == null) - _ContentRoUsages = ContentRoUsages.New(); - return _ContentRoUsages; - } - } - public void Reset_ContentRoUsages() - { - _ContentRoUsageCount = -1; - } - private int _ContentTransitionCount = 0; - /// - /// Count of ContentTransitions for this Content - /// - public int ContentTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitionCount", true); - if (_ContentTransitionCount < 0) - _ContentTransitionCount = ContentTransitions.Count; - return _ContentTransitionCount; - } - } - private ContentTransitions _ContentTransitions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentTransitionsConverter))] - public ContentTransitions ContentTransitions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitions", true); - if (_ContentTransitionCount < 0 || (_ContentTransitionCount > 0 && _ContentTransitions == null)) - _ContentTransitions = ContentTransitions.GetByFromID(ContentID); - if (_ContentTransitionCount < 0 ) - _ContentTransitionCount = _ContentTransitions == null ? 0 : _ContentTransitions.Count; - if (_ContentTransitions == null) - _ContentTransitions = ContentTransitions.New(); - return _ContentTransitions; - } - } - public void Reset_ContentTransitions() - { - _ContentTransitionCount = -1; - } - private int _ContentZContentCount = 0; - /// - /// Count of ContentZContents for this Content - /// - public int ContentZContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentZContentCount", true); - return _ContentZContentCount; - } - } - private ZContent _MyZContent = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ZContentConverter))] - public ZContent MyZContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZContent", true); - if (_MyZContent == null) _MyZContent = ZContent.New(this); - return _MyZContent; - } - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_ContentDetails == null ? false : _ContentDetails.IsDirtyList(list)) || (_MyEntry == null ? false : _MyEntry.IsDirtyList(list)) || (_MyGrid == null ? false : _MyGrid.IsDirtyList(list)) || (_MyImage == null ? false : _MyImage.IsDirtyList(list)) || (_ContentItems == null ? false : _ContentItems.IsDirtyList(list)) || (_ContentParts == null ? false : _ContentParts.IsDirtyList(list)) || (_ContentRoUsages == null ? false : _ContentRoUsages.IsDirtyList(list)) || (_ContentTransitions == null ? false : _ContentTransitions.IsDirtyList(list)) || (_MyZContent == null ? false : _MyZContent.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ContentDetails == null ? true : _ContentDetails.IsValidList(list)) && (_MyEntry == null ? true : _MyEntry.IsValidList(list)) && (_MyGrid == null ? true : _MyGrid.IsValidList(list)) && (_MyImage == null ? true : _MyImage.IsValidList(list)) && (_ContentItems == null ? true : _ContentItems.IsValidList(list)) && (_ContentParts == null ? true : _ContentParts.IsValidList(list)) && (_ContentRoUsages == null ? true : _ContentRoUsages.IsValidList(list)) && (_ContentTransitions == null ? true : _ContentTransitions.IsValidList(list)) && (_MyZContent == null ? true : _MyZContent.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list)); - } - // CSLATODO: Replace base Content.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Content - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Content.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Content - protected override object GetIdValue() - { - return MyContentUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ContentItems != null && (hasBrokenRules = _ContentItems.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentDetails != null && (hasBrokenRules = _ContentDetails.HasBrokenRules) != null) return hasBrokenRules; - if (_MyEntry != null && (hasBrokenRules = _MyEntry.HasBrokenRules) != null) return hasBrokenRules; - if (_MyGrid != null && (hasBrokenRules = _MyGrid.HasBrokenRules) != null) return hasBrokenRules; - if (_MyImage != null && (hasBrokenRules = _MyImage.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentParts != null && (hasBrokenRules = _ContentParts.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentRoUsages != null && (hasBrokenRules = _ContentRoUsages.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentTransitions != null && (hasBrokenRules = _ContentTransitions.HasBrokenRules) != null) return hasBrokenRules; - if (_MyZContent != null && (hasBrokenRules = _MyZContent.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 256)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ContentExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ContentExtension.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, ""); - //AuthorizationRules.AllowRead(Number, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowRead(Type, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(Number, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowWrite(Type, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ContentExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ContentExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ContentDetailCount; - usedByCount += _ContentEntryCount; - usedByCount += _ContentGridCount; - usedByCount += _ContentImageCount; - usedByCount += _ContentItemCount; - usedByCount += _ContentPartCount; - usedByCount += _ContentRoUsageCount; - usedByCount += _ContentTransitionCount; - usedByCount += _ContentZContentCount; - 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; } } - private static int _ContentUnique = 0; - protected static int ContentUnique - { get { return ++_ContentUnique; } } - private int _MyContentUnique = ContentUnique; - public int MyContentUnique // Absolutely Unique ID - Editable - { get { return _MyContentUnique; } } - protected Content() - {/* require use of factory methods */ - AddToCache(this); - } - private bool _Disposed = false; - public bool Disposed - { - get { return _Disposed; } - set { _Disposed = value; } - } - 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; } } - ~Content() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - if (_MyZContent != null) // 9.79 - { - _MyZContent.Dispose(); - _MyZContent = null; - } - if (_ContentParts != null) // 8.93 - { - foreach (ContentPart cp in _ContentParts) - cp.Dispose(); - _ContentParts = null; - } - if (_MyEntry != null) // .465 - { - _MyEntry.Dispose(); - _MyEntry = null; - } - if (_MyGrid != null) - { - _MyGrid.Dispose(); - _MyGrid = null; - } - _Text = null; - //if (_ContentDetails != null) - // _ContentDetails = null; - //if (_ContentItems != null) - //{ - // _ContentItems = null; - // //foreach (ContentItem ci in _ContentItems) - // // ci.Dispose(); - //} - //if (_ContentRoUsages != null) - //{ - // //foreach (ContentRoUsage cr in _ContentRoUsages) - // // cr.Dispose(); - // _ContentRoUsages = null; - //} - //if (_ContentTransitions != null) - //{ - // foreach (ContentTransition ct in _ContentTransitions) - // ct.Dispose(); - // _ContentTransitions = null; - //} - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listContent.Contains(this)) listContent.Remove(this); // Remove the item from the list - if (listContent.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static Content New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Content"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.New", ex); - } - } - public static Content New(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) - { - Content tmp = Content.New(); - tmp.Number = number; - tmp.Text = text; - tmp.Type = type; - tmp.MyFormat = myFormat; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Content MakeContent(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) - { - Content tmp = Content.New(number, text, type, myFormat, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Content New(string number, string text, int? type, Format myFormat, string config) - { - Content tmp = Content.New(); - tmp.Number = number; - tmp.Text = text; - tmp.Type = type; - tmp.MyFormat = myFormat; - tmp.Config = config; - return tmp; - } - public static Content MakeContent(string number, string text, int? type, Format myFormat, string config) - { - Content tmp = Content.New(number, text, type, myFormat, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Content Get(int contentID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Content"); - try - { - Content tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Content - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.Get", ex); - } - } - public static Content Get(SafeDataReader dr) - { - if (dr.Read()) return new Content(dr); - return null; - } - internal Content(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int contentID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Content"); - try - { - DataPortal.Delete(new PKCriteria(contentID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.Delete", ex); - } - } - public override Content Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Content"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Content"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Content"); - try - { - BuildRefreshList(); - Content content = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(content);//Refresh the item in AllList - ProcessRefreshList(); - return content; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ContentID = NextContentID; - // Database Defaults - _DTS = _ContentExtension.DefaultDTS; - _UserID = _ContentExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ContentDetailCount = dr.GetInt32("DetailCount"); - _ContentEntryCount = dr.GetInt32("EntryCount"); - _ContentGridCount = dr.GetInt32("GridCount"); - _ContentImageCount = dr.GetInt32("ImageCount"); - _ContentItemCount = dr.GetInt32("ItemCount"); - _ContentPartCount = dr.GetInt32("PartCount"); - _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); - _ContentTransitionCount = dr.GetInt32("TransitionCount"); - _ContentZContentCount = dr.GetInt32("ZContentCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Content.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ContentDetails = ContentDetails.Get(dr); - // load child objects - dr.NextResult(); - _MyEntry = Entry.Get(dr); - // load child objects - dr.NextResult(); - _MyGrid = Grid.Get(dr); - // load child objects - dr.NextResult(); - _MyImage = Image.Get(dr); - // load child objects - dr.NextResult(); - _ContentItems = ContentItems.Get(dr); - // load child objects - dr.NextResult(); - _ContentParts = ContentParts.Get(dr); - // load child objects - dr.NextResult(); - _ContentRoUsages = ContentRoUsages.Get(dr); - // load child objects - dr.NextResult(); - _ContentTransitions = ContentTransitions.Get(dr); - // load child objects - dr.NextResult(); - _MyZContent = ZContent.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Content.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Content.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyFormat != null) _MyFormat.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); - param_ContentID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ContentID); - 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 - _ContentID = (int)cm.Parameters["@newContentID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_ContentItems != null) _ContentItems.Update(this); - if (_ContentDetails != null) _ContentDetails.Update(this); - if (_MyEntry != null) _MyEntry.Update(this); - if (_MyGrid != null) _MyGrid.Update(this); - if (_MyImage != null) _MyImage.Update(this); - if (_ContentParts != null) _ContentParts.Update(this); - if (_ContentRoUsages != null) _ContentRoUsages.Update(this); - if (_ContentTransitions != null) _ContentTransitions.Update(this); - if (_MyZContent != null) _MyZContent.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); - param_ContentID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ContentID); - 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 - contentID = (int)cm.Parameters["@newContentID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Add", ex); - throw new DbCslaException("Content.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Content.SQLUpdate", GetHashCode()); - try - { - if (_MyFormat != null) _MyFormat.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - //Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString()); - cm.CommandText = "updateContent"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_ContentItems != null) _ContentItems.Update(this); - if (_ContentDetails != null) _ContentDetails.Update(this); - if (_MyEntry != null) _MyEntry.Update(this); - if (_MyGrid != null) _MyGrid.Update(this); - if (_MyImage != null) _MyImage.Update(this); - if (_ContentParts != null) _ContentParts.Update(this); - if (_ContentRoUsages != null) _ContentRoUsages.Update(this); - if (_ContentTransitions != null) _ContentTransitions.Update(this); - if (_MyZContent != null) _MyZContent.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID); - else - _LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_ContentItems != null) _ContentItems.Update(this); - if (_ContentDetails != null) _ContentDetails.Update(this); - if (_MyEntry != null) _MyEntry.Update(this); - if (_MyGrid != null) _MyGrid.Update(this); - if (_MyImage != null) _MyImage.Update(this); - if (_ContentParts != null) _ContentParts.Update(this); - if (_ContentRoUsages != null) _ContentRoUsages.Update(this); - if (_ContentTransitions != null) _ContentTransitions.Update(this); - if (_MyZContent != null) _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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteContent"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Remove", ex); - throw new DbCslaException("Content.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsContent"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Execute", ex); - throw new DbCslaException("Content.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ContentExtension _ContentExtension = new ContentExtension(); - [Serializable()] - partial class ContentExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Content) - { - // Return the ToString value - return ((Content)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Content Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentConverter))] + public partial class Content : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshContents = new List(); + private List _RefreshContentDetails = new List(); + private List _RefreshContentItems = new List(); + private List _RefreshContentParts = new List(); + private List _RefreshContentRoUsages = new List(); + private List _RefreshContentTransitions = new List(); + private void AddToRefreshList(List refreshContents, List refreshContentDetails, List refreshContentItems, List refreshContentParts, List refreshContentRoUsages, List refreshContentTransitions) + { + if (IsDirty) + refreshContents.Add(this); + if (_ContentDetails != null && _ContentDetails.IsDirty) + { + foreach (ContentDetail tmp in _ContentDetails) + { + if (tmp.IsDirty) refreshContentDetails.Add(tmp); + } + } + if (_ContentItems != null && _ContentItems.IsDirty) + { + foreach (ContentItem tmp in _ContentItems) + { + if (tmp.IsDirty) refreshContentItems.Add(tmp); + } + } + if (_ContentParts != null && _ContentParts.IsDirty) + { + foreach (ContentPart tmp in _ContentParts) + { + if (tmp.IsDirty) refreshContentParts.Add(tmp); + } + } + if (_ContentRoUsages != null && _ContentRoUsages.IsDirty) + { + foreach (ContentRoUsage tmp in _ContentRoUsages) + { + if (tmp.IsDirty) refreshContentRoUsages.Add(tmp); + } + } + if (_ContentTransitions != null && _ContentTransitions.IsDirty) + { + foreach (ContentTransition tmp in _ContentTransitions) + { + if (tmp.IsDirty) refreshContentTransitions.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshContents = new List(); + _RefreshContentDetails = new List(); + _RefreshContentItems = new List(); + _RefreshContentParts = new List(); + _RefreshContentRoUsages = new List(); + _RefreshContentTransitions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshContents, _RefreshContentDetails, _RefreshContentItems, _RefreshContentParts, _RefreshContentRoUsages, _RefreshContentTransitions); + } + private void ProcessRefreshList() + { + foreach (Content tmp in _RefreshContents) + { + ContentInfo.Refresh(tmp); + if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); + } + foreach (ContentDetail tmp in _RefreshContentDetails) + { + DetailInfo.Refresh(tmp); + } + foreach (ContentItem tmp in _RefreshContentItems) + { + ItemInfo.Refresh(tmp); + } + foreach (ContentPart tmp in _RefreshContentParts) + { + PartInfo.Refresh(this, tmp); + } + foreach (ContentRoUsage tmp in _RefreshContentRoUsages) + { + RoUsageInfo.Refresh(tmp); + } + foreach (ContentTransition tmp in _RefreshContentTransitions) + { + TransitionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Content content) + { + if (!_CacheList.Contains(content)) _CacheList.Add(content); // In AddToCache + } + protected static void RemoveFromCache(Content content) + { + while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Content(s) from temporary _CacheList to _CacheByPrimaryKey + { + Content tmp = _CacheList[0]; // Get the first Content + if (!tmp.Disposed) + { + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + } + _CacheList.RemoveAt(0); // Remove the first Content + } + } + protected static Content GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextContentID = -1; + public static int NextContentID + { + get { return _nextContentID--; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private string _Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Number != value) + { + _Number = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (Disposed) throw new Exception("Attempt to access Disposed Object"); + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (Disposed) throw new Exception("Attempt to access Disposed Object"); + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private int? _Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Type != value) + { + _Type = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public byte[] LastChanged + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LastChanged; + } + set { _LastChanged = value; } + } + private int _ContentDetailCount = 0; + /// + /// Count of ContentDetails for this Content + /// + public int ContentDetailCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentDetailCount; + } + } + private ContentDetails _ContentDetails = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentDetailsConverter))] + public ContentDetails ContentDetails + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentDetailCount < 0 || (_ContentDetailCount > 0 && _ContentDetails == null)) + _ContentDetails = ContentDetails.GetByContentID(ContentID); + if (_ContentDetailCount < 0) + _ContentDetailCount = _ContentDetails == null ? 0 : _ContentDetails.Count; + if (_ContentDetails == null) + _ContentDetails = ContentDetails.New(); + return _ContentDetails; + } + } + public void Reset_ContentDetails() + { + _ContentDetailCount = -1; + } + private int _ContentEntryCount = 0; + /// + /// Count of ContentEntries for this Content + /// + public int ContentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentEntryCount; + } + } + private Entry _MyEntry = null; + /// + /// Related Field + /// + [TypeConverter(typeof(EntryConverter))] + public Entry MyEntry + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyEntry == null) _MyEntry = Entry.New(this); + return _MyEntry; + } + } + [TypeConverter(typeof(EntryConverter))] + public Entry LocalEntry + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get { return _MyEntry; } + } + private int _ContentGridCount = 0; + /// + /// Count of ContentGrids for this Content + /// + public int ContentGridCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentGridCount; + } + } + private Grid _MyGrid = null; + /// + /// Related Field + /// + [TypeConverter(typeof(GridConverter))] + public Grid MyGrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGrid == null) _MyGrid = Grid.New(this); + return _MyGrid; + } + set + { + _MyGrid = value; + } + } + private int _ContentImageCount = 0; + /// + /// Count of ContentImages for this Content + /// + public int ContentImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentImageCount; + } + } + private Image _MyImage = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ImageConverter))] + public Image MyImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyImage == null) _MyImage = Image.New(this); + return _MyImage; + } + } + private int _ContentItemCount = 0; + /// + /// Count of ContentItems for this Content + /// + public int ContentItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentItemCount; + } + } + private ContentItems _ContentItems = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentItemsConverter))] + public ContentItems ContentItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentItemCount < 0 || (_ContentItemCount > 0 && _ContentItems == null)) + _ContentItems = ContentItems.GetByContentID(ContentID); + if (_ContentItemCount < 0) + _ContentItemCount = _ContentItems == null ? 0 : _ContentItems.Count; + if (_ContentItems == null) + _ContentItems = ContentItems.New(); + return _ContentItems; + } + } + public void Reset_ContentItems() + { + _ContentItemCount = -1; + } + private int _ContentPartCount = 0; + /// + /// Count of ContentParts for this Content + /// + public int ContentPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentPartCount; + } + } + private ContentParts _ContentParts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentPartsConverter))] + public ContentParts ContentParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentPartCount < 0 || (_ContentPartCount > 0 && _ContentParts == null)) + _ContentParts = ContentParts.GetByContentID(ContentID); + if (_ContentPartCount < 0) + _ContentPartCount = _ContentParts == null ? 0 : _ContentParts.Count; + if (_ContentParts == null) + _ContentParts = ContentParts.New(); + return _ContentParts; + } + } + public void Reset_ContentParts() + { + _ContentPartCount = -1; + } + private int _ContentRoUsageCount = 0; + /// + /// Count of ContentRoUsages for this Content + /// + public int ContentRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentRoUsageCount < 0) + _ContentRoUsageCount = ContentRoUsages.Count; + return _ContentRoUsageCount; + } + } + private ContentRoUsages _ContentRoUsages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentRoUsagesConverter))] + public ContentRoUsages ContentRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentRoUsageCount < 0 || (_ContentRoUsageCount > 0 && _ContentRoUsages == null)) + _ContentRoUsages = ContentRoUsages.GetByContentID(ContentID); + if (_ContentRoUsageCount < 0) + _ContentRoUsageCount = _ContentRoUsages == null ? 0 : _ContentRoUsages.Count; + if (_ContentRoUsages == null) + _ContentRoUsages = ContentRoUsages.New(); + return _ContentRoUsages; + } + } + public void Reset_ContentRoUsages() + { + _ContentRoUsageCount = -1; + } + private int _ContentTransitionCount = 0; + /// + /// Count of ContentTransitions for this Content + /// + public int ContentTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentTransitionCount < 0) + _ContentTransitionCount = ContentTransitions.Count; + return _ContentTransitionCount; + } + } + private ContentTransitions _ContentTransitions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentTransitionsConverter))] + public ContentTransitions ContentTransitions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentTransitionCount < 0 || (_ContentTransitionCount > 0 && _ContentTransitions == null)) + _ContentTransitions = ContentTransitions.GetByFromID(ContentID); + if (_ContentTransitionCount < 0) + _ContentTransitionCount = _ContentTransitions == null ? 0 : _ContentTransitions.Count; + if (_ContentTransitions == null) + _ContentTransitions = ContentTransitions.New(); + return _ContentTransitions; + } + } + public void Reset_ContentTransitions() + { + _ContentTransitionCount = -1; + } + private int _ContentZContentCount = 0; + /// + /// Count of ContentZContents for this Content + /// + public int ContentZContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentZContentCount; + } + } + private ZContent _MyZContent = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ZContentConverter))] + public ZContent MyZContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyZContent == null) _MyZContent = ZContent.New(this); + return _MyZContent; + } + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_ContentDetails == null ? false : _ContentDetails.IsDirtyList(list)) || (_MyEntry == null ? false : _MyEntry.IsDirtyList(list)) || (_MyGrid == null ? false : _MyGrid.IsDirtyList(list)) || (_MyImage == null ? false : _MyImage.IsDirtyList(list)) || (_ContentItems == null ? false : _ContentItems.IsDirtyList(list)) || (_ContentParts == null ? false : _ContentParts.IsDirtyList(list)) || (_ContentRoUsages == null ? false : _ContentRoUsages.IsDirtyList(list)) || (_ContentTransitions == null ? false : _ContentTransitions.IsDirtyList(list)) || (_MyZContent == null ? false : _MyZContent.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ContentDetails == null ? true : _ContentDetails.IsValidList(list)) && (_MyEntry == null ? true : _MyEntry.IsValidList(list)) && (_MyGrid == null ? true : _MyGrid.IsValidList(list)) && (_MyImage == null ? true : _MyImage.IsValidList(list)) && (_ContentItems == null ? true : _ContentItems.IsValidList(list)) && (_ContentParts == null ? true : _ContentParts.IsValidList(list)) && (_ContentRoUsages == null ? true : _ContentRoUsages.IsValidList(list)) && (_ContentTransitions == null ? true : _ContentTransitions.IsValidList(list)) && (_MyZContent == null ? true : _MyZContent.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list)); + } + // CSLATODO: Replace base Content.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Content + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Content.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Content + protected override object GetIdValue() + { + return MyContentUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ContentItems != null && (hasBrokenRules = _ContentItems.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentDetails != null && (hasBrokenRules = _ContentDetails.HasBrokenRules) != null) return hasBrokenRules; + if (_MyEntry != null && (hasBrokenRules = _MyEntry.HasBrokenRules) != null) return hasBrokenRules; + if (_MyGrid != null && (hasBrokenRules = _MyGrid.HasBrokenRules) != null) return hasBrokenRules; + if (_MyImage != null && (hasBrokenRules = _MyImage.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentParts != null && (hasBrokenRules = _ContentParts.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentRoUsages != null && (hasBrokenRules = _ContentRoUsages.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentTransitions != null && (hasBrokenRules = _ContentTransitions.HasBrokenRules) != null) return hasBrokenRules; + if (_MyZContent != null && (hasBrokenRules = _MyZContent.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 256)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ContentExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ContentExtension.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, ""); + //AuthorizationRules.AllowRead(Number, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowRead(Type, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(Number, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowWrite(Type, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ContentExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ContentExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ContentDetailCount; + usedByCount += _ContentEntryCount; + usedByCount += _ContentGridCount; + usedByCount += _ContentImageCount; + usedByCount += _ContentItemCount; + usedByCount += _ContentPartCount; + usedByCount += _ContentRoUsageCount; + usedByCount += _ContentTransitionCount; + usedByCount += _ContentZContentCount; + 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; } } + private static int _ContentUnique = 0; + protected static int ContentUnique + { get { return ++_ContentUnique; } } + private int _MyContentUnique = ContentUnique; + public int MyContentUnique // Absolutely Unique ID - Editable + { get { return _MyContentUnique; } } + protected Content() + {/* require use of factory methods */ + AddToCache(this); + } + private bool _Disposed = false; + public bool Disposed + { + get { return _Disposed; } + set { _Disposed = value; } + } + 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; } } + ~Content() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + if (_MyZContent != null) // 9.79 + { + _MyZContent.Dispose(); + _MyZContent = null; + } + if (_ContentParts != null) // 8.93 + { + foreach (ContentPart cp in _ContentParts) + cp.Dispose(); + _ContentParts = null; + } + if (_MyEntry != null) // .465 + { + _MyEntry.Dispose(); + _MyEntry = null; + } + if (_MyGrid != null) + { + _MyGrid.Dispose(); + _MyGrid = null; + } + _Text = null; + //if (_ContentDetails != null) + // _ContentDetails = null; + //if (_ContentItems != null) + //{ + // _ContentItems = null; + // //foreach (ContentItem ci in _ContentItems) + // // ci.Dispose(); + //} + //if (_ContentRoUsages != null) + //{ + // //foreach (ContentRoUsage cr in _ContentRoUsages) + // // cr.Dispose(); + // _ContentRoUsages = null; + //} + //if (_ContentTransitions != null) + //{ + // foreach (ContentTransition ct in _ContentTransitions) + // ct.Dispose(); + // _ContentTransitions = null; + //} + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listContent.Contains(this)) listContent.Remove(this); // Remove the item from the list + if (listContent.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static Content New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Content"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.New", ex); + } + } + public static Content New(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) + { + Content tmp = Content.New(); + tmp.Number = number; + tmp.Text = text; + tmp.Type = type; + tmp.MyFormat = myFormat; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Content MakeContent(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) + { + Content tmp = Content.New(number, text, type, myFormat, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Content New(string number, string text, int? type, Format myFormat, string config) + { + Content tmp = Content.New(); + tmp.Number = number; + tmp.Text = text; + tmp.Type = type; + tmp.MyFormat = myFormat; + tmp.Config = config; + return tmp; + } + public static Content MakeContent(string number, string text, int? type, Format myFormat, string config) + { + Content tmp = Content.New(number, text, type, myFormat, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Content Get(int contentID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Content"); + try + { + Content tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Content + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.Get", ex); + } + } + public static Content Get(SafeDataReader dr) + { + if (dr.Read()) return new Content(dr); + return null; + } + internal Content(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int contentID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Content"); + try + { + DataPortal.Delete(new PKCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.Delete", ex); + } + } + public override Content Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Content"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Content"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Content"); + try + { + BuildRefreshList(); + Content content = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(content);//Refresh the item in AllList + ProcessRefreshList(); + return content; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ContentID = NextContentID; + // Database Defaults + _DTS = _ContentExtension.DefaultDTS; + _UserID = _ContentExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ContentDetailCount = dr.GetInt32("DetailCount"); + _ContentEntryCount = dr.GetInt32("EntryCount"); + _ContentGridCount = dr.GetInt32("GridCount"); + _ContentImageCount = dr.GetInt32("ImageCount"); + _ContentItemCount = dr.GetInt32("ItemCount"); + _ContentPartCount = dr.GetInt32("PartCount"); + _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); + _ContentTransitionCount = dr.GetInt32("TransitionCount"); + _ContentZContentCount = dr.GetInt32("ZContentCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Content.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ContentDetails = ContentDetails.Get(dr); + // load child objects + dr.NextResult(); + _MyEntry = Entry.Get(dr); + // load child objects + dr.NextResult(); + _MyGrid = Grid.Get(dr); + // load child objects + dr.NextResult(); + _MyImage = Image.Get(dr); + // load child objects + dr.NextResult(); + _ContentItems = ContentItems.Get(dr); + // load child objects + dr.NextResult(); + _ContentParts = ContentParts.Get(dr); + // load child objects + dr.NextResult(); + _ContentRoUsages = ContentRoUsages.Get(dr); + // load child objects + dr.NextResult(); + _ContentTransitions = ContentTransitions.Get(dr); + // load child objects + dr.NextResult(); + _MyZContent = ZContent.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Content.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Content.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyFormat != null) _MyFormat.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); + param_ContentID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ContentID); + 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 + _ContentID = (int)cm.Parameters["@newContentID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_ContentItems != null) _ContentItems.Update(this); + if (_ContentDetails != null) _ContentDetails.Update(this); + if (_MyEntry != null) _MyEntry.Update(this); + if (_MyGrid != null) _MyGrid.Update(this); + if (_MyImage != null) _MyImage.Update(this); + if (_ContentParts != null) _ContentParts.Update(this); + if (_ContentRoUsages != null) _ContentRoUsages.Update(this); + if (_ContentTransitions != null) _ContentTransitions.Update(this); + if (_MyZContent != null) _MyZContent.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); + param_ContentID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ContentID); + 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 + contentID = (int)cm.Parameters["@newContentID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Add", ex); + throw new DbCslaException("Content.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Content.SQLUpdate", GetHashCode()); + try + { + if (_MyFormat != null) _MyFormat.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + //Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString()); + cm.CommandText = "updateContent"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_ContentItems != null) _ContentItems.Update(this); + if (_ContentDetails != null) _ContentDetails.Update(this); + if (_MyEntry != null) _MyEntry.Update(this); + if (_MyGrid != null) _MyGrid.Update(this); + if (_MyImage != null) _MyImage.Update(this); + if (_ContentParts != null) _ContentParts.Update(this); + if (_ContentRoUsages != null) _ContentRoUsages.Update(this); + if (_ContentTransitions != null) _ContentTransitions.Update(this); + if (_MyZContent != null) _MyZContent.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID); + else + _LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_ContentItems != null) _ContentItems.Update(this); + if (_ContentDetails != null) _ContentDetails.Update(this); + if (_MyEntry != null) _MyEntry.Update(this); + if (_MyGrid != null) _MyGrid.Update(this); + if (_MyImage != null) _MyImage.Update(this); + if (_ContentParts != null) _ContentParts.Update(this); + if (_ContentRoUsages != null) _ContentRoUsages.Update(this); + if (_ContentTransitions != null) _ContentTransitions.Update(this); + if (_MyZContent != null) _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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteContent"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Remove", ex); + throw new DbCslaException("Content.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsContent"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Execute", ex); + throw new DbCslaException("Content.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ContentExtension _ContentExtension = new ContentExtension(); + [Serializable()] + partial class ContentExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Content) + { + // Return the ToString value + return ((Content)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs index 45360163..183ae941 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAudit.cs @@ -20,1010 +20,991 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentAuditConverter))] - public partial class ContentAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshContentAudits = new List(); - private void AddToRefreshList(List refreshContentAudits) - { - if (IsDirty) - refreshContentAudits.Add(this); - } - private void ClearRefreshList() - { - _RefreshContentAudits = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshContentAudits); - } - private void ProcessRefreshList() - { - foreach (ContentAudit tmp in _RefreshContentAudits) - { - ContentAuditInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ContentAudit contentAudit) - { - if (!_CacheList.Contains(contentAudit)) _CacheList.Add(contentAudit); // In AddToCache - } - protected static void RemoveFromCache(ContentAudit contentAudit) - { - while (_CacheList.Contains(contentAudit)) _CacheList.Remove(contentAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ContentAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - ContentAudit tmp = _CacheList[0]; // Get the first ContentAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ContentAudit - } - } - protected static ContentAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private string _Number = string.Empty; - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Number", true); - if (value == null) value = string.Empty; - if (_Number != value) - { - _Number = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private int? _Type; - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Type", true); - if (_Type != value) - { - _Type = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FormatID", true); - if (_FormatID != value) - { - _FormatID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base ContentAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ContentAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentAudit - protected override object GetIdValue() - { - return MyContentAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 512)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _ContentAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ContentAuditExtension.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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(Number, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowRead(Type, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(Number, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowWrite(Type, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _ContentAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ContentAuditExtension.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; } } - private static int _ContentAuditUnique = 0; - protected static int ContentAuditUnique - { get { return ++_ContentAuditUnique; } } - private int _MyContentAuditUnique = ContentAuditUnique; - public int MyContentAuditUnique // Absolutely Unique ID - Editable - { get { return _MyContentAuditUnique; } } - protected ContentAudit() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ContentAudit() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listContentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listContentAudit.Contains(this)) listContentAudit.Remove(this); // Remove the item from the list - if (listContentAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static ContentAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAudit.New", ex); - } - } - public static ContentAudit New(int contentID, DateTime dts, string userID, int deleteStatus) - { - ContentAudit tmp = ContentAudit.New(); - tmp.ContentID = contentID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ContentAudit New(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) - { - ContentAudit tmp = ContentAudit.New(); - tmp.ContentID = contentID; - tmp.Number = number; - tmp.Text = text; - tmp.Type = type; - tmp.FormatID = formatID; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ContentAudit MakeContentAudit(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) - { - ContentAudit tmp = ContentAudit.New(contentID, number, text, type, formatID, config, dts, userID, deleteStatus); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ContentAudit Get(long auditID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); - try - { - ContentAudit tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ContentAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAudit.Get", ex); - } - } - public static ContentAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new ContentAudit(dr); - return null; - } - internal ContentAudit(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(long auditID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); - try - { - DataPortal.Delete(new PKCriteria(auditID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAudit.Delete", ex); - } - } - public override ContentAudit Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ContentAudit"); - try - { - BuildRefreshList(); - ContentAudit contentAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(contentAudit);//Refresh the item in AllList - ProcessRefreshList(); - return contentAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// ContentAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentAuditConverter))] + public partial class ContentAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshContentAudits = new List(); + private void AddToRefreshList(List refreshContentAudits) + { + if (IsDirty) + refreshContentAudits.Add(this); + } + private void ClearRefreshList() + { + _RefreshContentAudits = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshContentAudits); + } + private void ProcessRefreshList() + { + foreach (ContentAudit tmp in _RefreshContentAudits) + { + ContentAuditInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ContentAudit contentAudit) + { + if (!_CacheList.Contains(contentAudit)) _CacheList.Add(contentAudit); // In AddToCache + } + protected static void RemoveFromCache(ContentAudit contentAudit) + { + while (_CacheList.Contains(contentAudit)) _CacheList.Remove(contentAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ContentAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + ContentAudit tmp = _CacheList[0]; // Get the first ContentAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ContentAudit + } + } + protected static ContentAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Number != value) + { + _Number = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private int? _Type; + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Type != value) + { + _Type = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_FormatID != value) + { + _FormatID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ContentAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ContentAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentAudit + protected override object GetIdValue() + { + return MyContentAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 512)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _ContentAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ContentAuditExtension.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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(Number, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowRead(Type, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(Number, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowWrite(Type, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _ContentAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ContentAuditExtension.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; } } + private static int _ContentAuditUnique = 0; + protected static int ContentAuditUnique + { get { return ++_ContentAuditUnique; } } + private int _MyContentAuditUnique = ContentAuditUnique; + public int MyContentAuditUnique // Absolutely Unique ID - Editable + { get { return _MyContentAuditUnique; } } + protected ContentAudit() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ContentAudit() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listContentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listContentAudit.Contains(this)) listContentAudit.Remove(this); // Remove the item from the list + if (listContentAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static ContentAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.New", ex); + } + } + public static ContentAudit New(int contentID, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(); + tmp.ContentID = contentID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ContentAudit New(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(); + tmp.ContentID = contentID; + tmp.Number = number; + tmp.Text = text; + tmp.Type = type; + tmp.FormatID = formatID; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ContentAudit MakeContentAudit(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(contentID, number, text, type, formatID, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ContentAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); + try + { + ContentAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.Get", ex); + } + } + public static ContentAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new ContentAudit(dr); + return null; + } + internal ContentAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.Delete", ex); + } + } + public override ContentAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ContentAudit"); + try + { + BuildRefreshList(); + ContentAudit contentAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(contentAudit);//Refresh the item in AllList + ProcessRefreshList(); + return contentAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addContentAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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("@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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addContentAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - 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("@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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Add", ex); - throw new DbCslaException("ContentAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateContentAudit"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AuditID", _AuditID); - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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("@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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); - else - ContentAudit.Update(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateContentAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AuditID", auditID); - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - 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("@DeleteStatus", deleteStatus); - // Output Calculated Columns - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteContentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteContentAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Remove", ex); - throw new DbCslaException("ContentAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - ContentAuditExtension _ContentAuditExtension = new ContentAuditExtension(); - [Serializable()] - partial class ContentAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentAudit) - { - // Return the ToString value - return ((ContentAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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("@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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + 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("@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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Add", ex); + throw new DbCslaException("ContentAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateContentAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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("@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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); + else + ContentAudit.Update(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteContentAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Remove", ex); + throw new DbCslaException("ContentAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + ContentAuditExtension _ContentAuditExtension = new ContentAuditExtension(); + [Serializable()] + partial class ContentAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentAudit) + { + // Return the ToString value + return ((ContentAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfo.cs index ec7e9580..6d63a93e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentAuditInfo.cs @@ -19,397 +19,387 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ContentAuditInfoEvent(object sender); - /// - /// ContentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentAuditInfoConverter))] - public partial class ContentAuditInfo : ReadOnlyBase, IDisposable - { - public event ContentAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ContentAuditInfo contentAuditInfo) - { - if (!_CacheList.Contains(contentAuditInfo)) _CacheList.Add(contentAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(ContentAuditInfo contentAuditInfo) - { - while (_CacheList.Contains(contentAuditInfo)) _CacheList.Remove(contentAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ContentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ContentAuditInfo tmp = _CacheList[0]; // Get the first ContentAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ContentAuditInfo - } - } - internal static void AddList(ContentAuditInfoList lst) - { - foreach (ContentAuditInfo item in lst) AddToCache(item); - } - protected static ContentAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ContentAudit _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private string _Number = string.Empty; - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - } - private int? _Type; - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base ContentAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ContentAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentAuditInfo - protected override object GetIdValue() - { - return MyContentAuditInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ContentAuditInfoUnique = 0; - private static int ContentAuditInfoUnique - { get { return ++_ContentAuditInfoUnique; } } - private int _MyContentAuditInfoUnique = ContentAuditInfoUnique; - public int MyContentAuditInfoUnique // Absolutely Unique ID - Info - { get { return _MyContentAuditInfoUnique; } } - protected ContentAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ContentAuditInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listContentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listContentAuditInfo.Contains(this)) listContentAuditInfo.Remove(this); // Remove the item from the list - if (listContentAuditInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - public virtual ContentAudit Get() - { - return _Editable = ContentAudit.Get(_AuditID); - } - public static void Refresh(ContentAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ContentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentAudit tmp) - { - _ContentID = tmp.ContentID; - _Number = tmp.Number; - _Text = tmp.Text; - _Type = tmp.Type; - _FormatID = tmp.FormatID; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _ContentAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ContentAuditInfo Get(long auditID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); - try - { - ContentAuditInfo tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ContentAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ContentAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.Constructor", ex); - throw new DbCslaException("ContentAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ContentAuditInfoExtension _ContentAuditInfoExtension = new ContentAuditInfoExtension(); - [Serializable()] - partial class ContentAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ContentAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ContentAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentAuditInfo) - { - // Return the ToString value - return ((ContentAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ContentAuditInfoEvent(object sender); + /// + /// ContentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentAuditInfoConverter))] + public partial class ContentAuditInfo : ReadOnlyBase, IDisposable + { + public event ContentAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ContentAuditInfo contentAuditInfo) + { + if (!_CacheList.Contains(contentAuditInfo)) _CacheList.Add(contentAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(ContentAuditInfo contentAuditInfo) + { + while (_CacheList.Contains(contentAuditInfo)) _CacheList.Remove(contentAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ContentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ContentAuditInfo tmp = _CacheList[0]; // Get the first ContentAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ContentAuditInfo + } + } + internal static void AddList(ContentAuditInfoList lst) + { + foreach (ContentAuditInfo item in lst) AddToCache(item); + } + protected static ContentAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ContentAudit _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + } + private int? _Type; + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base ContentAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ContentAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentAuditInfo + protected override object GetIdValue() + { + return MyContentAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ContentAuditInfoUnique = 0; + private static int ContentAuditInfoUnique + { get { return ++_ContentAuditInfoUnique; } } + private int _MyContentAuditInfoUnique = ContentAuditInfoUnique; + public int MyContentAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyContentAuditInfoUnique; } } + protected ContentAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ContentAuditInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listContentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listContentAuditInfo.Contains(this)) listContentAuditInfo.Remove(this); // Remove the item from the list + if (listContentAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual ContentAudit Get() + { + return _Editable = ContentAudit.Get(_AuditID); + } + public static void Refresh(ContentAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentAudit tmp) + { + _ContentID = tmp.ContentID; + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ContentAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ContentAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); + try + { + ContentAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ContentAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.Constructor", ex); + throw new DbCslaException("ContentAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ContentAuditInfoExtension _ContentAuditInfoExtension = new ContentAuditInfoExtension(); + [Serializable()] + partial class ContentAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ContentAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ContentAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentAuditInfo) + { + // Return the ToString value + return ((ContentAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetail.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetail.cs index 69dc8a94..87b465ec 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetail.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentDetail.cs @@ -20,456 +20,444 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentDetail Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentDetailConverter))] - public partial class ContentDetail : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _DetailID; - [System.ComponentModel.DataObjectField(true, true)] - public int DetailID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DetailID", true); - if (_MyDetail != null) _DetailID = _MyDetail.DetailID; - return _DetailID; - } - } - private Detail _MyDetail; - [System.ComponentModel.DataObjectField(true, true)] - public Detail MyDetail - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDetail", true); - if (_MyDetail == null && _DetailID != 0) _MyDetail = Detail.Get(_DetailID); - return _MyDetail; - } - } - private int _ItemType; - public int ItemType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemType", true); - return _ItemType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemType", true); - if (_ItemType != value) - { - _ItemType = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check ContentDetail.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentDetail - protected override object GetIdValue() - { - return MyContentDetailUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ContentDetail.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentDetail - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Text"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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(DetailID, ""); - //AuthorizationRules.AllowRead(ItemType, ""); - //AuthorizationRules.AllowWrite(ItemType, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ContentDetailUnique = 0; - private static int ContentDetailUnique - { get { return ++_ContentDetailUnique; } } - private int _MyContentDetailUnique = ContentDetailUnique; - public int MyContentDetailUnique // Absolutely Unique ID - Editable FK - { get { return _MyContentDetailUnique; } } - internal static ContentDetail New(int itemType, string text) - { - return new ContentDetail(itemType, text); - } - internal static ContentDetail Get(SafeDataReader dr) - { - return new ContentDetail(dr); - } - public ContentDetail() - { - MarkAsChild(); - _DetailID = Detail.NextDetailID; - _DTS = _ContentDetailExtension.DefaultDTS; - _UserID = _ContentDetailExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentDetail(int itemType, string text) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _DetailID = Detail.NextDetailID; - _DTS = _ContentDetailExtension.DefaultDTS; - _UserID = _ContentDetailExtension.DefaultUserID; - _ItemType = itemType; - _Text = text; - ValidationRules.CheckRules(); - } - internal ContentDetail(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ContentDetail() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentDetail.FetchDR", GetHashCode()); - try - { - _DetailID = dr.GetInt32("DetailID"); - _ItemType = dr.GetInt32("ItemType"); - _Text = dr.GetString("Text"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentDetail.FetchDR", ex); - throw new DbCslaException("ContentDetail.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Detail.Add(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Detail.Update(cn, ref _DetailID, myContent.ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Detail.Remove(cn, _DetailID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentDetailExtension _ContentDetailExtension = new ContentDetailExtension(); - [Serializable()] - partial class ContentDetailExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentDetailConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentDetail) - { - // Return the ToString value - return ((ContentDetail)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentDetail Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentDetailConverter))] + public partial class ContentDetail : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _DetailID; + [System.ComponentModel.DataObjectField(true, true)] + public int DetailID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDetail != null) _DetailID = _MyDetail.DetailID; + return _DetailID; + } + } + private Detail _MyDetail; + [System.ComponentModel.DataObjectField(true, true)] + public Detail MyDetail + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDetail == null && _DetailID != 0) _MyDetail = Detail.Get(_DetailID); + return _MyDetail; + } + } + private int _ItemType; + public int ItemType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemType != value) + { + _ItemType = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check ContentDetail.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentDetail + protected override object GetIdValue() + { + return MyContentDetailUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ContentDetail.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentDetail + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Text"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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(DetailID, ""); + //AuthorizationRules.AllowRead(ItemType, ""); + //AuthorizationRules.AllowWrite(ItemType, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ContentDetailUnique = 0; + private static int ContentDetailUnique + { get { return ++_ContentDetailUnique; } } + private int _MyContentDetailUnique = ContentDetailUnique; + public int MyContentDetailUnique // Absolutely Unique ID - Editable FK + { get { return _MyContentDetailUnique; } } + internal static ContentDetail New(int itemType, string text) + { + return new ContentDetail(itemType, text); + } + internal static ContentDetail Get(SafeDataReader dr) + { + return new ContentDetail(dr); + } + public ContentDetail() + { + MarkAsChild(); + _DetailID = Detail.NextDetailID; + _DTS = _ContentDetailExtension.DefaultDTS; + _UserID = _ContentDetailExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentDetail(int itemType, string text) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _DetailID = Detail.NextDetailID; + _DTS = _ContentDetailExtension.DefaultDTS; + _UserID = _ContentDetailExtension.DefaultUserID; + _ItemType = itemType; + _Text = text; + ValidationRules.CheckRules(); + } + internal ContentDetail(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ContentDetail() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentDetail.FetchDR", GetHashCode()); + try + { + _DetailID = dr.GetInt32("DetailID"); + _ItemType = dr.GetInt32("ItemType"); + _Text = dr.GetString("Text"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentDetail.FetchDR", ex); + throw new DbCslaException("ContentDetail.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Detail.Add(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Detail.Update(cn, ref _DetailID, myContent.ContentID, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Detail.Remove(cn, _DetailID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentDetailExtension _ContentDetailExtension = new ContentDetailExtension(); + [Serializable()] + partial class ContentDetailExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentDetailConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentDetail) + { + // Return the ToString value + return ((ContentDetail)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs index de92f460..58d49b91 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentInfo.cs @@ -19,859 +19,844 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ContentInfoEvent(object sender); - /// - /// ContentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentInfoConverter))] - public partial class ContentInfo : ReadOnlyBase, IDisposable - { - public static event ContentInfoEvent InfoChanged; - private void OnInfoChanged(ContentInfo contentInfo) - { - if (InfoChanged != null) - InfoChanged(this); - } - public event ContentInfoEvent Changed; - private void OnChange(ContentInfo contentInfo) - { - if (Changed != null) - Changed(this); - OnInfoChanged(this); - } - private void OnChange() - { - string key = ContentID.ToString(); - if( _CacheByPrimaryKey.ContainsKey(key)) - foreach (ContentInfo cont in _CacheByPrimaryKey[key]) - cont.OnChange(cont); - else - OnChange(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ContentInfo contentInfo) - { - if (!_CacheList.Contains(contentInfo)) _CacheList.Add(contentInfo); // In AddToCache - } - protected static void RemoveFromCache(ContentInfo contentInfo) - { - while (_CacheList.Contains(contentInfo)) _CacheList.Remove(contentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ContentInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ContentInfo tmp = _CacheList[0]; // Get the first ContentInfo - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ContentInfo - } - } - internal static void AddList(ContentInfoList lst) - { - foreach (ContentInfo item in lst) AddToCache(item); - } - protected static ContentInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Content _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public byte[] LastChanged - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LastChanged", true); - return _LastChanged; - } - set { _LastChanged = value; } - } + public delegate void ContentInfoEvent(object sender); + /// + /// ContentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentInfoConverter))] + public partial class ContentInfo : ReadOnlyBase, IDisposable + { + public static event ContentInfoEvent InfoChanged; + private void OnInfoChanged(ContentInfo contentInfo) + { + if (InfoChanged != null) + InfoChanged(this); + } + public event ContentInfoEvent Changed; + private void OnChange(ContentInfo contentInfo) + { + if (Changed != null) + Changed(this); + OnInfoChanged(this); + } + private void OnChange() + { + string key = ContentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentInfo cont in _CacheByPrimaryKey[key]) + cont.OnChange(cont); + else + OnChange(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ContentInfo contentInfo) + { + if (!_CacheList.Contains(contentInfo)) _CacheList.Add(contentInfo); // In AddToCache + } + protected static void RemoveFromCache(ContentInfo contentInfo) + { + while (_CacheList.Contains(contentInfo)) _CacheList.Remove(contentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ContentInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ContentInfo tmp = _CacheList[0]; // Get the first ContentInfo + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ContentInfo + } + } + internal static void AddList(ContentInfoList lst) + { + foreach (ContentInfo item in lst) AddToCache(item); + } + protected static ContentInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + public static void ClearContentInfoCache() + { + _CacheByPrimaryKey.Clear(); + while (_CacheList.Count > 0) + { + while (_CacheList[0]?._ContentItems?.Count > 0) + { + _CacheList[0]?._ContentItems[0]?.Dispose(); + } + _CacheList[0]?._ContentItems?.Dispose(); + _CacheList[0].Dispose(); + } + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Content _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public byte[] LastChanged + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LastChanged; + } + set { _LastChanged = value; } + } - private string _Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - if (_Disposed) throw new Exception("Cannot access disposed object"); - CanReadProperty("Text", true); - return _Text; - } - } - private int? _Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private FormatInfo _MyFormat; - public FormatInfo MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); - return _MyFormat; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ContentDetailCount = 0; - /// - /// Count of ContentDetails for this Content - /// - public int ContentDetailCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetailCount", true); - if (_ContentDetailCount < 0) - _ContentDetailCount = ContentDetails.Count; - return _ContentDetailCount; - } - } - private DetailInfoList _ContentDetails = null; - [TypeConverter(typeof(DetailInfoListConverter))] - public DetailInfoList ContentDetails - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetails", true); - if (_ContentDetailCount < 0 || (_ContentDetailCount > 0 && _ContentDetails == null)) - _ContentDetails = DetailInfoList.GetByContentID(_ContentID); - if (_ContentDetailCount < 0) - _ContentDetailCount = _ContentDetails.Count; - return _ContentDetails; - } - } - public void RefreshContentDetails() - { - _ContentDetailCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentDetailCount = -1; // This will cause the data to be requeried - } - private int _ContentEntryCount = 0; - /// - /// Count of ContentEntries for this Content - /// - public int ContentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentEntryCount", true); - if (_ContentEntryCount < 0) - { - _MyEntry = EntryInfo.Get(_ContentID); - _ContentEntryCount = MyEntry == null ? 0 : 1; - } - return _ContentEntryCount; - } - } - private EntryInfo _MyEntry = null; - [TypeConverter(typeof(EntryInfoConverter))] - public EntryInfo MyEntry - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyEntry", true); - if (_ContentEntryCount != 0 && _MyEntry == null) - { - _MyEntry = EntryInfo.Get(_ContentID); - _ContentEntryCount = _MyEntry == null ? 0 : 1; - } - return _MyEntry; - } - } - private int _ContentGridCount = 0; - /// - /// Count of ContentGrids for this Content - /// - public int ContentGridCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentGridCount", true); - return _ContentGridCount; - } - } - private GridInfo _MyGrid = null; - [TypeConverter(typeof(GridInfoConverter))] - public GridInfo MyGrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGrid", true); - if (_ContentGridCount == -1 && _MyGrid != null) - { - _MyGrid = null; - } - if (_ContentGridCount != 0 && _MyGrid == null) - { - _MyGrid = GridInfo.Get(_ContentID); - _ContentGridCount = _MyGrid == null ? 0 : 1; - } - return _MyGrid; - } - } - private int _ContentImageCount = 0; - /// - /// Count of ContentImages for this Content - /// - public int ContentImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentImageCount", true); - return _ContentImageCount; - } - } - private ImageInfo _MyImage = null; - [TypeConverter(typeof(ImageInfoConverter))] - public ImageInfo MyImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyImage", true); - if (_ContentImageCount != 0 && _MyImage == null) - { - _MyImage = ImageInfo.Get(_ContentID); - _ContentImageCount = _MyImage == null ? 0 : 1; - } - return _MyImage; - } - } - private int _ContentItemCount = 0; - /// - /// Count of ContentItems for this Content - /// - public int ContentItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItemCount", true); - if (_ContentItemCount < 0) - _ContentItemCount = ContentItems.Count; - return _ContentItemCount; - } - } - private ItemInfoList _ContentItems = null; - [TypeConverter(typeof(ItemInfoListConverter))] - public ItemInfoList ContentItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItems", true); - if (_ContentItemCount < 0 || (_ContentItemCount > 0 && _ContentItems == null)) - _ContentItems = ItemInfoList.GetByContentID(_ContentID); - if (_ContentItemCount < 0) - _ContentItemCount = _ContentItems.Count; - return _ContentItems; - } - } - public void RefreshContentItems() - { - _ContentItemCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentItemCount = -1; // This will cause the data to be requeried - } - private int _ContentPartCount = 0; - /// - /// Count of ContentParts for this Content - /// - public int ContentPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentPartCount", true); - if (_ContentPartCount < 0) - _ContentPartCount = ContentParts.Count; - return _ContentPartCount; - } - } - private PartInfoList _ContentParts = null; - [TypeConverter(typeof(PartInfoListConverter))] - public PartInfoList ContentParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentParts", true); - if (_ContentPartCount < 0 || (_ContentPartCount > 0 && _ContentParts == null)) - _ContentParts = PartInfoList.GetByContentID(_ContentID); - if (_ContentPartCount < 0) - _ContentPartCount = _ContentParts.Count; - return _ContentParts; - } - } - public void RefreshContentParts() - { - _ContentPartCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentPartCount = -1; // This will cause the data to be requeried - } - private int _ContentRoUsageCount = 0; - /// - /// Count of ContentRoUsages for this Content - /// - public int ContentRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsageCount", true); - if (_ContentRoUsageCount < 0) - _ContentRoUsageCount = ContentRoUsages.Count; - return _ContentRoUsageCount; - } - } - private RoUsageInfoList _ContentRoUsages = null; - [TypeConverter(typeof(RoUsageInfoListConverter))] - public RoUsageInfoList ContentRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsages", true); - if (_ContentRoUsageCount < 0 || (_ContentRoUsageCount > 0 && _ContentRoUsages == null)) - _ContentRoUsages = RoUsageInfoList.GetByContentID(_ContentID); - if (_ContentRoUsageCount < 0) - _ContentRoUsageCount = _ContentRoUsages.Count; - return _ContentRoUsages; - } - } - public void RefreshContentRoUsages() - { - _ContentRoUsageCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentRoUsageCount = -1; // This will cause the data to be requeried - } - private int _ContentTransitionCount = 0; - /// - /// Count of ContentTransitions for this Content - /// - public int ContentTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitionCount", true); - if (_ContentTransitionCount < 0) - _ContentTransitionCount = ContentTransitions.Count; - return _ContentTransitionCount; - } - } - private TransitionInfoList _ContentTransitions = null; - [TypeConverter(typeof(TransitionInfoListConverter))] - public TransitionInfoList ContentTransitions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitions", true); - if (_ContentTransitionCount < 0 || (_ContentTransitionCount > 0 && _ContentTransitions == null)) - _ContentTransitions = TransitionInfoList.GetByFromID(_ContentID); - if (_ContentTransitionCount < 0) - _ContentTransitionCount = _ContentTransitions.Count; - return _ContentTransitions; - } - } - public void RefreshContentTransitions() - { - _ContentTransitionCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentTransitionCount = -1; // This will cause the data to be requeried - } - private int _ContentZContentCount = 0; - /// - /// Count of ContentZContents for this Content - /// - public int ContentZContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentZContentCount", true); - return _ContentZContentCount; - } - } - private ZContentInfo _MyZContent = null; - [TypeConverter(typeof(ZContentInfoConverter))] - public ZContentInfo MyZContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZContent", true); - if (_ContentZContentCount != 0 && _MyZContent == null) - { - _MyZContent = ZContentInfo.Get(_ContentID); - _ContentZContentCount = _MyZContent == null ? 0 : 1; - } - return _MyZContent; - } - } - // CSLATODO: Replace base ContentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ContentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentInfo - protected override object GetIdValue() - { - return MyContentInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ContentInfoUnique = 0; - private static int ContentInfoUnique - { - get - { - int ui = ++_ContentInfoUnique; - // to debug to see where this gets allocated use the following code: - //if (ui == 2|| ui == 6) Console.WriteLine("Here"); - return ui; - } - } - private int _MyContentInfoUnique = ContentInfoUnique; - public int MyContentInfoUnique // Absolutely Unique ID - Info - { get { return _MyContentInfoUnique; } } - protected ContentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ContentInfo() - { - _CountFinalized++; - } - // Use PrintCache in the CacheUsage.cs/CSLACache.Usage call to see what is in the cache for Contents. - // for printing the contentinfo objects in the cache, add the line 'ContentInfo.PrintCache();' to that method. - // NOTE that similar code can be added for the various csla wrapper objects, such as grid & item. - public static void PrintCache() - { - foreach (string str in _CacheByPrimaryKey.Keys) - { - - List listContentInfo = _CacheByPrimaryKey[str]; // Get the list of items - if (listContentInfo.Count >1) Console.WriteLine("**Cache - {0}, count = {1}", str, listContentInfo.Count); - if (listContentInfo.Count > 1) - { - Console.WriteLine("**Cache - {0}, count = {1}", str, listContentInfo.Count); - foreach (ContentInfo ci in listContentInfo) Console.WriteLine(" num = {0}, uniqid = {1}, txt = {2}", ci.Number.Replace(@"\u8209?", "-"), ci.MyContentInfoUnique, ci.Text); - } - } - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listContentInfo.Contains(this)) listContentInfo.Remove(this); // Remove the item from the list - if (listContentInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - if (_Editable != null) - _Editable = null; - if (_ContentItems != null) - _ContentItems = null; - _Text = null; - //if (_ContentParts != null) - // _ContentParts = null; - //if (_ContentRoUsages != null) - // _ContentRoUsages = null; - //if (_ContentTransitions != null) - // _ContentTransitions = null; - //if (_MyEntry != null) - // _MyEntry = null; - //if (_MyGrid != null) - // _MyGrid = null; - //if (_MyImage != null) - // _MyImage = null; - //if (_MyZContent != null) - // _MyZContent = null; - } - public virtual Content Get() - { - return _Editable = Content.Get(_ContentID); - } - public static void Refresh(Content tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (tmp.MyGrid != null) // B2017-041 refresh the table (grid) on the screen to show the transition changes - GridInfo.Refresh(tmp.MyGrid); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) - { - tmpInfo.RefreshFields(tmp); - // TODO: This needs to be handled in Generated Code. - if (tmp.LocalEntry != null && tmpInfo.MyEntry != null && tmp.MyEntry.MyDocument.DocID != tmpInfo.MyEntry.MyDocument.DocID) - EntryInfo.Refresh(tmp.MyEntry); - } - // Update Enhanced Document Text - StepConfig sc = new StepConfig(tmp.Config); - foreach (EnhancedDocument ed in sc.MyEnhancedDocuments) - { - // Without this 'if' infinite loop. Only update text if in source and updating to point to enhanced. - if (ed.Type != 0) - { - ItemInfo ii = ItemInfo.Get(ed.ItemID); - if (ii == null) continue; //B2020-141 the itemID is not there because the linked Enhanced step was delete when EOP step was deleted - // C2019-045: For enhanced procedures, allow modification of number & text. A setting on the docversion (set from Properties dialog) defines whether text - // can be modified if it is an enhanced item. If it can be modified, don't do the automatic update if the 'source' text is changed. - bool doEnhancedMods = ii.EnhAllowMod(); - if (!doEnhancedMods) - { - DisplayText dt = new DisplayText(ii, ii.MyContent.Text, false); - string str = ItemInfo.Get(tmp.ContentItems[0].ItemID).DisplayTextKeepSpecialChars; - dt.Save(str); - if (tmp.Type < 20000 && ii.MyContent.Number != tmp.Number) // update number for sections & procedures, B2016-228 - { - using (Content enhCont = Content.Get(ii.MyContent.ContentID)) - { - enhCont.Number = tmp.Number; - enhCont.Save(); - } - } - } - } - } - } - protected virtual void RefreshFields(Content tmp) - { - _Number = tmp.Number; - _Text = tmp.Text; - _Type = tmp.Type; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) MyFormat.RefreshFormatContents(); // 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.RefreshFormatContents(); // Update List for new value - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _LastChanged = tmp.LastChanged; - _ContentInfoExtension.Refresh(this); - _ContentEntryCount = -1;// Reset Count - _ContentGridCount = -1;// Reset Count - _ContentImageCount = -1;// Reset Count - _ContentZContentCount = -1;// Reset Count - OnChange(this);// raise an event only for this instance - } - public static void Refresh(FormatContent tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FormatContent tmp) - { - _Number = tmp.Number; - _Text = tmp.Text; - _Type = tmp.Type; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ContentInfoExtension.Refresh(this); - _ContentEntryCount = -1;// Reset Count - _ContentGridCount = -1;// Reset Count - _ContentImageCount = -1;// Reset Count - _ContentZContentCount = -1;// Reset Count - OnChange(this);// raise an event only for this instance - } - public static ContentInfo Get(int contentID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Content"); - try - { - ContentInfo tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ContentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ContentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.Constructor", ex); - throw new DbCslaException("ContentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ContentDetailCount = dr.GetInt32("DetailCount"); - _ContentEntryCount = dr.GetInt32("EntryCount"); - _ContentGridCount = dr.GetInt32("GridCount"); - _ContentImageCount = dr.GetInt32("ImageCount"); - _ContentItemCount = dr.GetInt32("ItemCount"); - _ContentPartCount = dr.GetInt32("PartCount"); - _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); - _ContentTransitionCount = dr.GetInt32("TransitionCount"); - _ContentZContentCount = dr.GetInt32("ZContentCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ContentInfoExtension _ContentInfoExtension = new ContentInfoExtension(); - [Serializable()] - partial class ContentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ContentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ContentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentInfo) - { - // Return the ToString value - return ((ContentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + private string _Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_Disposed) throw new Exception("Cannot access disposed object"); + return _Text; + } + } + private int? _Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private FormatInfo _MyFormat; + public FormatInfo MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); + return _MyFormat; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ContentDetailCount = 0; + /// + /// Count of ContentDetails for this Content + /// + public int ContentDetailCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentDetailCount < 0) + _ContentDetailCount = ContentDetails.Count; + return _ContentDetailCount; + } + } + private DetailInfoList _ContentDetails = null; + [TypeConverter(typeof(DetailInfoListConverter))] + public DetailInfoList ContentDetails + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentDetailCount < 0 || (_ContentDetailCount > 0 && _ContentDetails == null)) + _ContentDetails = DetailInfoList.GetByContentID(_ContentID); + if (_ContentDetailCount < 0) + _ContentDetailCount = _ContentDetails.Count; + return _ContentDetails; + } + } + public void RefreshContentDetails() + { + _ContentDetailCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentDetailCount = -1; // This will cause the data to be requeried + } + private int _ContentEntryCount = 0; + /// + /// Count of ContentEntries for this Content + /// + public int ContentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentEntryCount < 0) + { + _MyEntry = EntryInfo.Get(_ContentID); + _ContentEntryCount = MyEntry == null ? 0 : 1; + } + return _ContentEntryCount; + } + } + private EntryInfo _MyEntry = null; + [TypeConverter(typeof(EntryInfoConverter))] + public EntryInfo MyEntry + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentEntryCount != 0 && _MyEntry == null) + { + _MyEntry = EntryInfo.Get(_ContentID); + _ContentEntryCount = _MyEntry == null ? 0 : 1; + } + return _MyEntry; + } + } + private int _ContentGridCount = 0; + /// + /// Count of ContentGrids for this Content + /// + public int ContentGridCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentGridCount; + } + } + private GridInfo _MyGrid = null; + [TypeConverter(typeof(GridInfoConverter))] + public GridInfo MyGrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentGridCount == -1 && _MyGrid != null) + { + _MyGrid = null; + } + if (_ContentGridCount != 0 && _MyGrid == null) + { + _MyGrid = GridInfo.Get(_ContentID); + _ContentGridCount = _MyGrid == null ? 0 : 1; + } + return _MyGrid; + } + } + private int _ContentImageCount = 0; + /// + /// Count of ContentImages for this Content + /// + public int ContentImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentImageCount; + } + } + private ImageInfo _MyImage = null; + [TypeConverter(typeof(ImageInfoConverter))] + public ImageInfo MyImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentImageCount != 0 && _MyImage == null) + { + _MyImage = ImageInfo.Get(_ContentID); + _ContentImageCount = _MyImage == null ? 0 : 1; + } + return _MyImage; + } + } + private int _ContentItemCount = 0; + /// + /// Count of ContentItems for this Content + /// + public int ContentItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentItemCount < 0) + _ContentItemCount = ContentItems.Count; + return _ContentItemCount; + } + } + private ItemInfoList _ContentItems = null; + [TypeConverter(typeof(ItemInfoListConverter))] + public ItemInfoList ContentItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentItemCount < 0 || (_ContentItemCount > 0 && _ContentItems == null)) + _ContentItems = ItemInfoList.GetByContentID(_ContentID); + if (_ContentItemCount < 0) + _ContentItemCount = _ContentItems.Count; + return _ContentItems; + } + } + public void RefreshContentItems() + { + _ContentItemCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentItemCount = -1; // This will cause the data to be requeried + } + private int _ContentPartCount = 0; + /// + /// Count of ContentParts for this Content + /// + public int ContentPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentPartCount < 0) + _ContentPartCount = ContentParts.Count; + return _ContentPartCount; + } + } + private PartInfoList _ContentParts = null; + [TypeConverter(typeof(PartInfoListConverter))] + public PartInfoList ContentParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentPartCount < 0 || (_ContentPartCount > 0 && _ContentParts == null)) + _ContentParts = PartInfoList.GetByContentID(_ContentID); + if (_ContentPartCount < 0) + _ContentPartCount = _ContentParts.Count; + return _ContentParts; + } + } + public void RefreshContentParts() + { + _ContentPartCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentPartCount = -1; // This will cause the data to be requeried + } + private int _ContentRoUsageCount = 0; + /// + /// Count of ContentRoUsages for this Content + /// + public int ContentRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentRoUsageCount < 0) + _ContentRoUsageCount = ContentRoUsages.Count; + return _ContentRoUsageCount; + } + } + private RoUsageInfoList _ContentRoUsages = null; + [TypeConverter(typeof(RoUsageInfoListConverter))] + public RoUsageInfoList ContentRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentRoUsageCount < 0 || (_ContentRoUsageCount > 0 && _ContentRoUsages == null)) + _ContentRoUsages = RoUsageInfoList.GetByContentID(_ContentID); + if (_ContentRoUsageCount < 0) + _ContentRoUsageCount = _ContentRoUsages.Count; + return _ContentRoUsages; + } + } + public void RefreshContentRoUsages() + { + _ContentRoUsageCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentRoUsageCount = -1; // This will cause the data to be requeried + } + private int _ContentTransitionCount = 0; + /// + /// Count of ContentTransitions for this Content + /// + public int ContentTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentTransitionCount < 0) + _ContentTransitionCount = ContentTransitions.Count; + return _ContentTransitionCount; + } + } + private TransitionInfoList _ContentTransitions = null; + [TypeConverter(typeof(TransitionInfoListConverter))] + public TransitionInfoList ContentTransitions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentTransitionCount < 0 || (_ContentTransitionCount > 0 && _ContentTransitions == null)) + _ContentTransitions = TransitionInfoList.GetByFromID(_ContentID); + if (_ContentTransitionCount < 0) + _ContentTransitionCount = _ContentTransitions.Count; + return _ContentTransitions; + } + } + public void RefreshContentTransitions() + { + _ContentTransitionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentTransitionCount = -1; // This will cause the data to be requeried + } + private int _ContentZContentCount = 0; + /// + /// Count of ContentZContents for this Content + /// + public int ContentZContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentZContentCount; + } + } + private ZContentInfo _MyZContent = null; + [TypeConverter(typeof(ZContentInfoConverter))] + public ZContentInfo MyZContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentZContentCount != 0 && _MyZContent == null) + { + _MyZContent = ZContentInfo.Get(_ContentID); + _ContentZContentCount = _MyZContent == null ? 0 : 1; + } + return _MyZContent; + } + } + // CSLATODO: Replace base ContentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ContentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentInfo + protected override object GetIdValue() + { + return MyContentInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ContentInfoUnique = 0; + private static int ContentInfoUnique + { + get + { + int ui = ++_ContentInfoUnique; + // to debug to see where this gets allocated use the following code: + //if (ui == 2|| ui == 6) Console.WriteLine("Here"); + return ui; + } + } + private int _MyContentInfoUnique = ContentInfoUnique; + public int MyContentInfoUnique // Absolutely Unique ID - Info + { get { return _MyContentInfoUnique; } } + protected ContentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ContentInfo() + { + _CountFinalized++; + } + // Use PrintCache in the CacheUsage.cs/CSLACache.Usage call to see what is in the cache for Contents. + // for printing the contentinfo objects in the cache, add the line 'ContentInfo.PrintCache();' to that method. + // NOTE that similar code can be added for the various csla wrapper objects, such as grid & item. + public static void PrintCache() + { + foreach (string str in _CacheByPrimaryKey.Keys) + { + + List listContentInfo = _CacheByPrimaryKey[str]; // Get the list of items + if (listContentInfo.Count > 1) Console.WriteLine("**Cache - {0}, count = {1}", str, listContentInfo.Count); + if (listContentInfo.Count > 1) + { + Console.WriteLine("**Cache - {0}, count = {1}", str, listContentInfo.Count); + foreach (ContentInfo ci in listContentInfo) Console.WriteLine(" num = {0}, uniqid = {1}, txt = {2}", ci.Number.Replace(@"\u8209?", "-"), ci.MyContentInfoUnique, ci.Text); + } + } + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listContentInfo.Contains(this)) listContentInfo.Remove(this); // Remove the item from the list + if (listContentInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + if (_Editable != null) + _Editable = null; + if (_ContentItems != null) + _ContentItems = null; + _Text = null; + //if (_ContentParts != null) + // _ContentParts = null; + //if (_ContentRoUsages != null) + // _ContentRoUsages = null; + //if (_ContentTransitions != null) + // _ContentTransitions = null; + //if (_MyEntry != null) + // _MyEntry = null; + //if (_MyGrid != null) + // _MyGrid = null; + //if (_MyImage != null) + // _MyImage = null; + //if (_MyZContent != null) + // _MyZContent = null; + } + public virtual Content Get() + { + return _Editable = Content.Get(_ContentID); + } + public static void Refresh(Content tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (tmp.MyGrid != null) // B2017-041 refresh the table (grid) on the screen to show the transition changes + GridInfo.Refresh(tmp.MyGrid); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) + { + tmpInfo.RefreshFields(tmp); + // TODO: This needs to be handled in Generated Code. + if (tmp.LocalEntry != null && tmpInfo.MyEntry != null && tmp.MyEntry.MyDocument.DocID != tmpInfo.MyEntry.MyDocument.DocID) + EntryInfo.Refresh(tmp.MyEntry); + } + // Update Enhanced Document Text + StepConfig sc = new StepConfig(tmp.Config); + foreach (EnhancedDocument ed in sc.MyEnhancedDocuments) + { + // Without this 'if' infinite loop. Only update text if in source and updating to point to enhanced. + if (ed.Type != 0) + { + ItemInfo ii = ItemInfo.Get(ed.ItemID); + if (ii == null) continue; //B2020-141 the itemID is not there because the linked Enhanced step was delete when EOP step was deleted + // C2019-045: For enhanced procedures, allow modification of number & text. A setting on the docversion (set from Properties dialog) defines whether text + // can be modified if it is an enhanced item. If it can be modified, don't do the automatic update if the 'source' text is changed. + bool doEnhancedMods = ii.EnhAllowMod(); + if (!doEnhancedMods) + { + DisplayText dt = new DisplayText(ii, ii.MyContent.Text, false); + string str = ItemInfo.Get(tmp.ContentItems[0].ItemID).DisplayTextKeepSpecialChars; + dt.Save(str); + if (tmp.Type < 20000 && ii.MyContent.Number != tmp.Number) // update number for sections & procedures, B2016-228 + { + using (Content enhCont = Content.Get(ii.MyContent.ContentID)) + { + enhCont.Number = tmp.Number; + enhCont.Save(); + } + } + } + } + } + } + protected virtual void RefreshFields(Content tmp) + { + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) MyFormat.RefreshFormatContents(); // 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.RefreshFormatContents(); // Update List for new value + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _LastChanged = tmp.LastChanged; + _ContentInfoExtension.Refresh(this); + _ContentEntryCount = -1;// Reset Count + _ContentGridCount = -1;// Reset Count + _ContentImageCount = -1;// Reset Count + _ContentZContentCount = -1;// Reset Count + OnChange(this);// raise an event only for this instance + } + public static void Refresh(FormatContent tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FormatContent tmp) + { + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ContentInfoExtension.Refresh(this); + _ContentEntryCount = -1;// Reset Count + _ContentGridCount = -1;// Reset Count + _ContentImageCount = -1;// Reset Count + _ContentZContentCount = -1;// Reset Count + OnChange(this);// raise an event only for this instance + } + public static ContentInfo Get(int contentID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Content"); + try + { + ContentInfo tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ContentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.Constructor", ex); + throw new DbCslaException("ContentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ContentDetailCount = dr.GetInt32("DetailCount"); + _ContentEntryCount = dr.GetInt32("EntryCount"); + _ContentGridCount = dr.GetInt32("GridCount"); + _ContentImageCount = dr.GetInt32("ImageCount"); + _ContentItemCount = dr.GetInt32("ItemCount"); + _ContentPartCount = dr.GetInt32("PartCount"); + _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); + _ContentTransitionCount = dr.GetInt32("TransitionCount"); + _ContentZContentCount = dr.GetInt32("ZContentCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ContentInfoExtension _ContentInfoExtension = new ContentInfoExtension(); + [Serializable()] + partial class ContentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ContentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ContentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentInfo) + { + // Return the ToString value + return ((ContentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs index 100411a9..815a68f7 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentItem.cs @@ -20,403 +20,394 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentItem Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentItemConverter))] - public partial class ContentItem : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ItemID; - [System.ComponentModel.DataObjectField(true, true)] - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - [System.ComponentModel.DataObjectField(true, true)] - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; - return _PreviousID; - } - } - private Item _MyPrevious; - public Item MyPrevious - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPrevious", true); - if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); - return _MyPrevious; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyPrevious", true); - if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyPrevious = value; - _PreviousID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check ContentItem.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentItem - protected override object GetIdValue() - { - return MyContentItemUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ContentItem.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentItem - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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(ItemID, ""); - //AuthorizationRules.AllowRead(PreviousID, ""); - //AuthorizationRules.AllowWrite(PreviousID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ContentItemUnique = 0; - private static int ContentItemUnique - { get { return ++_ContentItemUnique; } } - private int _MyContentItemUnique = ContentItemUnique; - public int MyContentItemUnique // Absolutely Unique ID - Editable FK - { get { return _MyContentItemUnique; } } - internal static ContentItem New() - { - return new ContentItem(); - } - internal static ContentItem Get(SafeDataReader dr) - { - return new ContentItem(dr); - } - public ContentItem() - { - MarkAsChild(); - _ItemID = Item.NextItemID; - _DTS = _ContentItemExtension.DefaultDTS; - _UserID = _ContentItemExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - internal ContentItem(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ContentItem() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentItem.FetchDR", GetHashCode()); - try - { - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentItem.FetchDR", ex); - throw new DbCslaException("ContentItem.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Item.Add(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, myContent.ContentID, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Item.Remove(cn, _ItemID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentItemExtension _ContentItemExtension = new ContentItemExtension(); - [Serializable()] - partial class ContentItemExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentItemConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentItem) - { - // Return the ToString value - return ((ContentItem)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentItem Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentItemConverter))] + public partial class ContentItem : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ItemID; + [System.ComponentModel.DataObjectField(true, true)] + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + [System.ComponentModel.DataObjectField(true, true)] + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; + return _PreviousID; + } + } + private Item _MyPrevious; + public Item MyPrevious + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); + return _MyPrevious; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyPrevious = value; + _PreviousID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check ContentItem.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentItem + protected override object GetIdValue() + { + return MyContentItemUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ContentItem.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentItem + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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(ItemID, ""); + //AuthorizationRules.AllowRead(PreviousID, ""); + //AuthorizationRules.AllowWrite(PreviousID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ContentItemUnique = 0; + private static int ContentItemUnique + { get { return ++_ContentItemUnique; } } + private int _MyContentItemUnique = ContentItemUnique; + public int MyContentItemUnique // Absolutely Unique ID - Editable FK + { get { return _MyContentItemUnique; } } + internal static ContentItem New() + { + return new ContentItem(); + } + internal static ContentItem Get(SafeDataReader dr) + { + return new ContentItem(dr); + } + public ContentItem() + { + MarkAsChild(); + _ItemID = Item.NextItemID; + _DTS = _ContentItemExtension.DefaultDTS; + _UserID = _ContentItemExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + internal ContentItem(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ContentItem() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentItem.FetchDR", GetHashCode()); + try + { + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentItem.FetchDR", ex); + throw new DbCslaException("ContentItem.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Item.Add(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Item.Update(cn, ref _ItemID, _PreviousID, myContent.ContentID, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Item.Remove(cn, _ItemID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentItemExtension _ContentItemExtension = new ContentItemExtension(); + [Serializable()] + partial class ContentItemExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentItemConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentItem) + { + // Return the ToString value + return ((ContentItem)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentPart.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentPart.cs index 1d7bc02c..7a139983 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentPart.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentPart.cs @@ -20,470 +20,458 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentPart Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentPartConverter))] - public partial class ContentPart : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if (_MyItem != value) - { - _MyItem = value; - _ItemID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int? _Item_PreviousID; - public int? Item_PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_PreviousID", true); - return _Item_PreviousID; - } - } - private int _Item_ContentID; - public int Item_ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ContentID", true); - return _Item_ContentID; - } - } - private DateTime _Item_DTS = new DateTime(); - public DateTime Item_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_DTS", true); - return _Item_DTS; - } - } - private string _Item_UserID = string.Empty; - public string Item_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_UserID", true); - return _Item_UserID; - } - } - // CSLATODO: Check ContentPart.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentPart - protected override object GetIdValue() - { - return MyContentPartUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ContentPart.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentPart - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyItem == null ? true : _MyItem.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemRequired, "MyItem"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyItemRequired(ContentPart target, Csla.Validation.RuleArgs e) - { - if (target._ItemID == 0 && target._MyItem == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(FromType, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ContentPartUnique = 0; - private static int ContentPartUnique - { get { return ++_ContentPartUnique; } } - private int _MyContentPartUnique = ContentPartUnique; - public int MyContentPartUnique // Absolutely Unique ID - Editable FK - { get { return _MyContentPartUnique; } } - internal static ContentPart New(int fromType, Item myItem) - { - return new ContentPart(fromType, myItem); - } - internal static ContentPart Get(SafeDataReader dr) - { - return new ContentPart(dr); - } - public ContentPart() - { - MarkAsChild(); + /// + /// ContentPart Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentPartConverter))] + public partial class ContentPart : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItem != value) + { + _MyItem = value; + _ItemID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int? _Item_PreviousID; + public int? Item_PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_PreviousID; + } + } + private int _Item_ContentID; + public int Item_ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ContentID; + } + } + private DateTime _Item_DTS = new DateTime(); + public DateTime Item_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_DTS; + } + } + private string _Item_UserID = string.Empty; + public string Item_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_UserID; + } + } + // CSLATODO: Check ContentPart.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentPart + protected override object GetIdValue() + { + return MyContentPartUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ContentPart.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentPart + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyItem == null ? true : _MyItem.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemRequired, "MyItem"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyItemRequired(ContentPart target, Csla.Validation.RuleArgs e) + { + if (target._ItemID == 0 && target._MyItem == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(FromType, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ContentPartUnique = 0; + private static int ContentPartUnique + { get { return ++_ContentPartUnique; } } + private int _MyContentPartUnique = ContentPartUnique; + public int MyContentPartUnique // Absolutely Unique ID - Editable FK + { get { return _MyContentPartUnique; } } + internal static ContentPart New(int fromType, Item myItem) + { + return new ContentPart(fromType, myItem); + } + internal static ContentPart Get(SafeDataReader dr) + { + return new ContentPart(dr); + } + public ContentPart() + { + MarkAsChild(); - _DTS = _ContentPartExtension.DefaultDTS; - _UserID = _ContentPartExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentPart(int fromType, Item myItem) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _DTS = _ContentPartExtension.DefaultDTS; - _UserID = _ContentPartExtension.DefaultUserID; - _FromType = fromType; - _MyItem = myItem; - ValidationRules.CheckRules(); - } - internal ContentPart(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ContentPart() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - if (_MyItem != null) - { - _MyItem.Dispose(); - _MyItem = null; - } - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentPart.FetchDR", GetHashCode()); - try - { - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Item_PreviousID = (int?)dr.GetValue("Item_PreviousID"); - _Item_ContentID = dr.GetInt32("Item_ContentID"); - _Item_DTS = dr.GetDateTime("Item_DTS"); - _Item_UserID = dr.GetString("Item_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentPart.FetchDR", ex); - throw new DbCslaException("ContentPart.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Part.Update(cn, myContent.ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Part.Remove(cn, myContent.ContentID, _FromType); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentPartExtension _ContentPartExtension = new ContentPartExtension(); - [Serializable()] - partial class ContentPartExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentPartConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentPart) - { - // Return the ToString value - return ((ContentPart)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _ContentPartExtension.DefaultDTS; + _UserID = _ContentPartExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentPart(int fromType, Item myItem) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _DTS = _ContentPartExtension.DefaultDTS; + _UserID = _ContentPartExtension.DefaultUserID; + _FromType = fromType; + _MyItem = myItem; + ValidationRules.CheckRules(); + } + internal ContentPart(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ContentPart() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + if (_MyItem != null) + { + _MyItem.Dispose(); + _MyItem = null; + } + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentPart.FetchDR", GetHashCode()); + try + { + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Item_PreviousID = (int?)dr.GetValue("Item_PreviousID"); + _Item_ContentID = dr.GetInt32("Item_ContentID"); + _Item_DTS = dr.GetDateTime("Item_DTS"); + _Item_UserID = dr.GetString("Item_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentPart.FetchDR", ex); + throw new DbCslaException("ContentPart.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Part.Update(cn, myContent.ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Part.Remove(cn, myContent.ContentID, _FromType); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentPartExtension _ContentPartExtension = new ContentPartExtension(); + [Serializable()] + partial class ContentPartExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentPartConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentPart) + { + // Return the ToString value + return ((ContentPart)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsage.cs index 158675ff..4451517d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentRoUsage.cs @@ -20,570 +20,551 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentRoUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentRoUsageConverter))] - public partial class ContentRoUsage : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; - return _ROUsageID; - } - } - private RoUsage _MyRoUsage; - [System.ComponentModel.DataObjectField(true, true)] - public RoUsage MyRoUsage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRoUsage", true); - if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); - return _MyRoUsage; - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - _RODbID = value.RODbID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _RODb_ROName = string.Empty; - /// - /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion - /// - public string RODb_ROName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_ROName", true); - return _RODb_ROName; - } - } - private string _RODb_FolderPath = string.Empty; - /// - /// Path to the RO database - /// - public string RODb_FolderPath - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_FolderPath", true); - return _RODb_FolderPath; - } - } - private string _RODb_DBConnectionString = string.Empty; - /// - /// Connection String - Default could just be the full path and name of the database - /// - public string RODb_DBConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_DBConnectionString", true); - return _RODb_DBConnectionString; - } - } - private string _RODb_Config = string.Empty; - public string RODb_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_Config", true); - return _RODb_Config; - } - } - private DateTime _RODb_DTS = new DateTime(); - public DateTime RODb_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_DTS", true); - return _RODb_DTS; - } - } - private string _RODb_UserID = string.Empty; - public string RODb_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_UserID", true); - return _RODb_UserID; - } - } - // CSLATODO: Check ContentRoUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentRoUsage - protected override object GetIdValue() - { - return MyContentRoUsageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ContentRoUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentRoUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - // CSLATODO: Add other validation rules - } - private static bool MyRODbRequired(ContentRoUsage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(ROUsageID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - } - 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; } } - private static int _ContentRoUsageUnique = 0; - private static int ContentRoUsageUnique - { get { return ++_ContentRoUsageUnique; } } - private int _MyContentRoUsageUnique = ContentRoUsageUnique; - public int MyContentRoUsageUnique // Absolutely Unique ID - Editable FK - { get { return _MyContentRoUsageUnique; } } - internal static ContentRoUsage New(string roid, RODb myRODb) - { - return new ContentRoUsage(roid, myRODb); - } - internal static ContentRoUsage Get(SafeDataReader dr) - { - return new ContentRoUsage(dr); - } - public ContentRoUsage() - { - MarkAsChild(); - _ROUsageID = RoUsage.NextROUsageID; - _DTS = _ContentRoUsageExtension.DefaultDTS; - _UserID = _ContentRoUsageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentRoUsage(string roid, RODb myRODb) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _ROUsageID = RoUsage.NextROUsageID; - _DTS = _ContentRoUsageExtension.DefaultDTS; - _UserID = _ContentRoUsageExtension.DefaultUserID; - _ROID = roid; - _MyRODb = myRODb; - ValidationRules.CheckRules(); - } - internal ContentRoUsage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ContentRoUsage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentRoUsage.FetchDR", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbID = dr.GetInt32("RODbID"); - _RODb_ROName = dr.GetString("RODb_ROName"); - _RODb_FolderPath = dr.GetString("RODb_FolderPath"); - _RODb_DBConnectionString = dr.GetString("RODb_DBConnectionString"); - _RODb_Config = dr.GetString("RODb_Config"); - _RODb_DTS = dr.GetDateTime("RODb_DTS"); - _RODb_UserID = dr.GetString("RODb_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentRoUsage.FetchDR", ex); - throw new DbCslaException("ContentRoUsage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Add(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, _MyRODb); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Update(cn, ref _ROUsageID, myContent.ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - RoUsage.Remove(cn, _ROUsageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentRoUsageExtension _ContentRoUsageExtension = new ContentRoUsageExtension(); - [Serializable()] - partial class ContentRoUsageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultContentID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentRoUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentRoUsage) - { - // Return the ToString value - return ((ContentRoUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentRoUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentRoUsageConverter))] + public partial class ContentRoUsage : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; + return _ROUsageID; + } + } + private RoUsage _MyRoUsage; + [System.ComponentModel.DataObjectField(true, true)] + public RoUsage MyRoUsage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); + return _MyRoUsage; + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + _RODbID = value.RODbID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _RODb_ROName = string.Empty; + /// + /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion + /// + public string RODb_ROName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_ROName; + } + } + private string _RODb_FolderPath = string.Empty; + /// + /// Path to the RO database + /// + public string RODb_FolderPath + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_FolderPath; + } + } + private string _RODb_DBConnectionString = string.Empty; + /// + /// Connection String - Default could just be the full path and name of the database + /// + public string RODb_DBConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_DBConnectionString; + } + } + private string _RODb_Config = string.Empty; + public string RODb_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_Config; + } + } + private DateTime _RODb_DTS = new DateTime(); + public DateTime RODb_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_DTS; + } + } + private string _RODb_UserID = string.Empty; + public string RODb_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_UserID; + } + } + // CSLATODO: Check ContentRoUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentRoUsage + protected override object GetIdValue() + { + return MyContentRoUsageUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ContentRoUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentRoUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + // CSLATODO: Add other validation rules + } + private static bool MyRODbRequired(ContentRoUsage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(ROUsageID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + } + 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; } } + private static int _ContentRoUsageUnique = 0; + private static int ContentRoUsageUnique + { get { return ++_ContentRoUsageUnique; } } + private int _MyContentRoUsageUnique = ContentRoUsageUnique; + public int MyContentRoUsageUnique // Absolutely Unique ID - Editable FK + { get { return _MyContentRoUsageUnique; } } + internal static ContentRoUsage New(string roid, RODb myRODb) + { + return new ContentRoUsage(roid, myRODb); + } + internal static ContentRoUsage Get(SafeDataReader dr) + { + return new ContentRoUsage(dr); + } + public ContentRoUsage() + { + MarkAsChild(); + _ROUsageID = RoUsage.NextROUsageID; + _DTS = _ContentRoUsageExtension.DefaultDTS; + _UserID = _ContentRoUsageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentRoUsage(string roid, RODb myRODb) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _ROUsageID = RoUsage.NextROUsageID; + _DTS = _ContentRoUsageExtension.DefaultDTS; + _UserID = _ContentRoUsageExtension.DefaultUserID; + _ROID = roid; + _MyRODb = myRODb; + ValidationRules.CheckRules(); + } + internal ContentRoUsage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ContentRoUsage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentRoUsage.FetchDR", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbID = dr.GetInt32("RODbID"); + _RODb_ROName = dr.GetString("RODb_ROName"); + _RODb_FolderPath = dr.GetString("RODb_FolderPath"); + _RODb_DBConnectionString = dr.GetString("RODb_DBConnectionString"); + _RODb_Config = dr.GetString("RODb_Config"); + _RODb_DTS = dr.GetDateTime("RODb_DTS"); + _RODb_UserID = dr.GetString("RODb_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentRoUsage.FetchDR", ex); + throw new DbCslaException("ContentRoUsage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Add(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, _MyRODb); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, myContent.ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + RoUsage.Remove(cn, _ROUsageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentRoUsageExtension _ContentRoUsageExtension = new ContentRoUsageExtension(); + [Serializable()] + partial class ContentRoUsageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultContentID + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentRoUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentRoUsage) + { + // Return the ToString value + return ((ContentRoUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransition.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransition.cs index 7d62d072..a730f992 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransition.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ContentTransition.cs @@ -21,667 +21,641 @@ using System.Text.RegularExpressions; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentTransition Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentTransitionConverter))] - public partial class ContentTransition : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private Item _MyItemToID; - public Item MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); - return _MyItemToID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemToID", true); - if (_MyItemToID != value) - { - _MyItemToID = value; - _ToID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private Item _MyItemRangeID; - public Item MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); - return _MyItemRangeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemRangeID", true); - if (_MyItemRangeID != value) - { - _MyItemRangeID = value; - _RangeID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _IsRange; - /// - /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling - /// - public int IsRange - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("IsRange", true); - return _IsRange; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("IsRange", true); - if (_IsRange != value) - { - _IsRange = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int? _Item_RangeID_PreviousID; - public int? Item_RangeID_PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_PreviousID", true); - return _Item_RangeID_PreviousID; - } - } - private int _Item_RangeID_ContentID; - public int Item_RangeID_ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_ContentID", true); - return _Item_RangeID_ContentID; - } - } - private DateTime _Item_RangeID_DTS = new DateTime(); - public DateTime Item_RangeID_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_DTS", true); - return _Item_RangeID_DTS; - } - } - private string _Item_RangeID_UserID = string.Empty; - public string Item_RangeID_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_UserID", true); - return _Item_RangeID_UserID; - } - } - private int? _Item_ToID_PreviousID; - public int? Item_ToID_PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_PreviousID", true); - return _Item_ToID_PreviousID; - } - } - private int _Item_ToID_ContentID; - public int Item_ToID_ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_ContentID", true); - return _Item_ToID_ContentID; - } - } - private DateTime _Item_ToID_DTS = new DateTime(); - public DateTime Item_ToID_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_DTS", true); - return _Item_ToID_DTS; - } - } - private string _Item_ToID_UserID = string.Empty; - public string Item_ToID_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_UserID", true); - return _Item_ToID_UserID; - } - } - // CSLATODO: Check ContentTransition.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentTransition - protected override object GetIdValue() - { - return MyContentTransitionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ContentTransition.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentTransition - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyItemToID == null ? false : _MyItemToID.IsDirtyList(list)) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyItemToID == null ? true : _MyItemToID.IsValidList(list)) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); - ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyItemToIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) - { - if (target._ToID == 0 && target._MyItemToID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyItemRangeIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) - { - if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(TransitionID, ""); - //AuthorizationRules.AllowRead(ToID, ""); - //AuthorizationRules.AllowWrite(ToID, ""); - //AuthorizationRules.AllowRead(RangeID, ""); - //AuthorizationRules.AllowWrite(RangeID, ""); - //AuthorizationRules.AllowRead(IsRange, ""); - //AuthorizationRules.AllowWrite(IsRange, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ContentTransitionUnique = 0; - private static int ContentTransitionUnique - { get { return ++_ContentTransitionUnique; } } - private int _MyContentTransitionUnique = ContentTransitionUnique; - public int MyContentTransitionUnique // Absolutely Unique ID - Editable FK - { get { return _MyContentTransitionUnique; } } - internal static ContentTransition New(Item myItemToID, Item myItemRangeID) - { - return new ContentTransition(myItemToID, myItemRangeID); - } - internal static ContentTransition Get(SafeDataReader dr) - { - return new ContentTransition(dr); - } - public ContentTransition() - { - MarkAsChild(); - _TransitionID = Transition.NextTransitionID; - _IsRange = _ContentTransitionExtension.DefaultIsRange; - _TranType = _ContentTransitionExtension.DefaultTranType; - _DTS = _ContentTransitionExtension.DefaultDTS; - _UserID = _ContentTransitionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentTransition(Item myItemToID, Item myItemRangeID) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _TransitionID = Transition.NextTransitionID; - _IsRange = _ContentTransitionExtension.DefaultIsRange; - _TranType = _ContentTransitionExtension.DefaultTranType; - _DTS = _ContentTransitionExtension.DefaultDTS; - _UserID = _ContentTransitionExtension.DefaultUserID; - _MyItemToID = myItemToID; - _MyItemRangeID = myItemRangeID; - ValidationRules.CheckRules(); - } - internal ContentTransition(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ContentTransition() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentTransition.FetchDR", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _ToID = dr.GetInt32("ToID"); - _RangeID = dr.GetInt32("RangeID"); - _IsRange = dr.GetInt32("IsRange"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Item_RangeID_PreviousID = (int?)dr.GetValue("Item_RangeID_PreviousID"); - _Item_RangeID_ContentID = dr.GetInt32("Item_RangeID_ContentID"); - _Item_RangeID_DTS = dr.GetDateTime("Item_RangeID_DTS"); - _Item_RangeID_UserID = dr.GetString("Item_RangeID_UserID"); - _Item_ToID_PreviousID = (int?)dr.GetValue("Item_ToID_PreviousID"); - _Item_ToID_ContentID = dr.GetInt32("Item_ToID_ContentID"); - _Item_ToID_DTS = dr.GetDateTime("Item_ToID_DTS"); - _Item_ToID_UserID = dr.GetString("Item_ToID_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentTransition.FetchDR", ex); - throw new DbCslaException("ContentTransition.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - string pattern = string.Format(@"( [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 - _Config = ""; - else - _Config = string.Empty; - _LastChanged = Transition.Add(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Update(cn, ref _TransitionID, myContent.ContentID, _ToID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Transition.Remove(cn, _TransitionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentTransitionExtension _ContentTransitionExtension = new ContentTransitionExtension(); - [Serializable()] - partial class ContentTransitionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultIsRange - { - get { return 0; } - } - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentTransitionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentTransition) - { - // Return the ToString value - return ((ContentTransition)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentTransition Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentTransitionConverter))] + public partial class ContentTransition : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private Item _MyItemToID; + public Item MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); + return _MyItemToID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemToID != value) + { + _MyItemToID = value; + _ToID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private Item _MyItemRangeID; + public Item MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); + return _MyItemRangeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemRangeID != value) + { + _MyItemRangeID = value; + _RangeID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _IsRange; + /// + /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling + /// + public int IsRange + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _IsRange; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_IsRange != value) + { + _IsRange = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int? _Item_RangeID_PreviousID; + public int? Item_RangeID_PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_PreviousID; + } + } + private int _Item_RangeID_ContentID; + public int Item_RangeID_ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_ContentID; + } + } + private DateTime _Item_RangeID_DTS = new DateTime(); + public DateTime Item_RangeID_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_DTS; + } + } + private string _Item_RangeID_UserID = string.Empty; + public string Item_RangeID_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_UserID; + } + } + private int? _Item_ToID_PreviousID; + public int? Item_ToID_PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_PreviousID; + } + } + private int _Item_ToID_ContentID; + public int Item_ToID_ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_ContentID; + } + } + private DateTime _Item_ToID_DTS = new DateTime(); + public DateTime Item_ToID_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_DTS; + } + } + private string _Item_ToID_UserID = string.Empty; + public string Item_ToID_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_UserID; + } + } + // CSLATODO: Check ContentTransition.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentTransition + protected override object GetIdValue() + { + return MyContentTransitionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ContentTransition.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentTransition + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyItemToID == null ? false : _MyItemToID.IsDirtyList(list)) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyItemToID == null ? true : _MyItemToID.IsValidList(list)) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); + ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyItemToIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) + { + if (target._ToID == 0 && target._MyItemToID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyItemRangeIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) + { + if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(TransitionID, ""); + //AuthorizationRules.AllowRead(ToID, ""); + //AuthorizationRules.AllowWrite(ToID, ""); + //AuthorizationRules.AllowRead(RangeID, ""); + //AuthorizationRules.AllowWrite(RangeID, ""); + //AuthorizationRules.AllowRead(IsRange, ""); + //AuthorizationRules.AllowWrite(IsRange, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ContentTransitionUnique = 0; + private static int ContentTransitionUnique + { get { return ++_ContentTransitionUnique; } } + private int _MyContentTransitionUnique = ContentTransitionUnique; + public int MyContentTransitionUnique // Absolutely Unique ID - Editable FK + { get { return _MyContentTransitionUnique; } } + internal static ContentTransition New(Item myItemToID, Item myItemRangeID) + { + return new ContentTransition(myItemToID, myItemRangeID); + } + internal static ContentTransition Get(SafeDataReader dr) + { + return new ContentTransition(dr); + } + public ContentTransition() + { + MarkAsChild(); + _TransitionID = Transition.NextTransitionID; + _IsRange = _ContentTransitionExtension.DefaultIsRange; + _TranType = _ContentTransitionExtension.DefaultTranType; + _DTS = _ContentTransitionExtension.DefaultDTS; + _UserID = _ContentTransitionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentTransition(Item myItemToID, Item myItemRangeID) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _TransitionID = Transition.NextTransitionID; + _IsRange = _ContentTransitionExtension.DefaultIsRange; + _TranType = _ContentTransitionExtension.DefaultTranType; + _DTS = _ContentTransitionExtension.DefaultDTS; + _UserID = _ContentTransitionExtension.DefaultUserID; + _MyItemToID = myItemToID; + _MyItemRangeID = myItemRangeID; + ValidationRules.CheckRules(); + } + internal ContentTransition(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ContentTransition() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentTransition.FetchDR", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _ToID = dr.GetInt32("ToID"); + _RangeID = dr.GetInt32("RangeID"); + _IsRange = dr.GetInt32("IsRange"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Item_RangeID_PreviousID = (int?)dr.GetValue("Item_RangeID_PreviousID"); + _Item_RangeID_ContentID = dr.GetInt32("Item_RangeID_ContentID"); + _Item_RangeID_DTS = dr.GetDateTime("Item_RangeID_DTS"); + _Item_RangeID_UserID = dr.GetString("Item_RangeID_UserID"); + _Item_ToID_PreviousID = (int?)dr.GetValue("Item_ToID_PreviousID"); + _Item_ToID_ContentID = dr.GetInt32("Item_ToID_ContentID"); + _Item_ToID_DTS = dr.GetDateTime("Item_ToID_DTS"); + _Item_ToID_UserID = dr.GetString("Item_ToID_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentTransition.FetchDR", ex); + throw new DbCslaException("ContentTransition.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + string pattern = string.Format(@"( [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 + _Config = ""; + else + _Config = string.Empty; + _LastChanged = Transition.Add(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Update(cn, ref _TransitionID, myContent.ContentID, _ToID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Transition.Remove(cn, _TransitionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentTransitionExtension _ContentTransitionExtension = new ContentTransitionExtension(); + [Serializable()] + partial class ContentTransitionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultIsRange + { + get { return 0; } + } + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentTransitionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentTransition) + { + // Return the ToString value + return ((ContentTransition)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAudit.cs index 760fdd4a..fe11cf1e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAudit.cs @@ -20,1037 +20,1018 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// AnnotationAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AnnotationAuditConverter))] - public partial class AnnotationAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshAnnotationAudits = new List(); - private void AddToRefreshList(List refreshAnnotationAudits) - { - if (IsDirty) - refreshAnnotationAudits.Add(this); - } - private void BuildRefreshList() - { - _RefreshAnnotationAudits = new List(); - AddToRefreshList(_RefreshAnnotationAudits); - } - private void ProcessRefreshList() - { - foreach (AnnotationAudit tmp in _RefreshAnnotationAudits) - { - AnnotationAuditInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AnnotationAudit annotationAudit) - { - if (!_CacheList.Contains(annotationAudit)) _CacheList.Add(annotationAudit); // In AddToCache - } - protected static void RemoveFromCache(AnnotationAudit annotationAudit) - { - while (_CacheList.Contains(annotationAudit)) _CacheList.Remove(annotationAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move AnnotationAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - AnnotationAudit tmp = _CacheList[0]; // Get the first AnnotationAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first AnnotationAudit - } - } - protected static AnnotationAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _AnnotationID; - public int AnnotationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationID", true); - return _AnnotationID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("AnnotationID", true); - if (_AnnotationID != value) - { - _AnnotationID = value; - PropertyHasChanged(); - } - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemID", true); - if (_ItemID != value) - { - _ItemID = value; - PropertyHasChanged(); - } - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - return _TypeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TypeID", true); - if (_TypeID != value) - { - _TypeID = value; - PropertyHasChanged(); - } - } - } - private string _RtfText = string.Empty; - public string RtfText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RtfText", true); - return _RtfText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("RtfText", true); - if (value == null) value = string.Empty; - if (_RtfText != value) - { - _RtfText = value; - PropertyHasChanged(); - } - } - } - private string _SearchText = string.Empty; - public string SearchText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SearchText", true); - return _SearchText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SearchText", true); - if (value == null) value = string.Empty; - if (_SearchText != value) - { - _SearchText = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base AnnotationAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AnnotationAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check AnnotationAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AnnotationAudit - protected override object GetIdValue() - { - return MyAnnotationAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _AnnotationAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _AnnotationAuditExtension.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, ""); - //AuthorizationRules.AllowRead(AnnotationID, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(TypeID, ""); - //AuthorizationRules.AllowRead(RtfText, ""); - //AuthorizationRules.AllowRead(SearchText, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(AnnotationID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(TypeID, ""); - //AuthorizationRules.AllowWrite(RtfText, ""); - //AuthorizationRules.AllowWrite(SearchText, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _AnnotationAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _AnnotationAuditExtension.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; } } - private static int _AnnotationAuditUnique = 0; - protected static int AnnotationAuditUnique - { get { return ++_AnnotationAuditUnique; } } - private int _MyAnnotationAuditUnique = AnnotationAuditUnique; - public int MyAnnotationAuditUnique // Absolutely Unique ID - Editable - { get { return _MyAnnotationAuditUnique; } } - protected AnnotationAudit() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listAnnotationAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listAnnotationAudit.Contains(this)) listAnnotationAudit.Remove(this); // Remove the item from the list - if (listAnnotationAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static AnnotationAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationAudit.New", ex); - } - } - public static AnnotationAudit New(int annotationID, int itemID, int typeID, DateTime dts, string userID, int deleteStatus) - { - AnnotationAudit tmp = AnnotationAudit.New(); - tmp.AnnotationID = annotationID; - tmp.ItemID = itemID; - tmp.TypeID = typeID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static AnnotationAudit New(int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) - { - AnnotationAudit tmp = AnnotationAudit.New(); - tmp.AnnotationID = annotationID; - tmp.ItemID = itemID; - tmp.TypeID = typeID; - tmp.RtfText = rtfText; - tmp.SearchText = searchText; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static AnnotationAudit MakeAnnotationAudit(int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) - { - AnnotationAudit tmp = AnnotationAudit.New(annotationID, itemID, typeID, rtfText, searchText, config, dts, userID, deleteStatus); - if (tmp.IsSavable) - { - AnnotationAudit tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static AnnotationAudit Get(long auditID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit"); - try - { - AnnotationAudit tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AnnotationAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationAudit.Get", ex); - } - } - public static AnnotationAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new AnnotationAudit(dr); - return null; - } - internal AnnotationAudit(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(long auditID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a AnnotationAudit"); - try - { - DataPortal.Delete(new PKCriteria(auditID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationAudit.Delete", ex); - } - } - public override AnnotationAudit Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a AnnotationAudit"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a AnnotationAudit"); - try - { - BuildRefreshList(); - AnnotationAudit annotationAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(annotationAudit);//Refresh the item in AllList - ProcessRefreshList(); - return annotationAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// AnnotationAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationAuditConverter))] + public partial class AnnotationAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshAnnotationAudits = new List(); + private void AddToRefreshList(List refreshAnnotationAudits) + { + if (IsDirty) + refreshAnnotationAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshAnnotationAudits = new List(); + AddToRefreshList(_RefreshAnnotationAudits); + } + private void ProcessRefreshList() + { + foreach (AnnotationAudit tmp in _RefreshAnnotationAudits) + { + AnnotationAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AnnotationAudit annotationAudit) + { + if (!_CacheList.Contains(annotationAudit)) _CacheList.Add(annotationAudit); // In AddToCache + } + protected static void RemoveFromCache(AnnotationAudit annotationAudit) + { + while (_CacheList.Contains(annotationAudit)) _CacheList.Remove(annotationAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move AnnotationAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + AnnotationAudit tmp = _CacheList[0]; // Get the first AnnotationAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first AnnotationAudit + } + } + protected static AnnotationAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _AnnotationID; + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_AnnotationID != value) + { + _AnnotationID = value; + PropertyHasChanged(); + } + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemID != value) + { + _ItemID = value; + PropertyHasChanged(); + } + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TypeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TypeID != value) + { + _TypeID = value; + PropertyHasChanged(); + } + } + } + private string _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RtfText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_RtfText != value) + { + _RtfText = value; + PropertyHasChanged(); + } + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SearchText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_SearchText != value) + { + _SearchText = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base AnnotationAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check AnnotationAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AnnotationAudit + protected override object GetIdValue() + { + return MyAnnotationAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _AnnotationAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _AnnotationAuditExtension.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, ""); + //AuthorizationRules.AllowRead(AnnotationID, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowRead(RtfText, ""); + //AuthorizationRules.AllowRead(SearchText, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(AnnotationID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(TypeID, ""); + //AuthorizationRules.AllowWrite(RtfText, ""); + //AuthorizationRules.AllowWrite(SearchText, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _AnnotationAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _AnnotationAuditExtension.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; } } + private static int _AnnotationAuditUnique = 0; + protected static int AnnotationAuditUnique + { get { return ++_AnnotationAuditUnique; } } + private int _MyAnnotationAuditUnique = AnnotationAuditUnique; + public int MyAnnotationAuditUnique // Absolutely Unique ID - Editable + { get { return _MyAnnotationAuditUnique; } } + protected AnnotationAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listAnnotationAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listAnnotationAudit.Contains(this)) listAnnotationAudit.Remove(this); // Remove the item from the list + if (listAnnotationAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static AnnotationAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.New", ex); + } + } + public static AnnotationAudit New(int annotationID, int itemID, int typeID, DateTime dts, string userID, int deleteStatus) + { + AnnotationAudit tmp = AnnotationAudit.New(); + tmp.AnnotationID = annotationID; + tmp.ItemID = itemID; + tmp.TypeID = typeID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static AnnotationAudit New(int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) + { + AnnotationAudit tmp = AnnotationAudit.New(); + tmp.AnnotationID = annotationID; + tmp.ItemID = itemID; + tmp.TypeID = typeID; + tmp.RtfText = rtfText; + tmp.SearchText = searchText; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static AnnotationAudit MakeAnnotationAudit(int annotationID, int itemID, int typeID, string rtfText, string searchText, string config, DateTime dts, string userID, int deleteStatus) + { + AnnotationAudit tmp = AnnotationAudit.New(annotationID, itemID, typeID, rtfText, searchText, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + AnnotationAudit tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static AnnotationAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit"); + try + { + AnnotationAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.Get", ex); + } + } + public static AnnotationAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new AnnotationAudit(dr); + return null; + } + internal AnnotationAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a AnnotationAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.Delete", ex); + } + } + public override AnnotationAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a AnnotationAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a AnnotationAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a AnnotationAudit"); + try + { + BuildRefreshList(); + AnnotationAudit annotationAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(annotationAudit);//Refresh the item in AllList + ProcessRefreshList(); + return annotationAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _AnnotationID = dr.GetInt32("AnnotationID"); - _ItemID = dr.GetInt32("ItemID"); - _TypeID = dr.GetInt32("TypeID"); - _RtfText = dr.GetString("RtfText"); - _SearchText = dr.GetString("SearchText"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAnnotationAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAnnotationAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); - cm.Parameters.AddWithValue("@ItemID", _ItemID); - cm.Parameters.AddWithValue("@TypeID", _TypeID); - cm.Parameters.AddWithValue("@RtfText", _RtfText); - cm.Parameters.AddWithValue("@SearchText", _SearchText); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAnnotationAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AnnotationID", annotationID); - cm.Parameters.AddWithValue("@ItemID", itemID); - cm.Parameters.AddWithValue("@TypeID", typeID); - cm.Parameters.AddWithValue("@RtfText", rtfText); - cm.Parameters.AddWithValue("@SearchText", searchText); - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Add", ex); - throw new DbCslaException("AnnotationAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAnnotationAudit"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AuditID", _AuditID); - cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); - cm.Parameters.AddWithValue("@ItemID", _ItemID); - cm.Parameters.AddWithValue("@TypeID", _TypeID); - cm.Parameters.AddWithValue("@RtfText", _RtfText); - cm.Parameters.AddWithValue("@SearchText", _SearchText); - 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - AnnotationAudit.Add(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); - else - AnnotationAudit.Update(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAnnotationAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AuditID", auditID); - cm.Parameters.AddWithValue("@AnnotationID", annotationID); - cm.Parameters.AddWithValue("@ItemID", itemID); - cm.Parameters.AddWithValue("@TypeID", typeID); - cm.Parameters.AddWithValue("@RtfText", rtfText); - cm.Parameters.AddWithValue("@SearchText", searchText); - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAnnotationAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAnnotationAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Remove", ex); - throw new DbCslaException("AnnotationAudit.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(long auditID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(auditID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationAudit.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private long _AuditID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(long auditID) - { - _AuditID = auditID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsAnnotationAudit"; - cm.Parameters.AddWithValue("@AuditID", _AuditID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Execute", ex); - throw new DbCslaException("AnnotationAudit.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - AnnotationAuditExtension _AnnotationAuditExtension = new AnnotationAuditExtension(); - [Serializable()] - partial class AnnotationAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class AnnotationAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AnnotationAudit) - { - // Return the ToString value - return ((AnnotationAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _AnnotationID = dr.GetInt32("AnnotationID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAnnotationAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RtfText", _RtfText); + cm.Parameters.AddWithValue("@SearchText", _SearchText); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAnnotationAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AnnotationID", annotationID); + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@TypeID", typeID); + cm.Parameters.AddWithValue("@RtfText", rtfText); + cm.Parameters.AddWithValue("@SearchText", searchText); + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Add", ex); + throw new DbCslaException("AnnotationAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotationAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RtfText", _RtfText); + cm.Parameters.AddWithValue("@SearchText", _SearchText); + 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + AnnotationAudit.Add(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); + else + AnnotationAudit.Update(cn, ref _AuditID, _AnnotationID, _ItemID, _TypeID, _RtfText, _SearchText, _Config, _DTS, _UserID, _DeleteStatus); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotationAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@AnnotationID", annotationID); + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@TypeID", typeID); + cm.Parameters.AddWithValue("@RtfText", rtfText); + cm.Parameters.AddWithValue("@SearchText", searchText); + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotationAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.Remove", ex); + throw new DbCslaException("AnnotationAudit.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(long auditID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(auditID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAudit.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private long _AuditID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(long auditID) + { + _AuditID = auditID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAudit.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", _AuditID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAudit.DataPortal_Execute", ex); + throw new DbCslaException("AnnotationAudit.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + AnnotationAuditExtension _AnnotationAuditExtension = new AnnotationAuditExtension(); + [Serializable()] + partial class AnnotationAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class AnnotationAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationAudit) + { + // Return the ToString value + return ((AnnotationAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAuditInfo.cs index f6a346ab..9bbfd86d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of AnnotationAuditInfo.cs @@ -19,376 +19,366 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void AnnotationAuditInfoEvent(object sender); - /// - /// AnnotationAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AnnotationAuditInfoConverter))] - public partial class AnnotationAuditInfo : ReadOnlyBase, IDisposable - { - public event AnnotationAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AnnotationAuditInfo annotationAuditInfo) - { - if (!_CacheList.Contains(annotationAuditInfo)) _CacheList.Add(annotationAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(AnnotationAuditInfo annotationAuditInfo) - { - while (_CacheList.Contains(annotationAuditInfo)) _CacheList.Remove(annotationAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move AnnotationAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - AnnotationAuditInfo tmp = _CacheList[0]; // Get the first AnnotationAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first AnnotationAuditInfo - } - } - internal static void AddList(AnnotationAuditInfoList lst) - { - foreach (AnnotationAuditInfo item in lst) AddToCache(item); - } - protected static AnnotationAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected AnnotationAudit _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _AnnotationID; - public int AnnotationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationID", true); - return _AnnotationID; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - return _TypeID; - } - } - private string _RtfText = string.Empty; - public string RtfText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RtfText", true); - return _RtfText; - } - } - private string _SearchText = string.Empty; - public string SearchText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SearchText", true); - return _SearchText; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base AnnotationAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AnnotationAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check AnnotationAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AnnotationAuditInfo - protected override object GetIdValue() - { - return MyAnnotationAuditInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _AnnotationAuditInfoUnique = 0; - private static int AnnotationAuditInfoUnique - { get { return ++_AnnotationAuditInfoUnique; } } - private int _MyAnnotationAuditInfoUnique = AnnotationAuditInfoUnique; - public int MyAnnotationAuditInfoUnique // Absolutely Unique ID - Info - { get { return _MyAnnotationAuditInfoUnique; } } - protected AnnotationAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listAnnotationAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listAnnotationAuditInfo.Contains(this)) listAnnotationAuditInfo.Remove(this); // Remove the item from the list - if (listAnnotationAuditInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - public virtual AnnotationAudit Get() - { - return _Editable = AnnotationAudit.Get(_AuditID); - } - public static void Refresh(AnnotationAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AnnotationAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(AnnotationAudit tmp) - { - _AnnotationID = tmp.AnnotationID; - _ItemID = tmp.ItemID; - _TypeID = tmp.TypeID; - _RtfText = tmp.RtfText; - _SearchText = tmp.SearchText; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _AnnotationAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static AnnotationAuditInfo Get(long auditID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit"); - try - { - AnnotationAuditInfo tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AnnotationAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal AnnotationAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.Constructor", ex); - throw new DbCslaException("AnnotationAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _AnnotationID = dr.GetInt32("AnnotationID"); - _ItemID = dr.GetInt32("ItemID"); - _TypeID = dr.GetInt32("TypeID"); - _RtfText = dr.GetString("RtfText"); - _SearchText = dr.GetString("SearchText"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAnnotationAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - AnnotationAuditInfoExtension _AnnotationAuditInfoExtension = new AnnotationAuditInfoExtension(); - [Serializable()] - partial class AnnotationAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(AnnotationAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class AnnotationAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AnnotationAuditInfo) - { - // Return the ToString value - return ((AnnotationAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void AnnotationAuditInfoEvent(object sender); + /// + /// AnnotationAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationAuditInfoConverter))] + public partial class AnnotationAuditInfo : ReadOnlyBase, IDisposable + { + public event AnnotationAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AnnotationAuditInfo annotationAuditInfo) + { + if (!_CacheList.Contains(annotationAuditInfo)) _CacheList.Add(annotationAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(AnnotationAuditInfo annotationAuditInfo) + { + while (_CacheList.Contains(annotationAuditInfo)) _CacheList.Remove(annotationAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move AnnotationAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + AnnotationAuditInfo tmp = _CacheList[0]; // Get the first AnnotationAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first AnnotationAuditInfo + } + } + internal static void AddList(AnnotationAuditInfoList lst) + { + foreach (AnnotationAuditInfo item in lst) AddToCache(item); + } + protected static AnnotationAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected AnnotationAudit _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _AnnotationID; + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TypeID; + } + } + private string _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RtfText; + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SearchText; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base AnnotationAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check AnnotationAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AnnotationAuditInfo + protected override object GetIdValue() + { + return MyAnnotationAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _AnnotationAuditInfoUnique = 0; + private static int AnnotationAuditInfoUnique + { get { return ++_AnnotationAuditInfoUnique; } } + private int _MyAnnotationAuditInfoUnique = AnnotationAuditInfoUnique; + public int MyAnnotationAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyAnnotationAuditInfoUnique; } } + protected AnnotationAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listAnnotationAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listAnnotationAuditInfo.Contains(this)) listAnnotationAuditInfo.Remove(this); // Remove the item from the list + if (listAnnotationAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual AnnotationAudit Get() + { + return _Editable = AnnotationAudit.Get(_AuditID); + } + public static void Refresh(AnnotationAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AnnotationAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(AnnotationAudit tmp) + { + _AnnotationID = tmp.AnnotationID; + _ItemID = tmp.ItemID; + _TypeID = tmp.TypeID; + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _AnnotationAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static AnnotationAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a AnnotationAudit"); + try + { + AnnotationAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal AnnotationAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.Constructor", ex); + throw new DbCslaException("AnnotationAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _AnnotationID = dr.GetInt32("AnnotationID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + AnnotationAuditInfoExtension _AnnotationAuditInfoExtension = new AnnotationAuditInfoExtension(); + [Serializable()] + partial class AnnotationAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(AnnotationAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class AnnotationAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationAuditInfo) + { + // Return the ToString value + return ((AnnotationAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAudit.cs index 832073ea..3fcd5f44 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAudit.cs @@ -20,982 +20,963 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentAuditConverter))] - public partial class ContentAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshContentAudits = new List(); - private void AddToRefreshList(List refreshContentAudits) - { - if (IsDirty) - refreshContentAudits.Add(this); - } - private void BuildRefreshList() - { - _RefreshContentAudits = new List(); - AddToRefreshList(_RefreshContentAudits); - } - private void ProcessRefreshList() - { - foreach (ContentAudit tmp in _RefreshContentAudits) - { - ContentAuditInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ContentAudit contentAudit) - { - if (!_CacheList.Contains(contentAudit)) _CacheList.Add(contentAudit); // In AddToCache - } - protected static void RemoveFromCache(ContentAudit contentAudit) - { - while (_CacheList.Contains(contentAudit)) _CacheList.Remove(contentAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ContentAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - ContentAudit tmp = _CacheList[0]; // Get the first ContentAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ContentAudit - } - } - protected static ContentAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private string _Number = string.Empty; - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Number", true); - if (value == null) value = string.Empty; - if (_Number != value) - { - _Number = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private int? _Type; - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Type", true); - if (_Type != value) - { - _Type = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FormatID", true); - if (_FormatID != value) - { - _FormatID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base ContentAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ContentAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentAudit - protected override object GetIdValue() - { - return MyContentAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 512)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _ContentAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ContentAuditExtension.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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(Number, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowRead(Type, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(Number, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowWrite(Type, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _ContentAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ContentAuditExtension.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; } } - private static int _ContentAuditUnique = 0; - protected static int ContentAuditUnique - { get { return ++_ContentAuditUnique; } } - private int _MyContentAuditUnique = ContentAuditUnique; - public int MyContentAuditUnique // Absolutely Unique ID - Editable - { get { return _MyContentAuditUnique; } } - protected ContentAudit() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listContentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listContentAudit.Contains(this)) listContentAudit.Remove(this); // Remove the item from the list - if (listContentAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static ContentAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAudit.New", ex); - } - } - public static ContentAudit New(int contentID, DateTime dts, string userID, int deleteStatus) - { - ContentAudit tmp = ContentAudit.New(); - tmp.ContentID = contentID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ContentAudit New(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) - { - ContentAudit tmp = ContentAudit.New(); - tmp.ContentID = contentID; - tmp.Number = number; - tmp.Text = text; - tmp.Type = type; - tmp.FormatID = formatID; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ContentAudit MakeContentAudit(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) - { - ContentAudit tmp = ContentAudit.New(contentID, number, text, type, formatID, config, dts, userID, deleteStatus); - if (tmp.IsSavable) - { - ContentAudit tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ContentAudit Get(long auditID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); - try - { - ContentAudit tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ContentAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAudit.Get", ex); - } - } - public static ContentAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new ContentAudit(dr); - return null; - } - internal ContentAudit(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(long auditID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); - try - { - DataPortal.Delete(new PKCriteria(auditID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAudit.Delete", ex); - } - } - public override ContentAudit Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ContentAudit"); - try - { - BuildRefreshList(); - ContentAudit contentAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(contentAudit);//Refresh the item in AllList - ProcessRefreshList(); - return contentAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// ContentAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentAuditConverter))] + public partial class ContentAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshContentAudits = new List(); + private void AddToRefreshList(List refreshContentAudits) + { + if (IsDirty) + refreshContentAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshContentAudits = new List(); + AddToRefreshList(_RefreshContentAudits); + } + private void ProcessRefreshList() + { + foreach (ContentAudit tmp in _RefreshContentAudits) + { + ContentAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ContentAudit contentAudit) + { + if (!_CacheList.Contains(contentAudit)) _CacheList.Add(contentAudit); // In AddToCache + } + protected static void RemoveFromCache(ContentAudit contentAudit) + { + while (_CacheList.Contains(contentAudit)) _CacheList.Remove(contentAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ContentAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + ContentAudit tmp = _CacheList[0]; // Get the first ContentAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ContentAudit + } + } + protected static ContentAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Number != value) + { + _Number = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private int? _Type; + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Type != value) + { + _Type = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_FormatID != value) + { + _FormatID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ContentAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ContentAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentAudit + protected override object GetIdValue() + { + return MyContentAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 512)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _ContentAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ContentAuditExtension.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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(Number, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowRead(Type, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(Number, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowWrite(Type, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _ContentAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ContentAuditExtension.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; } } + private static int _ContentAuditUnique = 0; + protected static int ContentAuditUnique + { get { return ++_ContentAuditUnique; } } + private int _MyContentAuditUnique = ContentAuditUnique; + public int MyContentAuditUnique // Absolutely Unique ID - Editable + { get { return _MyContentAuditUnique; } } + protected ContentAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listContentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listContentAudit.Contains(this)) listContentAudit.Remove(this); // Remove the item from the list + if (listContentAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static ContentAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.New", ex); + } + } + public static ContentAudit New(int contentID, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(); + tmp.ContentID = contentID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ContentAudit New(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(); + tmp.ContentID = contentID; + tmp.Number = number; + tmp.Text = text; + tmp.Type = type; + tmp.FormatID = formatID; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ContentAudit MakeContentAudit(int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, int deleteStatus) + { + ContentAudit tmp = ContentAudit.New(contentID, number, text, type, formatID, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + ContentAudit tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ContentAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); + try + { + ContentAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.Get", ex); + } + } + public static ContentAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new ContentAudit(dr); + return null; + } + internal ContentAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAudit.Delete", ex); + } + } + public override ContentAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ContentAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ContentAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ContentAudit"); + try + { + BuildRefreshList(); + ContentAudit contentAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(contentAudit);//Refresh the item in AllList + ProcessRefreshList(); + return contentAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addContentAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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("@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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addContentAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - 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("@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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Add", ex); - throw new DbCslaException("ContentAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateContentAudit"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AuditID", _AuditID); - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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("@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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); - else - ContentAudit.Update(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateContentAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AuditID", auditID); - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - 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("@DeleteStatus", deleteStatus); - // Output Calculated Columns - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteContentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteContentAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Remove", ex); - throw new DbCslaException("ContentAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - ContentAuditExtension _ContentAuditExtension = new ContentAuditExtension(); - [Serializable()] - partial class ContentAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentAudit) - { - // Return the ToString value - return ((ContentAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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("@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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + 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("@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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Add", ex); + throw new DbCslaException("ContentAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateContentAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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("@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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + ContentAudit.Add(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); + else + ContentAudit.Update(cn, ref _AuditID, _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, _DeleteStatus); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateContentAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + 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("@DeleteStatus", deleteStatus); + // Output Calculated Columns + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteContentAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAudit.Remove", ex); + throw new DbCslaException("ContentAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + ContentAuditExtension _ContentAuditExtension = new ContentAuditExtension(); + [Serializable()] + partial class ContentAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentAudit) + { + // Return the ToString value + return ((ContentAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAuditInfo.cs index af2bea2b..68303647 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of ContentAuditInfo.cs @@ -19,376 +19,366 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ContentAuditInfoEvent(object sender); - /// - /// ContentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentAuditInfoConverter))] - public partial class ContentAuditInfo : ReadOnlyBase, IDisposable - { - public event ContentAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ContentAuditInfo contentAuditInfo) - { - if (!_CacheList.Contains(contentAuditInfo)) _CacheList.Add(contentAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(ContentAuditInfo contentAuditInfo) - { - while (_CacheList.Contains(contentAuditInfo)) _CacheList.Remove(contentAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ContentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ContentAuditInfo tmp = _CacheList[0]; // Get the first ContentAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ContentAuditInfo - } - } - internal static void AddList(ContentAuditInfoList lst) - { - foreach (ContentAuditInfo item in lst) AddToCache(item); - } - protected static ContentAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ContentAudit _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private string _Number = string.Empty; - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - } - private int? _Type; - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base ContentAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ContentAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentAuditInfo - protected override object GetIdValue() - { - return MyContentAuditInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ContentAuditInfoUnique = 0; - private static int ContentAuditInfoUnique - { get { return ++_ContentAuditInfoUnique; } } - private int _MyContentAuditInfoUnique = ContentAuditInfoUnique; - public int MyContentAuditInfoUnique // Absolutely Unique ID - Info - { get { return _MyContentAuditInfoUnique; } } - protected ContentAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listContentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listContentAuditInfo.Contains(this)) listContentAuditInfo.Remove(this); // Remove the item from the list - if (listContentAuditInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - public virtual ContentAudit Get() - { - return _Editable = ContentAudit.Get(_AuditID); - } - public static void Refresh(ContentAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ContentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentAudit tmp) - { - _ContentID = tmp.ContentID; - _Number = tmp.Number; - _Text = tmp.Text; - _Type = tmp.Type; - _FormatID = tmp.FormatID; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _ContentAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ContentAuditInfo Get(long auditID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); - try - { - ContentAuditInfo tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ContentAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ContentAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.Constructor", ex); - throw new DbCslaException("ContentAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ContentAuditInfoExtension _ContentAuditInfoExtension = new ContentAuditInfoExtension(); - [Serializable()] - partial class ContentAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ContentAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ContentAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentAuditInfo) - { - // Return the ToString value - return ((ContentAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ContentAuditInfoEvent(object sender); + /// + /// ContentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentAuditInfoConverter))] + public partial class ContentAuditInfo : ReadOnlyBase, IDisposable + { + public event ContentAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ContentAuditInfo contentAuditInfo) + { + if (!_CacheList.Contains(contentAuditInfo)) _CacheList.Add(contentAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(ContentAuditInfo contentAuditInfo) + { + while (_CacheList.Contains(contentAuditInfo)) _CacheList.Remove(contentAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ContentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ContentAuditInfo tmp = _CacheList[0]; // Get the first ContentAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ContentAuditInfo + } + } + internal static void AddList(ContentAuditInfoList lst) + { + foreach (ContentAuditInfo item in lst) AddToCache(item); + } + protected static ContentAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ContentAudit _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + } + private int? _Type; + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base ContentAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ContentAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentAuditInfo + protected override object GetIdValue() + { + return MyContentAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ContentAuditInfoUnique = 0; + private static int ContentAuditInfoUnique + { get { return ++_ContentAuditInfoUnique; } } + private int _MyContentAuditInfoUnique = ContentAuditInfoUnique; + public int MyContentAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyContentAuditInfoUnique; } } + protected ContentAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listContentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listContentAuditInfo.Contains(this)) listContentAuditInfo.Remove(this); // Remove the item from the list + if (listContentAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual ContentAudit Get() + { + return _Editable = ContentAudit.Get(_AuditID); + } + public static void Refresh(ContentAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentAudit tmp) + { + _ContentID = tmp.ContentID; + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + _FormatID = tmp.FormatID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ContentAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ContentAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ContentAudit"); + try + { + ContentAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ContentAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.Constructor", ex); + throw new DbCslaException("ContentAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ContentAuditInfoExtension _ContentAuditInfoExtension = new ContentAuditInfoExtension(); + [Serializable()] + partial class ContentAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ContentAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ContentAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentAuditInfo) + { + // Return the ToString value + return ((ContentAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAudit.cs index d6d142c3..340ceadb 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAudit.cs @@ -20,1017 +20,996 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocumentAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentAuditConverter))] - public partial class DocumentAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDocumentAudits = new List(); - private void AddToRefreshList(List refreshDocumentAudits) - { - if (IsDirty) - refreshDocumentAudits.Add(this); - } - private void BuildRefreshList() - { - _RefreshDocumentAudits = new List(); - AddToRefreshList(_RefreshDocumentAudits); - } - private void ProcessRefreshList() - { - foreach (DocumentAudit tmp in _RefreshDocumentAudits) - { - DocumentAuditInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocumentAudit documentAudit) - { - if (!_CacheList.Contains(documentAudit)) _CacheList.Add(documentAudit); // In AddToCache - } - protected static void RemoveFromCache(DocumentAudit documentAudit) - { - while (_CacheList.Contains(documentAudit)) _CacheList.Remove(documentAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DocumentAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - DocumentAudit tmp = _CacheList[0]; // Get the first DocumentAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DocumentAudit - } - } - protected static DocumentAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocID", true); - if (_DocID != value) - { - _DocID = value; - PropertyHasChanged(); - } - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("LibTitle", true); - if (value == null) value = string.Empty; - if (_LibTitle != value) - { - _LibTitle = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocContent; - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocContent", true); - if (_DocContent != value) - { - _DocContent = value; - PropertyHasChanged(); - } - } - } - private string _DocAscii = string.Empty; - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocAscii", true); - if (value == null) value = string.Empty; - if (_DocAscii != value) - { - _DocAscii = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private string _FileExtension = string.Empty; - public string FileExtension - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileExtension", true); - return _FileExtension; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileExtension", true); - if (value == null) value = string.Empty; - if (_FileExtension != value) - { - _FileExtension = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocPdf; - public byte[] DocPdf - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocPdf", true); - return _DocPdf; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocPdf", true); - if (_DocPdf != value) - { - _DocPdf = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base DocumentAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DocumentAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentAudit - protected override object GetIdValue() - { - return MyDocumentAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 2048)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileExtension"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileExtension", 20)); - //ValidationRules.AddDependantProperty("x", "y"); - _DocumentAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(LibTitle, ""); - //AuthorizationRules.AllowRead(DocContent, ""); - //AuthorizationRules.AllowRead(DocAscii, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(FileExtension, ""); - //AuthorizationRules.AllowRead(DocPdf, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(LibTitle, ""); - //AuthorizationRules.AllowWrite(DocContent, ""); - //AuthorizationRules.AllowWrite(DocAscii, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(FileExtension, ""); - //AuthorizationRules.AllowWrite(DocPdf, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _DocumentAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 DocumentAudit() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listDocumentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listDocumentAudit.Contains(this)) listDocumentAudit.Remove(this); // Remove the item from the list - if (listDocumentAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static DocumentAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAudit.New", ex); - } - } - public static DocumentAudit New(int docID, DateTime dts, string userID, string fileExtension, int deleteStatus) - { - DocumentAudit tmp = DocumentAudit.New(); - tmp.DocID = docID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.FileExtension = fileExtension; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static DocumentAudit New(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) - { - DocumentAudit tmp = DocumentAudit.New(); - tmp.DocID = docID; - tmp.LibTitle = libTitle; - tmp.DocContent = docContent; - tmp.DocAscii = docAscii; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.FileExtension = fileExtension; - tmp.DocPdf = docPdf; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static DocumentAudit MakeDocumentAudit(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) - { - DocumentAudit tmp = DocumentAudit.New(docID, libTitle, docContent, docAscii, config, dts, userID, fileExtension, docPdf, deleteStatus); - if (tmp.IsSavable) - { - DocumentAudit tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocumentAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAudit.Get", ex); - } - } - public static DocumentAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new DocumentAudit(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAudit.Delete", ex); - } - } - 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(); - DocumentAudit documentAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(documentAudit);//Refresh the item in AllList - ProcessRefreshList(); - return documentAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// DocumentAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentAuditConverter))] + public partial class DocumentAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocumentAudits = new List(); + private void AddToRefreshList(List refreshDocumentAudits) + { + if (IsDirty) + refreshDocumentAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshDocumentAudits = new List(); + AddToRefreshList(_RefreshDocumentAudits); + } + private void ProcessRefreshList() + { + foreach (DocumentAudit tmp in _RefreshDocumentAudits) + { + DocumentAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocumentAudit documentAudit) + { + if (!_CacheList.Contains(documentAudit)) _CacheList.Add(documentAudit); // In AddToCache + } + protected static void RemoveFromCache(DocumentAudit documentAudit) + { + while (_CacheList.Contains(documentAudit)) _CacheList.Remove(documentAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocumentAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocumentAudit tmp = _CacheList[0]; // Get the first DocumentAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DocumentAudit + } + } + protected static DocumentAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocID != value) + { + _DocID = value; + PropertyHasChanged(); + } + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_LibTitle != value) + { + _LibTitle = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocContent; + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocContent != value) + { + _DocContent = value; + PropertyHasChanged(); + } + } + } + private string _DocAscii = string.Empty; + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_DocAscii != value) + { + _DocAscii = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileExtension; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileExtension != value) + { + _FileExtension = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocPdf; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocPdf != value) + { + _DocPdf = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base DocumentAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocumentAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentAudit + protected override object GetIdValue() + { + return MyDocumentAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 2048)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileExtension"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileExtension", 20)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocumentAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(LibTitle, ""); + //AuthorizationRules.AllowRead(DocContent, ""); + //AuthorizationRules.AllowRead(DocAscii, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(FileExtension, ""); + //AuthorizationRules.AllowRead(DocPdf, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(LibTitle, ""); + //AuthorizationRules.AllowWrite(DocContent, ""); + //AuthorizationRules.AllowWrite(DocAscii, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(FileExtension, ""); + //AuthorizationRules.AllowWrite(DocPdf, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _DocumentAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 DocumentAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listDocumentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listDocumentAudit.Contains(this)) listDocumentAudit.Remove(this); // Remove the item from the list + if (listDocumentAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static DocumentAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.New", ex); + } + } + public static DocumentAudit New(int docID, DateTime dts, string userID, string fileExtension, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(); + tmp.DocID = docID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.FileExtension = fileExtension; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static DocumentAudit New(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(); + tmp.DocID = docID; + tmp.LibTitle = libTitle; + tmp.DocContent = docContent; + tmp.DocAscii = docAscii; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.FileExtension = fileExtension; + tmp.DocPdf = docPdf; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static DocumentAudit MakeDocumentAudit(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(docID, libTitle, docContent, docAscii, config, dts, userID, fileExtension, docPdf, deleteStatus); + if (tmp.IsSavable) + { + DocumentAudit tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.Get", ex); + } + } + public static DocumentAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new DocumentAudit(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.Delete", ex); + } + } + 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(); + DocumentAudit documentAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(documentAudit);//Refresh the item in AllList + ProcessRefreshList(); + return documentAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _FileExtension = dr.GetString("FileExtension"); - _DocPdf = (byte[])dr.GetValue("DocPdf"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocumentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Add", ex); - throw new DbCslaException("DocumentAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateDocumentAudit"; - // Input All Fields - Except Calculated Columns - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Update", ex); - throw new DbCslaException("DocumentAudit.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}] DocumentAudit.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocumentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocumentAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Remove", ex); - throw new DbCslaException("DocumentAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension(); - [Serializable()] - partial class DocumentAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentAudit) - { - // Return the ToString value - return ((DocumentAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FileExtension = dr.GetString("FileExtension"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Add", ex); + throw new DbCslaException("DocumentAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDocumentAudit"; + // Input All Fields - Except Calculated Columns + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Update", ex); + throw new DbCslaException("DocumentAudit.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}] DocumentAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocumentAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Remove", ex); + throw new DbCslaException("DocumentAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension(); + [Serializable()] + partial class DocumentAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentAudit) + { + // Return the ToString value + return ((DocumentAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAuditInfo.cs index 094837d6..6a414a83 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of DocumentAuditInfo.cs @@ -19,388 +19,377 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DocumentAuditInfoEvent(object sender); - /// - /// DocumentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentAuditInfoConverter))] - public partial class DocumentAuditInfo : ReadOnlyBase, IDisposable - { - public event DocumentAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocumentAuditInfo documentAuditInfo) - { - if (!_CacheList.Contains(documentAuditInfo)) _CacheList.Add(documentAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(DocumentAuditInfo documentAuditInfo) - { - while (_CacheList.Contains(documentAuditInfo)) _CacheList.Remove(documentAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DocumentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - DocumentAuditInfo tmp = _CacheList[0]; // Get the first DocumentAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DocumentAuditInfo - } - } - internal static void AddList(DocumentAuditInfoList lst) - { - foreach (DocumentAuditInfo item in lst) AddToCache(item); - } - protected static DocumentAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - } - private byte[] _DocContent; - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - } - private string _DocAscii = string.Empty; - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private string _FileExtension = string.Empty; - public string FileExtension - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileExtension", true); - return _FileExtension; - } - } - private byte[] _DocPdf; - public byte[] DocPdf - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocPdf", true); - return _DocPdf; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base DocumentAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DocumentAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentAuditInfo - protected override object GetIdValue() - { - return 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; } } - protected DocumentAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listDocumentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listDocumentAuditInfo.Contains(this)) listDocumentAuditInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(DocumentAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocumentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocumentAudit tmp) - { - _DocID = tmp.DocID; - _LibTitle = tmp.LibTitle; - _DocContent = tmp.DocContent; - _DocAscii = tmp.DocAscii; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FileExtension = tmp.FileExtension; - _DocPdf = tmp.DocPdf; - _DeleteStatus = tmp.DeleteStatus; - _DocumentAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocumentAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DocumentAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.Constructor", ex); - throw new DbCslaException("DocumentAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _FileExtension = dr.GetString("FileExtension"); - _DocPdf = (byte[])dr.GetValue("DocPdf"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocumentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension(); - [Serializable()] - partial class DocumentAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DocumentAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DocumentAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentAuditInfo) - { - // Return the ToString value - return ((DocumentAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DocumentAuditInfoEvent(object sender); + /// + /// DocumentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentAuditInfoConverter))] + public partial class DocumentAuditInfo : ReadOnlyBase, IDisposable + { + public event DocumentAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocumentAuditInfo documentAuditInfo) + { + if (!_CacheList.Contains(documentAuditInfo)) _CacheList.Add(documentAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(DocumentAuditInfo documentAuditInfo) + { + while (_CacheList.Contains(documentAuditInfo)) _CacheList.Remove(documentAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocumentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocumentAuditInfo tmp = _CacheList[0]; // Get the first DocumentAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DocumentAuditInfo + } + } + internal static void AddList(DocumentAuditInfoList lst) + { + foreach (DocumentAuditInfo item in lst) AddToCache(item); + } + protected static DocumentAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + } + private byte[] _DocContent; + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + } + private string _DocAscii = string.Empty; + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileExtension; + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocPdf; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base DocumentAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocumentAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentAuditInfo + protected override object GetIdValue() + { + return 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; } } + protected DocumentAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listDocumentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listDocumentAuditInfo.Contains(this)) listDocumentAuditInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(DocumentAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocumentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocumentAudit tmp) + { + _DocID = tmp.DocID; + _LibTitle = tmp.LibTitle; + _DocContent = tmp.DocContent; + _DocAscii = tmp.DocAscii; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FileExtension = tmp.FileExtension; + _DocPdf = tmp.DocPdf; + _DeleteStatus = tmp.DeleteStatus; + _DocumentAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocumentAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.Constructor", ex); + throw new DbCslaException("DocumentAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FileExtension = dr.GetString("FileExtension"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension(); + [Serializable()] + partial class DocumentAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocumentAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocumentAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentAuditInfo) + { + // Return the ToString value + return ((DocumentAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of EntryAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of EntryAudit.cs index 8df68a2f..1949a3da 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Copy of EntryAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Copy of EntryAudit.cs @@ -20,849 +20,838 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// EntryAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(EntryAuditConverter))] - public partial class EntryAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshEntryAudits = new List(); - private void AddToRefreshList(List refreshEntryAudits) - { - if (IsDirty) - refreshEntryAudits.Add(this); - } - private void BuildRefreshList() - { - _RefreshEntryAudits = new List(); - AddToRefreshList(_RefreshEntryAudits); - } - private void ProcessRefreshList() - { - foreach (EntryAudit tmp in _RefreshEntryAudits) - { - EntryAuditInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(EntryAudit entryAudit) - { - if (!_CacheList.Contains(entryAudit)) _CacheList.Add(entryAudit); // In AddToCache - } - protected static void RemoveFromCache(EntryAudit entryAudit) - { - while (_CacheList.Contains(entryAudit)) _CacheList.Remove(entryAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move EntryAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - EntryAudit tmp = _CacheList[0]; // Get the first EntryAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first EntryAudit - } - } - protected static EntryAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocID", true); - if (_DocID != value) - { - _DocID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base EntryAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current EntryAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check EntryAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current EntryAudit - protected override object GetIdValue() - { - return MyEntryAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _EntryAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _EntryAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 EntryAudit() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listEntryAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listEntryAudit.Contains(this)) listEntryAudit.Remove(this); // Remove the item from the list - if (listEntryAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static EntryAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a EntryAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryAudit.New", ex); - } - } - public static EntryAudit New(int contentID, int docID, DateTime dts, string userID, int deleteStatus) - { - EntryAudit tmp = EntryAudit.New(); - tmp.ContentID = contentID; - tmp.DocID = docID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static EntryAudit MakeEntryAudit(int contentID, int docID, DateTime dts, string userID, int deleteStatus) - { - EntryAudit tmp = EntryAudit.New(contentID, docID, dts, userID, deleteStatus); - if (tmp.IsSavable) - { - EntryAudit tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up EntryAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryAudit.Get", ex); - } - } - public static EntryAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new EntryAudit(dr); - return null; - } - internal EntryAudit(SafeDataReader dr) - { - ReadData(dr); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryAudit.Delete", ex); - } - } - 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(); - EntryAudit entryAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(entryAudit);//Refresh the item in AllList - ProcessRefreshList(); - return entryAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// EntryAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryAuditConverter))] + public partial class EntryAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshEntryAudits = new List(); + private void AddToRefreshList(List refreshEntryAudits) + { + if (IsDirty) + refreshEntryAudits.Add(this); + } + private void BuildRefreshList() + { + _RefreshEntryAudits = new List(); + AddToRefreshList(_RefreshEntryAudits); + } + private void ProcessRefreshList() + { + foreach (EntryAudit tmp in _RefreshEntryAudits) + { + EntryAuditInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(EntryAudit entryAudit) + { + if (!_CacheList.Contains(entryAudit)) _CacheList.Add(entryAudit); // In AddToCache + } + protected static void RemoveFromCache(EntryAudit entryAudit) + { + while (_CacheList.Contains(entryAudit)) _CacheList.Remove(entryAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move EntryAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + EntryAudit tmp = _CacheList[0]; // Get the first EntryAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first EntryAudit + } + } + protected static EntryAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocID != value) + { + _DocID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base EntryAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current EntryAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check EntryAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current EntryAudit + protected override object GetIdValue() + { + return MyEntryAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _EntryAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _EntryAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 EntryAudit() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listEntryAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listEntryAudit.Contains(this)) listEntryAudit.Remove(this); // Remove the item from the list + if (listEntryAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static EntryAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a EntryAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.New", ex); + } + } + public static EntryAudit New(int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + EntryAudit tmp = EntryAudit.New(); + tmp.ContentID = contentID; + tmp.DocID = docID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static EntryAudit MakeEntryAudit(int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + EntryAudit tmp = EntryAudit.New(contentID, docID, dts, userID, deleteStatus); + if (tmp.IsSavable) + { + EntryAudit tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up EntryAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.Get", ex); + } + } + public static EntryAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new EntryAudit(dr); + return null; + } + internal EntryAudit(SafeDataReader dr) + { + ReadData(dr); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.Delete", ex); + } + } + 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(); + EntryAudit entryAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(entryAudit);//Refresh the item in AllList + ProcessRefreshList(); + return entryAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _DocID = dr.GetInt32("DocID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getEntryAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Add", ex); - throw new DbCslaException("EntryAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateEntryAudit"; - // Input All Fields - Except Calculated Columns - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteEntryAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteEntryAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Remove", ex); - throw new DbCslaException("EntryAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension(); - [Serializable()] - partial class EntryAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class EntryAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is EntryAudit) - { - // Return the ToString value - return ((EntryAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Add", ex); + throw new DbCslaException("EntryAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateEntryAudit"; + // Input All Fields - Except Calculated Columns + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteEntryAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Remove", ex); + throw new DbCslaException("EntryAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension(); + [Serializable()] + partial class EntryAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class EntryAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryAudit) + { + // Return the ToString value + return ((EntryAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs index 45ec0450..37121afd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsage.cs @@ -20,1098 +20,1083 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DROUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DROUsageConverter))] - public partial class DROUsage : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDROUsages = new List(); - private void AddToRefreshList(List refreshDROUsages) - { - if (IsDirty) - refreshDROUsages.Add(this); - } - private void ClearRefreshList() - { - _RefreshDROUsages = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshDROUsages); - } - private void ProcessRefreshList() - { - foreach (DROUsage tmp in _RefreshDROUsages) - { - DROUsageInfo.Refresh(tmp); - if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); - if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DROUsage dROUsage) - { - if (!_CacheList.Contains(dROUsage)) _CacheList.Add(dROUsage); // In AddToCache - } - protected static void RemoveFromCache(DROUsage dROUsage) - { - while (_CacheList.Contains(dROUsage)) _CacheList.Remove(dROUsage); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DROUsage(s) from temporary _CacheList to _CacheByPrimaryKey - { - DROUsage tmp = _CacheList[0]; // Get the first DROUsage - string pKey = tmp.DROUsageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DROUsage - } - } - protected static DROUsage GetCachedByPrimaryKey(int dROUsageID) - { - ConvertListToDictionary(); - string key = dROUsageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextDROUsageID = -1; - public static int NextDROUsageID - { - get { return _nextDROUsageID--; } - } - private int _DROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int DROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DROUsageID", true); - return _DROUsageID; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private Document _MyDocument; - public Document MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); - return _MyDocument; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyDocument", true); - if (_MyDocument != value) - { - _MyDocument = value; - _DocID = value.DocID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - _RODbID = value.RODbID;// Update underlying data field - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); - } - // CSLATODO: Replace base DROUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DROUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DROUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DROUsage - protected override object GetIdValue() - { - return MyDROUsageUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - //ValidationRules.AddDependantProperty("x", "y"); - _DROUsageExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _DROUsageExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyDocumentRequired(DROUsage target, Csla.Validation.RuleArgs e) - { - if (target._DocID == 0 && target._MyDocument == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyRODbRequired(DROUsage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - _DROUsageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 DROUsage() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DROUsage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DROUsageID.ToString())) - { - List listDROUsage = _CacheByPrimaryKey[DROUsageID.ToString()]; // Get the list of items - while (listDROUsage.Contains(this)) listDROUsage.Remove(this); // Remove the item from the list - if (listDROUsage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DROUsageID.ToString()); // remove the list - } - } - public static DROUsage New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DROUsage"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DROUsage.New", ex); - } - } - public static DROUsage New(string roid, RODb myRODb) - { - DROUsage tmp = DROUsage.New(); - tmp.ROID = roid; - tmp.MyRODb = myRODb; - return tmp; - } - public static DROUsage New(Document myDocument, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - DROUsage tmp = DROUsage.New(); - tmp.MyDocument = myDocument; - tmp.ROID = roid; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.MyRODb = myRODb; - return tmp; - } - public static DROUsage MakeDROUsage(Document myDocument, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - DROUsage tmp = DROUsage.New(myDocument, roid, config, dts, userID, myRODb); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static DROUsage New(Document myDocument, string roid, string config, RODb myRODb) - { - DROUsage tmp = DROUsage.New(); - tmp.MyDocument = myDocument; - tmp.ROID = roid; - tmp.Config = config; - tmp.MyRODb = myRODb; - return tmp; - } - public static DROUsage MakeDROUsage(Document myDocument, string roid, string config, RODb myRODb) - { - DROUsage tmp = DROUsage.New(myDocument, roid, config, myRODb); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(dROUsageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DROUsage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DROUsage.Get", ex); - } - } - public static DROUsage Get(SafeDataReader dr) - { - if (dr.Read()) return new DROUsage(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DROUsage.Delete", ex); - } - } - 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(); - DROUsage dROUsage = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(dROUsage);//Refresh the item in AllList - ProcessRefreshList(); - return dROUsage; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DROUsageID; - public int DROUsageID - { get { return _DROUsageID; } } - public PKCriteria(int dROUsageID) - { - _DROUsageID = dROUsageID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _DROUsageID = NextDROUsageID; - // Database Defaults - _DocID = _DROUsageExtension.DefaultDocID; - _DTS = _DROUsageExtension.DefaultDTS; - _UserID = _DROUsageExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.ReadData", GetHashCode()); - try - { - _DROUsageID = dr.GetInt32("DROUsageID"); - _DocID = dr.GetInt32("DocID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbID = dr.GetInt32("RODbID"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DROUsage.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDROUsage"; - cm.Parameters.AddWithValue("@DROUsageID", criteria.DROUsageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DROUsage.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DROUsage.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyDocument != null) _MyDocument.Update(); - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myDocument.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", myRODb.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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.Add", ex); - throw new DbCslaException("DROUsage.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - 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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDROUsage"; - // Input All Fields - Except Calculated Columns - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.Update", ex); - throw new DbCslaException("DROUsage.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_DROUsageID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDROUsage"; - cm.Parameters.AddWithValue("@DROUsageID", criteria.DROUsageID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDROUsage"; - // Input PK Fields - cm.Parameters.AddWithValue("@DROUsageID", dROUsageID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.Remove", ex); - throw new DbCslaException("DROUsage.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int dROUsageID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(dROUsageID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DROUsage.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DROUsageID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int dROUsageID) - { - _DROUsageID = dROUsageID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsDROUsage"; - cm.Parameters.AddWithValue("@DROUsageID", _DROUsageID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Execute", ex); - throw new DbCslaException("DROUsage.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DROUsageExtension _DROUsageExtension = new DROUsageExtension(); - [Serializable()] - partial class DROUsageExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DROUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DROUsage) - { - // Return the ToString value - return ((DROUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// DROUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DROUsageConverter))] + public partial class DROUsage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDROUsages = new List(); + private void AddToRefreshList(List refreshDROUsages) + { + if (IsDirty) + refreshDROUsages.Add(this); + } + private void ClearRefreshList() + { + _RefreshDROUsages = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshDROUsages); + } + private void ProcessRefreshList() + { + foreach (DROUsage tmp in _RefreshDROUsages) + { + DROUsageInfo.Refresh(tmp); + if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); + if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DROUsage dROUsage) + { + if (!_CacheList.Contains(dROUsage)) _CacheList.Add(dROUsage); // In AddToCache + } + protected static void RemoveFromCache(DROUsage dROUsage) + { + while (_CacheList.Contains(dROUsage)) _CacheList.Remove(dROUsage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DROUsage(s) from temporary _CacheList to _CacheByPrimaryKey + { + DROUsage tmp = _CacheList[0]; // Get the first DROUsage + string pKey = tmp.DROUsageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DROUsage + } + } + protected static DROUsage GetCachedByPrimaryKey(int dROUsageID) + { + ConvertListToDictionary(); + string key = dROUsageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextDROUsageID = -1; + public static int NextDROUsageID + { + get { return _nextDROUsageID--; } + } + private int _DROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int DROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DROUsageID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private Document _MyDocument; + public Document MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); + return _MyDocument; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyDocument != value) + { + _MyDocument = value; + _DocID = value.DocID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + _RODbID = value.RODbID;// Update underlying data field + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + } + // CSLATODO: Replace base DROUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DROUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DROUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DROUsage + protected override object GetIdValue() + { + return MyDROUsageUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + //ValidationRules.AddDependantProperty("x", "y"); + _DROUsageExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DROUsageExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyDocumentRequired(DROUsage target, Csla.Validation.RuleArgs e) + { + if (target._DocID == 0 && target._MyDocument == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyRODbRequired(DROUsage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + _DROUsageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 DROUsage() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DROUsage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DROUsageID.ToString())) + { + List listDROUsage = _CacheByPrimaryKey[DROUsageID.ToString()]; // Get the list of items + while (listDROUsage.Contains(this)) listDROUsage.Remove(this); // Remove the item from the list + if (listDROUsage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DROUsageID.ToString()); // remove the list + } + } + public static DROUsage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DROUsage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DROUsage.New", ex); + } + } + public static DROUsage New(string roid, RODb myRODb) + { + DROUsage tmp = DROUsage.New(); + tmp.ROID = roid; + tmp.MyRODb = myRODb; + return tmp; + } + public static DROUsage New(Document myDocument, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + DROUsage tmp = DROUsage.New(); + tmp.MyDocument = myDocument; + tmp.ROID = roid; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.MyRODb = myRODb; + return tmp; + } + public static DROUsage MakeDROUsage(Document myDocument, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + DROUsage tmp = DROUsage.New(myDocument, roid, config, dts, userID, myRODb); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static DROUsage New(Document myDocument, string roid, string config, RODb myRODb) + { + DROUsage tmp = DROUsage.New(); + tmp.MyDocument = myDocument; + tmp.ROID = roid; + tmp.Config = config; + tmp.MyRODb = myRODb; + return tmp; + } + public static DROUsage MakeDROUsage(Document myDocument, string roid, string config, RODb myRODb) + { + DROUsage tmp = DROUsage.New(myDocument, roid, config, myRODb); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dROUsageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DROUsage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DROUsage.Get", ex); + } + } + public static DROUsage Get(SafeDataReader dr) + { + if (dr.Read()) return new DROUsage(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DROUsage.Delete", ex); + } + } + 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(); + DROUsage dROUsage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(dROUsage);//Refresh the item in AllList + ProcessRefreshList(); + return dROUsage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DROUsageID; + public int DROUsageID + { get { return _DROUsageID; } } + public PKCriteria(int dROUsageID) + { + _DROUsageID = dROUsageID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _DROUsageID = NextDROUsageID; + // Database Defaults + _DocID = _DROUsageExtension.DefaultDocID; + _DTS = _DROUsageExtension.DefaultDTS; + _UserID = _DROUsageExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.ReadData", GetHashCode()); + try + { + _DROUsageID = dr.GetInt32("DROUsageID"); + _DocID = dr.GetInt32("DocID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbID = dr.GetInt32("RODbID"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DROUsage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDROUsage"; + cm.Parameters.AddWithValue("@DROUsageID", criteria.DROUsageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DROUsage.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DROUsage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyDocument != null) _MyDocument.Update(); + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myDocument.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", myRODb.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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.Add", ex); + throw new DbCslaException("DROUsage.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + 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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDROUsage"; + // Input All Fields - Except Calculated Columns + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.Update", ex); + throw new DbCslaException("DROUsage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_DROUsageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDROUsage"; + cm.Parameters.AddWithValue("@DROUsageID", criteria.DROUsageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDROUsage"; + // Input PK Fields + cm.Parameters.AddWithValue("@DROUsageID", dROUsageID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.Remove", ex); + throw new DbCslaException("DROUsage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int dROUsageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(dROUsageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DROUsage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DROUsageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int dROUsageID) + { + _DROUsageID = dROUsageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsDROUsage"; + cm.Parameters.AddWithValue("@DROUsageID", _DROUsageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsage.DataPortal_Execute", ex); + throw new DbCslaException("DROUsage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DROUsageExtension _DROUsageExtension = new DROUsageExtension(); + [Serializable()] + partial class DROUsageExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DROUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DROUsage) + { + // Return the ToString value + return ((DROUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs index 86495808..db731e11 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DROUsageInfo.cs @@ -19,445 +19,436 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DROUsageInfoEvent(object sender); - /// - /// DROUsageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DROUsageInfoConverter))] - public partial class DROUsageInfo : ReadOnlyBase, IDisposable - { - public event DROUsageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DROUsageInfo dROUsageInfo) - { - if (!_CacheList.Contains(dROUsageInfo)) _CacheList.Add(dROUsageInfo); // In AddToCache - } - protected static void RemoveFromCache(DROUsageInfo dROUsageInfo) - { - while (_CacheList.Contains(dROUsageInfo)) _CacheList.Remove(dROUsageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DROUsageInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - DROUsageInfo tmp = _CacheList[0]; // Get the first DROUsageInfo - string pKey = tmp.DROUsageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DROUsageInfo - } - } - internal static void AddList(DROUsageInfoList lst) - { - foreach (DROUsageInfo item in lst) AddToCache(item); - } - protected static DROUsageInfo GetCachedByPrimaryKey(int dROUsageID) - { - ConvertListToDictionary(); - string key = dROUsageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DROUsageID", true); - return _DROUsageID; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private DocumentInfo _MyDocument; - public DocumentInfo MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); - return _MyDocument; - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODbInfo _MyRODb; - public RODbInfo MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); - return _MyRODb; - } - } - // CSLATODO: Replace base DROUsageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DROUsageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DROUsageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DROUsageInfo - protected override object GetIdValue() - { - return 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; } } - protected DROUsageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DROUsageInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DROUsageID.ToString())) return; - List listDROUsageInfo = _CacheByPrimaryKey[DROUsageID.ToString()]; // Get the list of items - while (listDROUsageInfo.Contains(this)) listDROUsageInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(DROUsage tmp) - { - string key = tmp.DROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DROUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DROUsage tmp) - { - if (_DocID != tmp.DocID) - { - if (MyDocument != null) 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 - _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 - _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 - _DROUsageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(DocumentDROUsage tmp) - { - string key = tmp.DROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DROUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocumentDROUsage tmp) - { - _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 - _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 - _DROUsageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RODbDROUsage tmp) - { - string key = tmp.DROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DROUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODbDROUsage tmp) - { - if (_DocID != tmp.DocID) - { - if (MyDocument != null) 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 - _ROID = tmp.ROID; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DROUsageInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(dROUsageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DROUsageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DROUsageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DROUsageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfo.Constructor", ex); - throw new DbCslaException("DROUsageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DROUsageID; - public int DROUsageID - { get { return _DROUsageID; } } - public PKCriteria(int dROUsageID) - { - _DROUsageID = dROUsageID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfo.ReadData", GetHashCode()); - try - { - _DROUsageID = dr.GetInt32("DROUsageID"); - _DocID = dr.GetInt32("DocID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _RODbID = dr.GetInt32("RODbID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DROUsageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDROUsage"; - cm.Parameters.AddWithValue("@DROUsageID", criteria.DROUsageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DROUsageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DROUsageInfoExtension _DROUsageInfoExtension = new DROUsageInfoExtension(); - [Serializable()] - partial class DROUsageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DROUsageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DROUsageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DROUsageInfo) - { - // Return the ToString value - return ((DROUsageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DROUsageInfoEvent(object sender); + /// + /// DROUsageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DROUsageInfoConverter))] + public partial class DROUsageInfo : ReadOnlyBase, IDisposable + { + public event DROUsageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DROUsageInfo dROUsageInfo) + { + if (!_CacheList.Contains(dROUsageInfo)) _CacheList.Add(dROUsageInfo); // In AddToCache + } + protected static void RemoveFromCache(DROUsageInfo dROUsageInfo) + { + while (_CacheList.Contains(dROUsageInfo)) _CacheList.Remove(dROUsageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DROUsageInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + DROUsageInfo tmp = _CacheList[0]; // Get the first DROUsageInfo + string pKey = tmp.DROUsageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DROUsageInfo + } + } + internal static void AddList(DROUsageInfoList lst) + { + foreach (DROUsageInfo item in lst) AddToCache(item); + } + protected static DROUsageInfo GetCachedByPrimaryKey(int dROUsageID) + { + ConvertListToDictionary(); + string key = dROUsageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DROUsageID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private DocumentInfo _MyDocument; + public DocumentInfo MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); + return _MyDocument; + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODbInfo _MyRODb; + public RODbInfo MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); + return _MyRODb; + } + } + // CSLATODO: Replace base DROUsageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DROUsageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DROUsageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DROUsageInfo + protected override object GetIdValue() + { + return 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; } } + protected DROUsageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DROUsageInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DROUsageID.ToString())) return; + List listDROUsageInfo = _CacheByPrimaryKey[DROUsageID.ToString()]; // Get the list of items + while (listDROUsageInfo.Contains(this)) listDROUsageInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(DROUsage tmp) + { + string key = tmp.DROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DROUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DROUsage tmp) + { + if (_DocID != tmp.DocID) + { + if (MyDocument != null) 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 + _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 + _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 + _DROUsageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(DocumentDROUsage tmp) + { + string key = tmp.DROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DROUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocumentDROUsage tmp) + { + _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 + _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 + _DROUsageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RODbDROUsage tmp) + { + string key = tmp.DROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DROUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODbDROUsage tmp) + { + if (_DocID != tmp.DocID) + { + if (MyDocument != null) 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 + _ROID = tmp.ROID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DROUsageInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dROUsageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DROUsageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DROUsageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DROUsageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfo.Constructor", ex); + throw new DbCslaException("DROUsageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DROUsageID; + public int DROUsageID + { get { return _DROUsageID; } } + public PKCriteria(int dROUsageID) + { + _DROUsageID = dROUsageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfo.ReadData", GetHashCode()); + try + { + _DROUsageID = dr.GetInt32("DROUsageID"); + _DocID = dr.GetInt32("DocID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _RODbID = dr.GetInt32("RODbID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DROUsageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DROUsageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDROUsage"; + cm.Parameters.AddWithValue("@DROUsageID", criteria.DROUsageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DROUsageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DROUsageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DROUsageInfoExtension _DROUsageInfoExtension = new DROUsageInfoExtension(); + [Serializable()] + partial class DROUsageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DROUsageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DROUsageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DROUsageInfo) + { + // Return the ToString value + return ((DROUsageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs index 19a0410e..dd3bd91b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Detail.cs @@ -20,1067 +20,1053 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Detail Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DetailConverter))] - public partial class Detail : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDetails = new List(); - private void AddToRefreshList(List refreshDetails) - { - if (IsDirty) - refreshDetails.Add(this); - } - private void ClearRefreshList() - { - _RefreshDetails = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshDetails); - } - private void ProcessRefreshList() - { - foreach (Detail tmp in _RefreshDetails) - { - DetailInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Detail detail) - { - if (!_CacheList.Contains(detail)) _CacheList.Add(detail); // In AddToCache - } - protected static void RemoveFromCache(Detail detail) - { - while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Detail(s) from temporary _CacheList to _CacheByPrimaryKey - { - Detail tmp = _CacheList[0]; // Get the first Detail - string pKey = tmp.DetailID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Detail - } - } - protected static Detail GetCachedByPrimaryKey(int detailID) - { - ConvertListToDictionary(); - string key = detailID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextDetailID = -1; - public static int NextDetailID - { - get { return _nextDetailID--; } - } - private int _DetailID; - [System.ComponentModel.DataObjectField(true, true)] - public int DetailID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DetailID", true); - return _DetailID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - _ContentID = value.ContentID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _ItemType; - public int ItemType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemType", true); - return _ItemType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemType", true); - if (_ItemType != value) - { - _ItemType = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); - } - // CSLATODO: Replace base Detail.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Detail - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Detail.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Detail - protected override object GetIdValue() - { - return MyDetailUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Text"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _DetailExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _DetailExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyContentRequired(Detail target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(ItemType, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(ItemType, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _DetailExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 Detail() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Detail() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) - { - List listDetail = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items - while (listDetail.Contains(this)) listDetail.Remove(this); // Remove the item from the list - if (listDetail.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list - } - } - public static Detail New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Detail"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.New", ex); - } - } - public static Detail New(Content myContent, int itemType, string text) - { - Detail tmp = Detail.New(); - tmp.MyContent = myContent; - tmp.ItemType = itemType; - tmp.Text = text; - return tmp; - } - public static Detail New(Content myContent, int itemType, string text, string config, DateTime dts, string userID) - { - Detail tmp = Detail.New(); - tmp.MyContent = myContent; - tmp.ItemType = itemType; - tmp.Text = text; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Detail MakeDetail(Content myContent, int itemType, string text, string config, DateTime dts, string userID) - { - Detail tmp = Detail.New(myContent, itemType, text, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Detail New(Content myContent, int itemType, string text, string config) - { - Detail tmp = Detail.New(); - tmp.MyContent = myContent; - tmp.ItemType = itemType; - tmp.Text = text; - tmp.Config = config; - return tmp; - } - public static Detail MakeDetail(Content myContent, int itemType, string text, string config) - { - Detail tmp = Detail.New(myContent, itemType, text, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(detailID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Detail - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.Get", ex); - } - } - public static Detail Get(SafeDataReader dr) - { - if (dr.Read()) return new Detail(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.Delete", ex); - } - } - 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(); - Detail detail = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(detail);//Refresh the item in AllList - ProcessRefreshList(); - return detail; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DetailID; - public int DetailID - { get { return _DetailID; } } - public PKCriteria(int detailID) - { - _DetailID = detailID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _DetailID = NextDetailID; - // Database Defaults - _DTS = _DetailExtension.DefaultDTS; - _UserID = _DetailExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.ReadData", GetHashCode()); - try - { - _DetailID = dr.GetInt32("DetailID"); - _ContentID = dr.GetInt32("ContentID"); - _ItemType = dr.GetInt32("ItemType"); - _Text = dr.GetString("Text"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Detail.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDetail"; - cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Detail.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Detail.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myContent.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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Add", ex); - throw new DbCslaException("Detail.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - 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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDetail"; - // Input All Fields - Except Calculated Columns - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDetail"; - cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDetail"; - // Input PK Fields - cm.Parameters.AddWithValue("@DetailID", detailID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Remove", ex); - throw new DbCslaException("Detail.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int detailID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(detailID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DetailID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int detailID) - { - _DetailID = detailID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsDetail"; - cm.Parameters.AddWithValue("@DetailID", _DetailID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Execute", ex); - throw new DbCslaException("Detail.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DetailExtension _DetailExtension = new DetailExtension(); - [Serializable()] - partial class DetailExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DetailConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Detail) - { - // Return the ToString value - return ((Detail)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Detail Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DetailConverter))] + public partial class Detail : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDetails = new List(); + private void AddToRefreshList(List refreshDetails) + { + if (IsDirty) + refreshDetails.Add(this); + } + private void ClearRefreshList() + { + _RefreshDetails = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshDetails); + } + private void ProcessRefreshList() + { + foreach (Detail tmp in _RefreshDetails) + { + DetailInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Detail detail) + { + if (!_CacheList.Contains(detail)) _CacheList.Add(detail); // In AddToCache + } + protected static void RemoveFromCache(Detail detail) + { + while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Detail(s) from temporary _CacheList to _CacheByPrimaryKey + { + Detail tmp = _CacheList[0]; // Get the first Detail + string pKey = tmp.DetailID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Detail + } + } + protected static Detail GetCachedByPrimaryKey(int detailID) + { + ConvertListToDictionary(); + string key = detailID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextDetailID = -1; + public static int NextDetailID + { + get { return _nextDetailID--; } + } + private int _DetailID; + [System.ComponentModel.DataObjectField(true, true)] + public int DetailID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DetailID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + _ContentID = value.ContentID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _ItemType; + public int ItemType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemType != value) + { + _ItemType = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); + } + // CSLATODO: Replace base Detail.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Detail + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Detail.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Detail + protected override object GetIdValue() + { + return MyDetailUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Text"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _DetailExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DetailExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyContentRequired(Detail target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(ItemType, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(ItemType, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _DetailExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 Detail() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Detail() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) + { + List listDetail = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items + while (listDetail.Contains(this)) listDetail.Remove(this); // Remove the item from the list + if (listDetail.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list + } + } + public static Detail New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Detail"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.New", ex); + } + } + public static Detail New(Content myContent, int itemType, string text) + { + Detail tmp = Detail.New(); + tmp.MyContent = myContent; + tmp.ItemType = itemType; + tmp.Text = text; + return tmp; + } + public static Detail New(Content myContent, int itemType, string text, string config, DateTime dts, string userID) + { + Detail tmp = Detail.New(); + tmp.MyContent = myContent; + tmp.ItemType = itemType; + tmp.Text = text; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Detail MakeDetail(Content myContent, int itemType, string text, string config, DateTime dts, string userID) + { + Detail tmp = Detail.New(myContent, itemType, text, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Detail New(Content myContent, int itemType, string text, string config) + { + Detail tmp = Detail.New(); + tmp.MyContent = myContent; + tmp.ItemType = itemType; + tmp.Text = text; + tmp.Config = config; + return tmp; + } + public static Detail MakeDetail(Content myContent, int itemType, string text, string config) + { + Detail tmp = Detail.New(myContent, itemType, text, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(detailID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Detail + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.Get", ex); + } + } + public static Detail Get(SafeDataReader dr) + { + if (dr.Read()) return new Detail(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.Delete", ex); + } + } + 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(); + Detail detail = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(detail);//Refresh the item in AllList + ProcessRefreshList(); + return detail; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DetailID; + public int DetailID + { get { return _DetailID; } } + public PKCriteria(int detailID) + { + _DetailID = detailID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _DetailID = NextDetailID; + // Database Defaults + _DTS = _DetailExtension.DefaultDTS; + _UserID = _DetailExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.ReadData", GetHashCode()); + try + { + _DetailID = dr.GetInt32("DetailID"); + _ContentID = dr.GetInt32("ContentID"); + _ItemType = dr.GetInt32("ItemType"); + _Text = dr.GetString("Text"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Detail.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDetail"; + cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Detail.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Detail.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myContent.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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Add", ex); + throw new DbCslaException("Detail.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + 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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDetail"; + // Input All Fields - Except Calculated Columns + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDetail"; + cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDetail"; + // Input PK Fields + cm.Parameters.AddWithValue("@DetailID", detailID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Remove", ex); + throw new DbCslaException("Detail.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int detailID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(detailID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DetailID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int detailID) + { + _DetailID = detailID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsDetail"; + cm.Parameters.AddWithValue("@DetailID", _DetailID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Execute", ex); + throw new DbCslaException("Detail.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DetailExtension _DetailExtension = new DetailExtension(); + [Serializable()] + partial class DetailExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DetailConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Detail) + { + // Return the ToString value + return ((Detail)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs index aa681cbe..a66ab7aa 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DetailInfo.cs @@ -19,397 +19,389 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DetailInfoEvent(object sender); - /// - /// DetailInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DetailInfoConverter))] - public partial class DetailInfo : ReadOnlyBase, IDisposable - { - public event DetailInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DetailInfo detailInfo) - { - if (!_CacheList.Contains(detailInfo)) _CacheList.Add(detailInfo); // In AddToCache - } - protected static void RemoveFromCache(DetailInfo detailInfo) - { - while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DetailInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - DetailInfo tmp = _CacheList[0]; // Get the first DetailInfo - string pKey = tmp.DetailID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DetailInfo - } - } - internal static void AddList(DetailInfoList lst) - { - foreach (DetailInfo item in lst) AddToCache(item); - } - protected static DetailInfo GetCachedByPrimaryKey(int detailID) - { - ConvertListToDictionary(); - string key = detailID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DetailID", true); - return _DetailID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private int _ItemType; - public int ItemType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemType", true); - return _ItemType; - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base DetailInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DetailInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DetailInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DetailInfo - protected override object GetIdValue() - { - return 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; } } - protected DetailInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DetailInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) return; - List listDetailInfo = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items - while (listDetailInfo.Contains(this)) listDetailInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Detail tmp) - { - string key = tmp.DetailID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Detail tmp) - { - if (_ContentID != tmp.ContentID) - { - if (MyContent != null) 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 - _ItemType = tmp.ItemType; - _Text = tmp.Text; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DetailInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ContentDetail tmp) - { - string key = tmp.DetailID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentDetail tmp) - { - _ItemType = tmp.ItemType; - _Text = tmp.Text; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DetailInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(detailID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DetailInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DetailInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DetailInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.Constructor", ex); - throw new DbCslaException("DetailInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DetailID; - public int DetailID - { get { return _DetailID; } } - public PKCriteria(int detailID) - { - _DetailID = detailID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.ReadData", GetHashCode()); - try - { - _DetailID = dr.GetInt32("DetailID"); - _ContentID = dr.GetInt32("ContentID"); - _ItemType = dr.GetInt32("ItemType"); - _Text = dr.GetString("Text"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DetailInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDetail"; - cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DetailInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension(); - [Serializable()] - partial class DetailInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DetailInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DetailInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DetailInfo) - { - // Return the ToString value - return ((DetailInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DetailInfoEvent(object sender); + /// + /// DetailInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DetailInfoConverter))] + public partial class DetailInfo : ReadOnlyBase, IDisposable + { + public event DetailInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DetailInfo detailInfo) + { + if (!_CacheList.Contains(detailInfo)) _CacheList.Add(detailInfo); // In AddToCache + } + protected static void RemoveFromCache(DetailInfo detailInfo) + { + while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DetailInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + DetailInfo tmp = _CacheList[0]; // Get the first DetailInfo + string pKey = tmp.DetailID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DetailInfo + } + } + internal static void AddList(DetailInfoList lst) + { + foreach (DetailInfo item in lst) AddToCache(item); + } + protected static DetailInfo GetCachedByPrimaryKey(int detailID) + { + ConvertListToDictionary(); + string key = detailID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DetailID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private int _ItemType; + public int ItemType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemType; + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base DetailInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DetailInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DetailInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DetailInfo + protected override object GetIdValue() + { + return 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; } } + protected DetailInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DetailInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) return; + List listDetailInfo = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items + while (listDetailInfo.Contains(this)) listDetailInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Detail tmp) + { + string key = tmp.DetailID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Detail tmp) + { + if (_ContentID != tmp.ContentID) + { + if (MyContent != null) 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 + _ItemType = tmp.ItemType; + _Text = tmp.Text; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DetailInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ContentDetail tmp) + { + string key = tmp.DetailID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentDetail tmp) + { + _ItemType = tmp.ItemType; + _Text = tmp.Text; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DetailInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(detailID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DetailInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DetailInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DetailInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.Constructor", ex); + throw new DbCslaException("DetailInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DetailID; + public int DetailID + { get { return _DetailID; } } + public PKCriteria(int detailID) + { + _DetailID = detailID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.ReadData", GetHashCode()); + try + { + _DetailID = dr.GetInt32("DetailID"); + _ContentID = dr.GetInt32("ContentID"); + _ItemType = dr.GetInt32("ItemType"); + _Text = dr.GetString("Text"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DetailInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDetail"; + cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DetailInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension(); + [Serializable()] + partial class DetailInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DetailInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DetailInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DetailInfo) + { + // Return the ToString value + return ((DetailInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs index 9d00f7f5..0b18bb3d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersion.cs @@ -20,1269 +20,1245 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionConverter))] - public partial class DocVersion : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDocVersions = new List(); - private List _RefreshDocVersionAssociations = new List(); - private void AddToRefreshList(List refreshDocVersions, List refreshDocVersionAssociations) - { - if (IsDirty) - refreshDocVersions.Add(this); - if (_DocVersionAssociations != null && _DocVersionAssociations.IsDirty) - { - foreach (DocVersionAssociation tmp in _DocVersionAssociations) - { - if (tmp.IsDirty) refreshDocVersionAssociations.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshDocVersions = new List(); - _RefreshDocVersionAssociations = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshDocVersions, _RefreshDocVersionAssociations); - } - private void ProcessRefreshList() - { - foreach (DocVersion tmp in _RefreshDocVersions) - { - DocVersionInfo.Refresh(tmp); - if (tmp._MyFolder != null) FolderInfo.Refresh(tmp._MyFolder); - if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); - if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); - } - foreach (DocVersionAssociation tmp in _RefreshDocVersionAssociations) - { - AssociationInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocVersion docVersion) - { - if (!_CacheList.Contains(docVersion)) _CacheList.Add(docVersion); // In AddToCache - } - protected static void RemoveFromCache(DocVersion docVersion) - { - while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DocVersion(s) from temporary _CacheList to _CacheByPrimaryKey - { - DocVersion tmp = _CacheList[0]; // Get the first DocVersion - string pKey = tmp.VersionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DocVersion - } - } - protected static DocVersion GetCachedByPrimaryKey(int versionID) - { - ConvertListToDictionary(); - string key = versionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextVersionID = -1; - public static int NextVersionID - { - get { return _nextVersionID--; } - } - private int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - return _VersionID; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - _FolderID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyItem = value; - _ItemID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _DocVersionAssociationCount = 0; - /// - /// Count of DocVersionAssociations for this DocVersion - /// - public int DocVersionAssociationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionAssociationCount", true); - return _DocVersionAssociationCount; - } - } - private DocVersionAssociations _DocVersionAssociations = null; - /// - /// Related Field - /// - [TypeConverter(typeof(DocVersionAssociationsConverter))] - public DocVersionAssociations DocVersionAssociations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionAssociations", true); - if (_DocVersionAssociationCount < 0 || (_DocVersionAssociationCount > 0 && _DocVersionAssociations == null)) - _DocVersionAssociations = DocVersionAssociations.GetByVersionID(VersionID); - if (_DocVersionAssociationCount < 0 ) - _DocVersionAssociationCount = _DocVersionAssociations == null ? 0 : _DocVersionAssociations.Count; - if (_DocVersionAssociations == null) - _DocVersionAssociations = DocVersionAssociations.New(); - return _DocVersionAssociations; - } - } - public void Reset_DocVersionAssociations() - { - _DocVersionAssociationCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : 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)); - } - // CSLATODO: Replace base DocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersion - protected override object GetIdValue() - { - return MyDocVersionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_DocVersionAssociations != null && (hasBrokenRules = _DocVersionAssociations.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _DocVersionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _DocVersionExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyFolderRequired(DocVersion target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _DocVersionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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; } } - 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 DocVersion() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DocVersion() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) - { - List listDocVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items - while (listDocVersion.Contains(this)) listDocVersion.Remove(this); // Remove the item from the list - if (listDocVersion.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list - } - } - public static DocVersion New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocVersion"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.New", ex); - } - } - public static DocVersion New(Folder myFolder, string name) - { - DocVersion tmp = DocVersion.New(); - tmp.MyFolder = myFolder; - tmp.Name = name; - return tmp; - } - public static DocVersion New(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) - { - DocVersion tmp = DocVersion.New(); - tmp.MyFolder = myFolder; - tmp.VersionType = versionType; - tmp.Name = name; - tmp.Title = title; - tmp.MyItem = myItem; - tmp.MyFormat = myFormat; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static DocVersion MakeDocVersion(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) - { - DocVersion tmp = DocVersion.New(myFolder, versionType, name, title, myItem, myFormat, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static DocVersion New(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) - { - DocVersion tmp = DocVersion.New(); - tmp.MyFolder = myFolder; - tmp.Name = name; - tmp.Title = title; - tmp.MyItem = myItem; - tmp.MyFormat = myFormat; - tmp.Config = config; - return tmp; - } - public static DocVersion MakeDocVersion(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) - { - DocVersion tmp = DocVersion.New(myFolder, name, title, myItem, myFormat, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocVersion - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.Get", ex); - } - } - public static DocVersion Get(SafeDataReader dr) - { - if (dr.Read()) return new DocVersion(dr); - return null; - } - internal DocVersion(SafeDataReader dr) - { - ReadData(dr); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.Delete", ex); - } - } - 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(); - DocVersion docVersion = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(docVersion);//Refresh the item in AllList - ProcessRefreshList(); - return docVersion; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _VersionID = NextVersionID; - // Database Defaults - _VersionType = _DocVersionExtension.DefaultVersionType; - _DTS = _DocVersionExtension.DefaultDTS; - _UserID = _DocVersionExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _DocVersionAssociationCount = dr.GetInt32("AssociationCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersion.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _DocVersionAssociations = DocVersionAssociations.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersion.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersion.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.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()) - { - 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; - } - MarkOld(); - // update child objects - if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myFolder.FolderID); - cm.Parameters.AddWithValue("@VersionType", versionType); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - if (myItem != null) cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Add", ex); - throw new DbCslaException("DocVersion.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - 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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - MarkOld(); - } - if (_DocVersionAssociations != null) _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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDocVersion"; - // Input All Fields - Except Calculated Columns - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDocVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDocVersion"; - // Input PK Fields - cm.Parameters.AddWithValue("@VersionID", versionID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Remove", ex); - throw new DbCslaException("DocVersion.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int versionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(versionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _VersionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int versionID) - { - _VersionID = versionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsDocVersion"; - cm.Parameters.AddWithValue("@VersionID", _VersionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Execute", ex); - throw new DbCslaException("DocVersion.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DocVersionExtension _DocVersionExtension = new DocVersionExtension(); - [Serializable()] - partial class DocVersionExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersion) - { - // Return the ToString value - return ((DocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// DocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionConverter))] + public partial class DocVersion : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocVersions = new List(); + private List _RefreshDocVersionAssociations = new List(); + private void AddToRefreshList(List refreshDocVersions, List refreshDocVersionAssociations) + { + if (IsDirty) + refreshDocVersions.Add(this); + if (_DocVersionAssociations != null && _DocVersionAssociations.IsDirty) + { + foreach (DocVersionAssociation tmp in _DocVersionAssociations) + { + if (tmp.IsDirty) refreshDocVersionAssociations.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshDocVersions = new List(); + _RefreshDocVersionAssociations = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshDocVersions, _RefreshDocVersionAssociations); + } + private void ProcessRefreshList() + { + foreach (DocVersion tmp in _RefreshDocVersions) + { + DocVersionInfo.Refresh(tmp); + if (tmp._MyFolder != null) FolderInfo.Refresh(tmp._MyFolder); + if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); + if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); + } + foreach (DocVersionAssociation tmp in _RefreshDocVersionAssociations) + { + AssociationInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocVersion docVersion) + { + if (!_CacheList.Contains(docVersion)) _CacheList.Add(docVersion); // In AddToCache + } + protected static void RemoveFromCache(DocVersion docVersion) + { + while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocVersion(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocVersion tmp = _CacheList[0]; // Get the first DocVersion + string pKey = tmp.VersionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DocVersion + } + } + protected static DocVersion GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextVersionID = -1; + public static int NextVersionID + { + get { return _nextVersionID--; } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionID; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + _FolderID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyItem = value; + _ItemID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _DocVersionAssociationCount = 0; + /// + /// Count of DocVersionAssociations for this DocVersion + /// + public int DocVersionAssociationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersionAssociationCount; + } + } + private DocVersionAssociations _DocVersionAssociations = null; + /// + /// Related Field + /// + [TypeConverter(typeof(DocVersionAssociationsConverter))] + public DocVersionAssociations DocVersionAssociations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocVersionAssociationCount < 0 || (_DocVersionAssociationCount > 0 && _DocVersionAssociations == null)) + _DocVersionAssociations = DocVersionAssociations.GetByVersionID(VersionID); + if (_DocVersionAssociationCount < 0) + _DocVersionAssociationCount = _DocVersionAssociations == null ? 0 : _DocVersionAssociations.Count; + if (_DocVersionAssociations == null) + _DocVersionAssociations = DocVersionAssociations.New(); + return _DocVersionAssociations; + } + } + public void Reset_DocVersionAssociations() + { + _DocVersionAssociationCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : 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)); + } + // CSLATODO: Replace base DocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersion + protected override object GetIdValue() + { + return MyDocVersionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_DocVersionAssociations != null && (hasBrokenRules = _DocVersionAssociations.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocVersionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DocVersionExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyFolderRequired(DocVersion target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _DocVersionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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; } } + 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 DocVersion() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DocVersion() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) + { + List listDocVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listDocVersion.Contains(this)) listDocVersion.Remove(this); // Remove the item from the list + if (listDocVersion.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list + } + } + public static DocVersion New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocVersion"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.New", ex); + } + } + public static DocVersion New(Folder myFolder, string name) + { + DocVersion tmp = DocVersion.New(); + tmp.MyFolder = myFolder; + tmp.Name = name; + return tmp; + } + public static DocVersion New(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) + { + DocVersion tmp = DocVersion.New(); + tmp.MyFolder = myFolder; + tmp.VersionType = versionType; + tmp.Name = name; + tmp.Title = title; + tmp.MyItem = myItem; + tmp.MyFormat = myFormat; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static DocVersion MakeDocVersion(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) + { + DocVersion tmp = DocVersion.New(myFolder, versionType, name, title, myItem, myFormat, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static DocVersion New(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) + { + DocVersion tmp = DocVersion.New(); + tmp.MyFolder = myFolder; + tmp.Name = name; + tmp.Title = title; + tmp.MyItem = myItem; + tmp.MyFormat = myFormat; + tmp.Config = config; + return tmp; + } + public static DocVersion MakeDocVersion(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) + { + DocVersion tmp = DocVersion.New(myFolder, name, title, myItem, myFormat, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersion + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.Get", ex); + } + } + public static DocVersion Get(SafeDataReader dr) + { + if (dr.Read()) return new DocVersion(dr); + return null; + } + internal DocVersion(SafeDataReader dr) + { + ReadData(dr); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.Delete", ex); + } + } + 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(); + DocVersion docVersion = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(docVersion);//Refresh the item in AllList + ProcessRefreshList(); + return docVersion; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _VersionID = NextVersionID; + // Database Defaults + _VersionType = _DocVersionExtension.DefaultVersionType; + _DTS = _DocVersionExtension.DefaultDTS; + _UserID = _DocVersionExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _DocVersionAssociationCount = dr.GetInt32("AssociationCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersion.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _DocVersionAssociations = DocVersionAssociations.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersion.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersion.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.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()) + { + 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; + } + MarkOld(); + // update child objects + if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myFolder.FolderID); + cm.Parameters.AddWithValue("@VersionType", versionType); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + if (myItem != null) cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Add", ex); + throw new DbCslaException("DocVersion.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + 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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_DocVersionAssociations != null) _DocVersionAssociations.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + MarkOld(); + } + if (_DocVersionAssociations != null) _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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDocVersion"; + // Input All Fields - Except Calculated Columns + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDocVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDocVersion"; + // Input PK Fields + cm.Parameters.AddWithValue("@VersionID", versionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Remove", ex); + throw new DbCslaException("DocVersion.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int versionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(versionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _VersionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int versionID) + { + _VersionID = versionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsDocVersion"; + cm.Parameters.AddWithValue("@VersionID", _VersionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Execute", ex); + throw new DbCslaException("DocVersion.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DocVersionExtension _DocVersionExtension = new DocVersionExtension(); + [Serializable()] + partial class DocVersionExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersion) + { + // Return the ToString value + return ((DocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs index ec86d357..2baf6ba5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionAssociation.cs @@ -20,519 +20,503 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocVersionAssociation Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionAssociationConverter))] - public partial class DocVersionAssociation : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _AssociationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AssociationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AssociationID", true); - if (_MyAssociation != null) _AssociationID = _MyAssociation.AssociationID; - return _AssociationID; - } - } - private Association _MyAssociation; - [System.ComponentModel.DataObjectField(true, true)] - public Association MyAssociation - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssociation", true); - if (_MyAssociation == null && _AssociationID != 0) _MyAssociation = Association.Get(_AssociationID); - return _MyAssociation; - } - } - private int _ROFstID; - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyROFst", true); - if (_MyROFst != value) - { - _MyROFst = value; - _ROFstID = value.ROFstID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - 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 - { - CanReadProperty("ROFst_RODbID", true); - return _ROFst_RODbID; - } - } - private byte[] _ROFst_ROLookup; - public byte[] ROFst_ROLookup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_ROLookup", true); - return _ROFst_ROLookup; - } - } - private string _ROFst_Config = string.Empty; - public string ROFst_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_Config", true); - return _ROFst_Config; - } - } - private DateTime _ROFst_DTS = new DateTime(); - public DateTime ROFst_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_DTS", true); - return _ROFst_DTS; - } - } - private string _ROFst_UserID = string.Empty; - public string ROFst_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_UserID", true); - return _ROFst_UserID; - } - } - // CSLATODO: Check DocVersionAssociation.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersionAssociation - protected override object GetIdValue() - { - return MyDocVersionAssociationUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base DocVersionAssociation.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersionAssociation - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyROFstRequired, "MyROFst"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyROFstRequired(DocVersionAssociation target, Csla.Validation.RuleArgs e) - { - if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowWrite(ROFstID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public DocVersionAssociation() - { - MarkAsChild(); - _AssociationID = Association.NextAssociationID; - _DTS = _DocVersionAssociationExtension.DefaultDTS; - _UserID = _DocVersionAssociationExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private DocVersionAssociation(ROFst myROFst) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _AssociationID = Association.NextAssociationID; - _DTS = _DocVersionAssociationExtension.DefaultDTS; - _UserID = _DocVersionAssociationExtension.DefaultUserID; - _MyROFst = myROFst; - ValidationRules.CheckRules(); - } - internal DocVersionAssociation(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~DocVersionAssociation() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionAssociation.FetchDR", GetHashCode()); - try - { - _AssociationID = dr.GetInt32("AssociationID"); - _ROFstID = dr.GetInt32("ROFstID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - 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 - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionAssociation.FetchDR", ex); - throw new DbCslaException("DocVersionAssociation.Fetch", ex); - } - MarkOld(); - } - internal void Insert(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.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); - MarkOld(); - } - 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - DocVersionAssociationExtension _DocVersionAssociationExtension = new DocVersionAssociationExtension(); - [Serializable()] - partial class DocVersionAssociationExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocVersionAssociationConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersionAssociation) - { - // Return the ToString value - return ((DocVersionAssociation)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// DocVersionAssociation Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionAssociationConverter))] + public partial class DocVersionAssociation : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _AssociationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AssociationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssociation != null) _AssociationID = _MyAssociation.AssociationID; + return _AssociationID; + } + } + private Association _MyAssociation; + [System.ComponentModel.DataObjectField(true, true)] + public Association MyAssociation + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssociation == null && _AssociationID != 0) _MyAssociation = Association.Get(_AssociationID); + return _MyAssociation; + } + } + private int _ROFstID; + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyROFst != value) + { + _MyROFst = value; + _ROFstID = value.ROFstID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + 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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_ROLookup; + } + } + private string _ROFst_Config = string.Empty; + public string ROFst_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_Config; + } + } + private DateTime _ROFst_DTS = new DateTime(); + public DateTime ROFst_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_DTS; + } + } + private string _ROFst_UserID = string.Empty; + public string ROFst_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_UserID; + } + } + // CSLATODO: Check DocVersionAssociation.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersionAssociation + protected override object GetIdValue() + { + return MyDocVersionAssociationUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base DocVersionAssociation.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersionAssociation + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyROFstRequired, "MyROFst"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyROFstRequired(DocVersionAssociation target, Csla.Validation.RuleArgs e) + { + if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowWrite(ROFstID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public DocVersionAssociation() + { + MarkAsChild(); + _AssociationID = Association.NextAssociationID; + _DTS = _DocVersionAssociationExtension.DefaultDTS; + _UserID = _DocVersionAssociationExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private DocVersionAssociation(ROFst myROFst) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _AssociationID = Association.NextAssociationID; + _DTS = _DocVersionAssociationExtension.DefaultDTS; + _UserID = _DocVersionAssociationExtension.DefaultUserID; + _MyROFst = myROFst; + ValidationRules.CheckRules(); + } + internal DocVersionAssociation(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~DocVersionAssociation() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionAssociation.FetchDR", GetHashCode()); + try + { + _AssociationID = dr.GetInt32("AssociationID"); + _ROFstID = dr.GetInt32("ROFstID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + 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 + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionAssociation.FetchDR", ex); + throw new DbCslaException("DocVersionAssociation.Fetch", ex); + } + MarkOld(); + } + internal void Insert(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.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); + MarkOld(); + } + 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + DocVersionAssociationExtension _DocVersionAssociationExtension = new DocVersionAssociationExtension(); + [Serializable()] + partial class DocVersionAssociationExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocVersionAssociationConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersionAssociation) + { + // Return the ToString value + return ((DocVersionAssociation)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs index 79fb87f9..aa0bb85b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocVersionInfo.cs @@ -19,592 +19,577 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DocVersionInfoEvent(object sender); - /// - /// DocVersionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionInfoConverter))] - public partial class DocVersionInfo : ReadOnlyBase, IDisposable - { - public event DocVersionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocVersionInfo docVersionInfo) - { - if (!_CacheList.Contains(docVersionInfo)) _CacheList.Add(docVersionInfo); // In AddToCache - } - protected static void RemoveFromCache(DocVersionInfo docVersionInfo) - { - while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DocVersionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - DocVersionInfo tmp = _CacheList[0]; // Get the first DocVersionInfo - string pKey = tmp.VersionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DocVersionInfo - } - } - internal static void AddList(DocVersionInfoList lst) - { - foreach (DocVersionInfo item in lst) AddToCache(item); - } - protected static DocVersionInfo GetCachedByPrimaryKey(int versionID) - { - ConvertListToDictionary(); - string key = versionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - return _VersionID; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private FolderInfo _MyFolder; - public FolderInfo MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); - return _MyFolder; - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private ItemInfo _MyItem; - public ItemInfo MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = ProcedureInfo.Get((int)_ItemID); - return _MyItem; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private FormatInfo _MyFormat; - public FormatInfo MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); - return _MyFormat; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DocVersionAssociationCount = 0; - /// - /// Count of DocVersionAssociations for this DocVersion - /// - public int DocVersionAssociationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionAssociationCount", true); - if (_DocVersionAssociationCount < 0) - _DocVersionAssociationCount = DocVersionAssociations.Count; - return _DocVersionAssociationCount; - } - } - private AssociationInfoList _DocVersionAssociations = null; - [TypeConverter(typeof(AssociationInfoListConverter))] - public AssociationInfoList DocVersionAssociations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionAssociations", true); - if (_DocVersionAssociationCount < 0 || (_DocVersionAssociationCount > 0 && _DocVersionAssociations == null)) - _DocVersionAssociations = AssociationInfoList.GetByVersionID(_VersionID); - if (_DocVersionAssociationCount < 0) - _DocVersionAssociationCount = _DocVersionAssociations.Count; - return _DocVersionAssociations; - } - } - public void RefreshDocVersionAssociations() - { - _DocVersionAssociationCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_VersionID.ToString())) - 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 - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DocVersionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersionInfo - protected override object GetIdValue() - { - return 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; } } - protected DocVersionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DocVersionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; - List listDocVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items - while (listDocVersionInfo.Contains(this)) listDocVersionInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(DocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocVersion tmp) - { - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) 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 - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) 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 - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(FolderDocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FolderDocVersion tmp) - { - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) 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 - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(FormatDocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FormatDocVersion tmp) - { - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) 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 - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ItemDocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemDocVersion tmp) - { - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) 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 - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocVersionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DocVersionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.Constructor", ex); - throw new DbCslaException("DocVersionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DocVersionAssociationCount = dr.GetInt32("AssociationCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension(); - [Serializable()] - partial class DocVersionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DocVersionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DocVersionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersionInfo) - { - // Return the ToString value - return ((DocVersionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DocVersionInfoEvent(object sender); + /// + /// DocVersionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionInfoConverter))] + public partial class DocVersionInfo : ReadOnlyBase, IDisposable + { + public event DocVersionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocVersionInfo docVersionInfo) + { + if (!_CacheList.Contains(docVersionInfo)) _CacheList.Add(docVersionInfo); // In AddToCache + } + protected static void RemoveFromCache(DocVersionInfo docVersionInfo) + { + while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocVersionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocVersionInfo tmp = _CacheList[0]; // Get the first DocVersionInfo + string pKey = tmp.VersionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DocVersionInfo + } + } + internal static void AddList(DocVersionInfoList lst) + { + foreach (DocVersionInfo item in lst) AddToCache(item); + } + protected static DocVersionInfo GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionID; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private FolderInfo _MyFolder; + public FolderInfo MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); + return _MyFolder; + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private ItemInfo _MyItem; + public ItemInfo MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = ProcedureInfo.Get((int)_ItemID); + return _MyItem; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private FormatInfo _MyFormat; + public FormatInfo MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); + return _MyFormat; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DocVersionAssociationCount = 0; + /// + /// Count of DocVersionAssociations for this DocVersion + /// + public int DocVersionAssociationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocVersionAssociationCount < 0) + _DocVersionAssociationCount = DocVersionAssociations.Count; + return _DocVersionAssociationCount; + } + } + private AssociationInfoList _DocVersionAssociations = null; + [TypeConverter(typeof(AssociationInfoListConverter))] + public AssociationInfoList DocVersionAssociations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocVersionAssociationCount < 0 || (_DocVersionAssociationCount > 0 && _DocVersionAssociations == null)) + _DocVersionAssociations = AssociationInfoList.GetByVersionID(_VersionID); + if (_DocVersionAssociationCount < 0) + _DocVersionAssociationCount = _DocVersionAssociations.Count; + return _DocVersionAssociations; + } + } + public void RefreshDocVersionAssociations() + { + _DocVersionAssociationCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_VersionID.ToString())) + 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 + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocVersionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersionInfo + protected override object GetIdValue() + { + return 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; } } + protected DocVersionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DocVersionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; + List listDocVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listDocVersionInfo.Contains(this)) listDocVersionInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(DocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocVersion tmp) + { + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) 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 + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) 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 + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(FolderDocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FolderDocVersion tmp) + { + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) 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 + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(FormatDocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FormatDocVersion tmp) + { + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) 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 + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ItemDocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemDocVersion tmp) + { + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) 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 + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocVersionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.Constructor", ex); + throw new DbCslaException("DocVersionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DocVersionAssociationCount = dr.GetInt32("AssociationCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension(); + [Serializable()] + partial class DocVersionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocVersionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocVersionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersionInfo) + { + // Return the ToString value + return ((DocVersionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs index 12e24870..6ca09e38 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Document.cs @@ -20,1271 +20,1250 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Document Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentConverter))] - public partial class Document : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDocuments = new List(); - private List _RefreshDocumentDROUsages = new List(); - private List _RefreshDocumentEntries = new List(); - private List _RefreshDocumentPdfs = new List(); - private void AddToRefreshList(List refreshDocuments, List refreshDocumentDROUsages, List refreshDocumentEntries, List refreshDocumentPdfs) - { - if (IsDirty) - refreshDocuments.Add(this); - if (_DocumentDROUsages != null && _DocumentDROUsages.IsDirty) - { - foreach (DocumentDROUsage tmp in _DocumentDROUsages) - { - if (tmp.IsDirty) refreshDocumentDROUsages.Add(tmp); - } - } - if (_DocumentEntries != null && _DocumentEntries.IsDirty) - { - foreach (DocumentEntry tmp in _DocumentEntries) - { - if (tmp.IsDirty) refreshDocumentEntries.Add(tmp); - } - } - if (_DocumentPdfs != null && _DocumentPdfs.IsDirty) - { - foreach (DocumentPdf tmp in _DocumentPdfs) - { - if (tmp.IsDirty) refreshDocumentPdfs.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshDocuments = new List(); - _RefreshDocumentDROUsages = new List(); - _RefreshDocumentEntries = new List(); - _RefreshDocumentPdfs = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshDocuments, _RefreshDocumentDROUsages, _RefreshDocumentEntries, _RefreshDocumentPdfs); - } - private void ProcessRefreshList() - { - foreach (Document tmp in _RefreshDocuments) - { - DocumentInfo.Refresh(tmp); - } - foreach (DocumentDROUsage tmp in _RefreshDocumentDROUsages) - { - DROUsageInfo.Refresh(tmp); - } - foreach (DocumentEntry tmp in _RefreshDocumentEntries) - { - EntryInfo.Refresh(tmp); - } - foreach (DocumentPdf tmp in _RefreshDocumentPdfs) - { - PdfInfo.Refresh(this, tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Document document) - { - if (!_CacheList.Contains(document)) _CacheList.Add(document); // In AddToCache - } - protected static void RemoveFromCache(Document document) - { - while (_CacheList.Contains(document)) _CacheList.Remove(document); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Document(s) from temporary _CacheList to _CacheByPrimaryKey - { - Document tmp = _CacheList[0]; // Get the first Document - string pKey = tmp.DocID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Document - } - } - protected static Document GetCachedByPrimaryKey(int docID) - { - ConvertListToDictionary(); - string key = docID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextDocID = -1; - public static int NextDocID - { - get { return _nextDocID--; } - } - private int _DocID; - [System.ComponentModel.DataObjectField(true, true)] - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("LibTitle", true); - if (value == null) value = string.Empty; - if (_LibTitle != value) - { - _LibTitle = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocContent; - /// - /// Actual content of a Word Document (RTF, DOC or XML Format) - /// - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocContent", true); - if (_DocContent != value) - { - _DocContent = value; - PropertyHasChanged(); - } - } - } - private string _DocAscii = string.Empty; - /// - /// Used for searching - /// - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocAscii", true); - if (value == null) value = string.Empty; - if (_DocAscii != value) - { - _DocAscii = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _FileExtension = string.Empty; - public string FileExtension - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileExtension", true); - return _FileExtension; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileExtension", true); - if (value == null) value = string.Empty; - if (_FileExtension != value) - { - _FileExtension = value; - PropertyHasChanged(); - } - } - } - private int _DocumentDROUsageCount = 0; - /// - /// Count of DocumentDROUsages for this Document - /// - public int DocumentDROUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentDROUsageCount", true); - return _DocumentDROUsageCount; - } - } - private DocumentDROUsages _DocumentDROUsages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(DocumentDROUsagesConverter))] - public DocumentDROUsages DocumentDROUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentDROUsages", true); - if (_DocumentDROUsageCount < 0 || (_DocumentDROUsageCount > 0 && _DocumentDROUsages == null)) - _DocumentDROUsages = DocumentDROUsages.GetByDocID(DocID); - if (_DocumentDROUsageCount < 0 ) - _DocumentDROUsageCount = _DocumentDROUsages == null ? 0 : _DocumentDROUsages.Count; - if (_DocumentDROUsages == null) - _DocumentDROUsages = DocumentDROUsages.New(); - return _DocumentDROUsages; - } - } - public void Reset_DocumentDROUsages() - { - _DocumentDROUsageCount = -1; - } - private int _DocumentEntryCount = 0; - /// - /// Count of DocumentEntries for this Document - /// - public int DocumentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntryCount", true); - if (_DocumentEntryCount < 0) - _DocumentEntryCount = DocumentEntries.Count; - return _DocumentEntryCount; - } - } - private DocumentEntries _DocumentEntries = null; - /// - /// Related Field - /// - [TypeConverter(typeof(DocumentEntriesConverter))] - public DocumentEntries DocumentEntries - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntries", true); - if (_DocumentEntryCount < 0 || (_DocumentEntryCount > 0 && _DocumentEntries == null)) - _DocumentEntries = DocumentEntries.GetByDocID(DocID); - if (_DocumentEntryCount < 0 ) - _DocumentEntryCount = _DocumentEntries == null ? 0 : _DocumentEntries.Count; - if (_DocumentEntries == null) - _DocumentEntries = DocumentEntries.New(); - return _DocumentEntries; - } - } - public void Reset_DocumentEntries() - { - _DocumentEntryCount = -1; - } - private int _DocumentPdfCount = 0; - /// - /// Count of DocumentPdfs for this Document - /// - public int DocumentPdfCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentPdfCount", true); - return _DocumentPdfCount; - } - } - private DocumentPdfs _DocumentPdfs = null; - /// - /// Related Field - /// - [TypeConverter(typeof(DocumentPdfsConverter))] - public DocumentPdfs DocumentPdfs - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentPdfs", true); - if (_DocumentPdfCount < 0 || (_DocumentPdfCount > 0 && _DocumentPdfs == null)) - _DocumentPdfs = DocumentPdfs.GetByDocID(DocID); - if (_DocumentPdfCount < 0 ) - _DocumentPdfCount = _DocumentPdfs == null ? 0 : _DocumentPdfs.Count; - if (_DocumentPdfs == null) - _DocumentPdfs = DocumentPdfs.New(); - return _DocumentPdfs; - } - } - public void Reset_DocumentPdfs() - { - _DocumentPdfCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocumentDROUsages == null ? true : _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null ? true : _DocumentEntries.IsValidList(list)) && (_DocumentPdfs == null ? true : _DocumentPdfs.IsValidList(list)); - } - // CSLATODO: Replace base Document.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Document - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Document.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Document - protected override object GetIdValue() - { - return MyDocumentUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_DocumentEntries != null && (hasBrokenRules = _DocumentEntries.HasBrokenRules) != null) return hasBrokenRules; - if (_DocumentDROUsages != null && (hasBrokenRules = _DocumentDROUsages.HasBrokenRules) != null) return hasBrokenRules; - if (_DocumentPdfs != null && (hasBrokenRules = _DocumentPdfs.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 1024)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileExtension"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileExtension", 10)); - //ValidationRules.AddDependantProperty("x", "y"); - _DocumentExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(LibTitle, ""); - //AuthorizationRules.AllowRead(DocContent, ""); - //AuthorizationRules.AllowRead(DocAscii, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(FileExtension, ""); - //AuthorizationRules.AllowWrite(LibTitle, ""); - //AuthorizationRules.AllowWrite(DocContent, ""); - //AuthorizationRules.AllowWrite(DocAscii, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(FileExtension, ""); - _DocumentExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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; } } - 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 Document() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Document() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DocID.ToString())) - { - List listDocument = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items - while (listDocument.Contains(this)) listDocument.Remove(this); // Remove the item from the list - if (listDocument.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list - } - } - public static Document New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Document"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.New", ex); - } - } - public static Document New(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension) - { - Document tmp = Document.New(); - tmp.LibTitle = libTitle; - tmp.DocContent = docContent; - tmp.DocAscii = docAscii; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.FileExtension = fileExtension; - return tmp; - } - public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension) - { - Document tmp = Document.New(libTitle, docContent, docAscii, config, dts, userID, fileExtension); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Document New(string libTitle, byte[] docContent, string docAscii, string config, string extension) - { - Document tmp = Document.New(); - tmp.LibTitle = libTitle; - tmp.DocContent = docContent; - tmp.DocAscii = docAscii; - tmp.Config = config; - tmp.FileExtension = extension; - return tmp; - } - public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, string extension) - { - Document tmp = Document.New(libTitle, docContent, docAscii, config, extension); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(docID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Document - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.Get", ex); - } - } - public static Document Get(SafeDataReader dr) - { - if (dr.Read()) return new Document(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.Delete", ex); - } - } - 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(); - Document document = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(document);//Refresh the item in AllList - ProcessRefreshList(); - return document; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DocID; - public int DocID - { get { return _DocID; } } - public PKCriteria(int docID) - { - _DocID = docID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _DocID = NextDocID; - // Database Defaults - _DTS = _DocumentExtension.DefaultDTS; - _UserID = _DocumentExtension.DefaultUserID; - _FileExtension = _DocumentExtension.DefaultFileExtension; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.ReadData", GetHashCode()); - try - { - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _FileExtension = dr.GetString("FileExtension"); - _DocumentDROUsageCount = dr.GetInt32("DROUsageCount"); - _DocumentEntryCount = dr.GetInt32("EntryCount"); - _DocumentPdfCount = dr.GetInt32("PdfCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Document.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocument"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _DocumentDROUsages = DocumentDROUsages.Get(dr); - // load child objects - dr.NextResult(); - _DocumentEntries = DocumentEntries.Get(dr); - // load child objects - dr.NextResult(); - _DocumentPdfs = DocumentPdfs.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Document.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Document.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_DocumentEntries != null) _DocumentEntries.Update(this); - if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this); - if (_DocumentPdfs != null) _DocumentPdfs.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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); - 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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Add", ex); - throw new DbCslaException("Document.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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); - 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; - } - } - 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - MarkOld(); - } - if (_DocumentEntries != null) _DocumentEntries.Update(this); - if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this); - if (_DocumentPdfs != null) _DocumentPdfs.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, ref byte[] lastChanged, string fileExtension) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDocument"; - // 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("@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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Update", ex); - throw new DbCslaException("Document.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_DocID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDocument"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDocument"; - // Input PK Fields - cm.Parameters.AddWithValue("@DocID", docID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Remove", ex); - throw new DbCslaException("Document.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int docID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(docID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DocID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int docID) - { - _DocID = docID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsDocument"; - cm.Parameters.AddWithValue("@DocID", _DocID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Execute", ex); - throw new DbCslaException("Document.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DocumentExtension _DocumentExtension = new DocumentExtension(); - [Serializable()] - partial class DocumentExtension : extensionBase - { - } - [Serializable()] - 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"; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Document) - { - // Return the ToString value - return ((Document)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Document Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentConverter))] + public partial class Document : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocuments = new List(); + private List _RefreshDocumentDROUsages = new List(); + private List _RefreshDocumentEntries = new List(); + private List _RefreshDocumentPdfs = new List(); + private void AddToRefreshList(List refreshDocuments, List refreshDocumentDROUsages, List refreshDocumentEntries, List refreshDocumentPdfs) + { + if (IsDirty) + refreshDocuments.Add(this); + if (_DocumentDROUsages != null && _DocumentDROUsages.IsDirty) + { + foreach (DocumentDROUsage tmp in _DocumentDROUsages) + { + if (tmp.IsDirty) refreshDocumentDROUsages.Add(tmp); + } + } + if (_DocumentEntries != null && _DocumentEntries.IsDirty) + { + foreach (DocumentEntry tmp in _DocumentEntries) + { + if (tmp.IsDirty) refreshDocumentEntries.Add(tmp); + } + } + if (_DocumentPdfs != null && _DocumentPdfs.IsDirty) + { + foreach (DocumentPdf tmp in _DocumentPdfs) + { + if (tmp.IsDirty) refreshDocumentPdfs.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshDocuments = new List(); + _RefreshDocumentDROUsages = new List(); + _RefreshDocumentEntries = new List(); + _RefreshDocumentPdfs = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshDocuments, _RefreshDocumentDROUsages, _RefreshDocumentEntries, _RefreshDocumentPdfs); + } + private void ProcessRefreshList() + { + foreach (Document tmp in _RefreshDocuments) + { + DocumentInfo.Refresh(tmp); + } + foreach (DocumentDROUsage tmp in _RefreshDocumentDROUsages) + { + DROUsageInfo.Refresh(tmp); + } + foreach (DocumentEntry tmp in _RefreshDocumentEntries) + { + EntryInfo.Refresh(tmp); + } + foreach (DocumentPdf tmp in _RefreshDocumentPdfs) + { + PdfInfo.Refresh(this, tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Document document) + { + if (!_CacheList.Contains(document)) _CacheList.Add(document); // In AddToCache + } + protected static void RemoveFromCache(Document document) + { + while (_CacheList.Contains(document)) _CacheList.Remove(document); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Document(s) from temporary _CacheList to _CacheByPrimaryKey + { + Document tmp = _CacheList[0]; // Get the first Document + string pKey = tmp.DocID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Document + } + } + protected static Document GetCachedByPrimaryKey(int docID) + { + ConvertListToDictionary(); + string key = docID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextDocID = -1; + public static int NextDocID + { + get { return _nextDocID--; } + } + private int _DocID; + [System.ComponentModel.DataObjectField(true, true)] + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_LibTitle != value) + { + _LibTitle = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocContent; + /// + /// Actual content of a Word Document (RTF, DOC or XML Format) + /// + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocContent != value) + { + _DocContent = value; + PropertyHasChanged(); + } + } + } + private string _DocAscii = string.Empty; + /// + /// Used for searching + /// + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_DocAscii != value) + { + _DocAscii = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileExtension; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileExtension != value) + { + _FileExtension = value; + PropertyHasChanged(); + } + } + } + private int _DocumentDROUsageCount = 0; + /// + /// Count of DocumentDROUsages for this Document + /// + public int DocumentDROUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocumentDROUsageCount; + } + } + private DocumentDROUsages _DocumentDROUsages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(DocumentDROUsagesConverter))] + public DocumentDROUsages DocumentDROUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentDROUsageCount < 0 || (_DocumentDROUsageCount > 0 && _DocumentDROUsages == null)) + _DocumentDROUsages = DocumentDROUsages.GetByDocID(DocID); + if (_DocumentDROUsageCount < 0) + _DocumentDROUsageCount = _DocumentDROUsages == null ? 0 : _DocumentDROUsages.Count; + if (_DocumentDROUsages == null) + _DocumentDROUsages = DocumentDROUsages.New(); + return _DocumentDROUsages; + } + } + public void Reset_DocumentDROUsages() + { + _DocumentDROUsageCount = -1; + } + private int _DocumentEntryCount = 0; + /// + /// Count of DocumentEntries for this Document + /// + public int DocumentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentEntryCount < 0) + _DocumentEntryCount = DocumentEntries.Count; + return _DocumentEntryCount; + } + } + private DocumentEntries _DocumentEntries = null; + /// + /// Related Field + /// + [TypeConverter(typeof(DocumentEntriesConverter))] + public DocumentEntries DocumentEntries + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentEntryCount < 0 || (_DocumentEntryCount > 0 && _DocumentEntries == null)) + _DocumentEntries = DocumentEntries.GetByDocID(DocID); + if (_DocumentEntryCount < 0) + _DocumentEntryCount = _DocumentEntries == null ? 0 : _DocumentEntries.Count; + if (_DocumentEntries == null) + _DocumentEntries = DocumentEntries.New(); + return _DocumentEntries; + } + } + public void Reset_DocumentEntries() + { + _DocumentEntryCount = -1; + } + private int _DocumentPdfCount = 0; + /// + /// Count of DocumentPdfs for this Document + /// + public int DocumentPdfCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocumentPdfCount; + } + } + private DocumentPdfs _DocumentPdfs = null; + /// + /// Related Field + /// + [TypeConverter(typeof(DocumentPdfsConverter))] + public DocumentPdfs DocumentPdfs + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentPdfCount < 0 || (_DocumentPdfCount > 0 && _DocumentPdfs == null)) + _DocumentPdfs = DocumentPdfs.GetByDocID(DocID); + if (_DocumentPdfCount < 0) + _DocumentPdfCount = _DocumentPdfs == null ? 0 : _DocumentPdfs.Count; + if (_DocumentPdfs == null) + _DocumentPdfs = DocumentPdfs.New(); + return _DocumentPdfs; + } + } + public void Reset_DocumentPdfs() + { + _DocumentPdfCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_DocumentDROUsages == null ? true : _DocumentDROUsages.IsValidList(list)) && (_DocumentEntries == null ? true : _DocumentEntries.IsValidList(list)) && (_DocumentPdfs == null ? true : _DocumentPdfs.IsValidList(list)); + } + // CSLATODO: Replace base Document.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Document + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Document.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Document + protected override object GetIdValue() + { + return MyDocumentUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_DocumentEntries != null && (hasBrokenRules = _DocumentEntries.HasBrokenRules) != null) return hasBrokenRules; + if (_DocumentDROUsages != null && (hasBrokenRules = _DocumentDROUsages.HasBrokenRules) != null) return hasBrokenRules; + if (_DocumentPdfs != null && (hasBrokenRules = _DocumentPdfs.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 1024)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileExtension"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileExtension", 10)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocumentExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(LibTitle, ""); + //AuthorizationRules.AllowRead(DocContent, ""); + //AuthorizationRules.AllowRead(DocAscii, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(FileExtension, ""); + //AuthorizationRules.AllowWrite(LibTitle, ""); + //AuthorizationRules.AllowWrite(DocContent, ""); + //AuthorizationRules.AllowWrite(DocAscii, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(FileExtension, ""); + _DocumentExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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; } } + 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 Document() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Document() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DocID.ToString())) + { + List listDocument = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items + while (listDocument.Contains(this)) listDocument.Remove(this); // Remove the item from the list + if (listDocument.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list + } + } + public static Document New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Document"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.New", ex); + } + } + public static Document New(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension) + { + Document tmp = Document.New(); + tmp.LibTitle = libTitle; + tmp.DocContent = docContent; + tmp.DocAscii = docAscii; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.FileExtension = fileExtension; + return tmp; + } + public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension) + { + Document tmp = Document.New(libTitle, docContent, docAscii, config, dts, userID, fileExtension); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Document New(string libTitle, byte[] docContent, string docAscii, string config, string extension) + { + Document tmp = Document.New(); + tmp.LibTitle = libTitle; + tmp.DocContent = docContent; + tmp.DocAscii = docAscii; + tmp.Config = config; + tmp.FileExtension = extension; + return tmp; + } + public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, string extension) + { + Document tmp = Document.New(libTitle, docContent, docAscii, config, extension); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Document + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.Get", ex); + } + } + public static Document Get(SafeDataReader dr) + { + if (dr.Read()) return new Document(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.Delete", ex); + } + } + 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(); + Document document = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(document);//Refresh the item in AllList + ProcessRefreshList(); + return document; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DocID; + public int DocID + { get { return _DocID; } } + public PKCriteria(int docID) + { + _DocID = docID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _DocID = NextDocID; + // Database Defaults + _DTS = _DocumentExtension.DefaultDTS; + _UserID = _DocumentExtension.DefaultUserID; + _FileExtension = _DocumentExtension.DefaultFileExtension; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.ReadData", GetHashCode()); + try + { + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _FileExtension = dr.GetString("FileExtension"); + _DocumentDROUsageCount = dr.GetInt32("DROUsageCount"); + _DocumentEntryCount = dr.GetInt32("EntryCount"); + _DocumentPdfCount = dr.GetInt32("PdfCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Document.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocument"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _DocumentDROUsages = DocumentDROUsages.Get(dr); + // load child objects + dr.NextResult(); + _DocumentEntries = DocumentEntries.Get(dr); + // load child objects + dr.NextResult(); + _DocumentPdfs = DocumentPdfs.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Document.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Document.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_DocumentEntries != null) _DocumentEntries.Update(this); + if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this); + if (_DocumentPdfs != null) _DocumentPdfs.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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); + 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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Add", ex); + throw new DbCslaException("Document.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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); + 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; + } + } + 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + MarkOld(); + } + if (_DocumentEntries != null) _DocumentEntries.Update(this); + if (_DocumentDROUsages != null) _DocumentDROUsages.Update(this); + if (_DocumentPdfs != null) _DocumentPdfs.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, ref byte[] lastChanged, string fileExtension) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDocument"; + // 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("@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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Update", ex); + throw new DbCslaException("Document.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_DocID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDocument"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDocument"; + // Input PK Fields + cm.Parameters.AddWithValue("@DocID", docID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Remove", ex); + throw new DbCslaException("Document.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int docID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(docID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DocID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int docID) + { + _DocID = docID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsDocument"; + cm.Parameters.AddWithValue("@DocID", _DocID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Execute", ex); + throw new DbCslaException("Document.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DocumentExtension _DocumentExtension = new DocumentExtension(); + [Serializable()] + partial class DocumentExtension : extensionBase + { + } + [Serializable()] + 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"; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Document) + { + // Return the ToString value + return ((Document)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs index f212fb30..7f1fdaf5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAudit.cs @@ -20,1045 +20,1024 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocumentAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentAuditConverter))] - public partial class DocumentAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDocumentAudits = new List(); - private void AddToRefreshList(List refreshDocumentAudits) - { - if (IsDirty) - refreshDocumentAudits.Add(this); - } - private void ClearRefreshList() - { - _RefreshDocumentAudits = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshDocumentAudits); - } - private void ProcessRefreshList() - { - foreach (DocumentAudit tmp in _RefreshDocumentAudits) - { - DocumentAuditInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocumentAudit documentAudit) - { - if (!_CacheList.Contains(documentAudit)) _CacheList.Add(documentAudit); // In AddToCache - } - protected static void RemoveFromCache(DocumentAudit documentAudit) - { - while (_CacheList.Contains(documentAudit)) _CacheList.Remove(documentAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DocumentAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - DocumentAudit tmp = _CacheList[0]; // Get the first DocumentAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DocumentAudit - } - } - protected static DocumentAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocID", true); - if (_DocID != value) - { - _DocID = value; - PropertyHasChanged(); - } - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("LibTitle", true); - if (value == null) value = string.Empty; - if (_LibTitle != value) - { - _LibTitle = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocContent; - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocContent", true); - if (_DocContent != value) - { - _DocContent = value; - PropertyHasChanged(); - } - } - } - private string _DocAscii = string.Empty; - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocAscii", true); - if (value == null) value = string.Empty; - if (_DocAscii != value) - { - _DocAscii = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private string _FileExtension = string.Empty; - public string FileExtension - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileExtension", true); - return _FileExtension; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileExtension", true); - if (value == null) value = string.Empty; - if (_FileExtension != value) - { - _FileExtension = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocPdf; - public byte[] DocPdf - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocPdf", true); - return _DocPdf; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocPdf", true); - if (_DocPdf != value) - { - _DocPdf = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base DocumentAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DocumentAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentAudit - protected override object GetIdValue() - { - return MyDocumentAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 2048)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileExtension"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileExtension", 20)); - //ValidationRules.AddDependantProperty("x", "y"); - _DocumentAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(LibTitle, ""); - //AuthorizationRules.AllowRead(DocContent, ""); - //AuthorizationRules.AllowRead(DocAscii, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(FileExtension, ""); - //AuthorizationRules.AllowRead(DocPdf, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(LibTitle, ""); - //AuthorizationRules.AllowWrite(DocContent, ""); - //AuthorizationRules.AllowWrite(DocAscii, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(FileExtension, ""); - //AuthorizationRules.AllowWrite(DocPdf, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _DocumentAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 DocumentAudit() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DocumentAudit() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listDocumentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listDocumentAudit.Contains(this)) listDocumentAudit.Remove(this); // Remove the item from the list - if (listDocumentAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static DocumentAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAudit.New", ex); - } - } - public static DocumentAudit New(int docID, DateTime dts, string userID, string fileExtension, int deleteStatus) - { - DocumentAudit tmp = DocumentAudit.New(); - tmp.DocID = docID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.FileExtension = fileExtension; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static DocumentAudit New(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) - { - DocumentAudit tmp = DocumentAudit.New(); - tmp.DocID = docID; - tmp.LibTitle = libTitle; - tmp.DocContent = docContent; - tmp.DocAscii = docAscii; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.FileExtension = fileExtension; - tmp.DocPdf = docPdf; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static DocumentAudit MakeDocumentAudit(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) - { - DocumentAudit tmp = DocumentAudit.New(docID, libTitle, docContent, docAscii, config, dts, userID, fileExtension, docPdf, deleteStatus); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocumentAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAudit.Get", ex); - } - } - public static DocumentAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new DocumentAudit(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAudit.Delete", ex); - } - } - 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(); - DocumentAudit documentAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(documentAudit);//Refresh the item in AllList - ProcessRefreshList(); - return documentAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// DocumentAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentAuditConverter))] + public partial class DocumentAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocumentAudits = new List(); + private void AddToRefreshList(List refreshDocumentAudits) + { + if (IsDirty) + refreshDocumentAudits.Add(this); + } + private void ClearRefreshList() + { + _RefreshDocumentAudits = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshDocumentAudits); + } + private void ProcessRefreshList() + { + foreach (DocumentAudit tmp in _RefreshDocumentAudits) + { + DocumentAuditInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocumentAudit documentAudit) + { + if (!_CacheList.Contains(documentAudit)) _CacheList.Add(documentAudit); // In AddToCache + } + protected static void RemoveFromCache(DocumentAudit documentAudit) + { + while (_CacheList.Contains(documentAudit)) _CacheList.Remove(documentAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocumentAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocumentAudit tmp = _CacheList[0]; // Get the first DocumentAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DocumentAudit + } + } + protected static DocumentAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocID != value) + { + _DocID = value; + PropertyHasChanged(); + } + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_LibTitle != value) + { + _LibTitle = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocContent; + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocContent != value) + { + _DocContent = value; + PropertyHasChanged(); + } + } + } + private string _DocAscii = string.Empty; + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_DocAscii != value) + { + _DocAscii = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileExtension; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileExtension != value) + { + _FileExtension = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocPdf; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocPdf != value) + { + _DocPdf = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base DocumentAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocumentAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentAudit + protected override object GetIdValue() + { + return MyDocumentAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 2048)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileExtension"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileExtension", 20)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocumentAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(LibTitle, ""); + //AuthorizationRules.AllowRead(DocContent, ""); + //AuthorizationRules.AllowRead(DocAscii, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(FileExtension, ""); + //AuthorizationRules.AllowRead(DocPdf, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(LibTitle, ""); + //AuthorizationRules.AllowWrite(DocContent, ""); + //AuthorizationRules.AllowWrite(DocAscii, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(FileExtension, ""); + //AuthorizationRules.AllowWrite(DocPdf, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _DocumentAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 DocumentAudit() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DocumentAudit() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listDocumentAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listDocumentAudit.Contains(this)) listDocumentAudit.Remove(this); // Remove the item from the list + if (listDocumentAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static DocumentAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocumentAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.New", ex); + } + } + public static DocumentAudit New(int docID, DateTime dts, string userID, string fileExtension, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(); + tmp.DocID = docID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.FileExtension = fileExtension; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static DocumentAudit New(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(); + tmp.DocID = docID; + tmp.LibTitle = libTitle; + tmp.DocContent = docContent; + tmp.DocAscii = docAscii; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.FileExtension = fileExtension; + tmp.DocPdf = docPdf; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static DocumentAudit MakeDocumentAudit(int docID, string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID, string fileExtension, byte[] docPdf, int deleteStatus) + { + DocumentAudit tmp = DocumentAudit.New(docID, libTitle, docContent, docAscii, config, dts, userID, fileExtension, docPdf, deleteStatus); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.Get", ex); + } + } + public static DocumentAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new DocumentAudit(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAudit.Delete", ex); + } + } + 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(); + DocumentAudit documentAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(documentAudit);//Refresh the item in AllList + ProcessRefreshList(); + return documentAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _FileExtension = dr.GetString("FileExtension"); - _DocPdf = (byte[])dr.GetValue("DocPdf"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocumentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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); - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Add", ex); - throw new DbCslaException("DocumentAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateDocumentAudit"; - // Input All Fields - Except Calculated Columns - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Update", ex); - throw new DbCslaException("DocumentAudit.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}] DocumentAudit.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDocumentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteDocumentAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Remove", ex); - throw new DbCslaException("DocumentAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension(); - [Serializable()] - partial class DocumentAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentAudit) - { - // Return the ToString value - return ((DocumentAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FileExtension = dr.GetString("FileExtension"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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); + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Add", ex); + throw new DbCslaException("DocumentAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateDocumentAudit"; + // Input All Fields - Except Calculated Columns + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Update", ex); + throw new DbCslaException("DocumentAudit.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}] DocumentAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteDocumentAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAudit.Remove", ex); + throw new DbCslaException("DocumentAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + DocumentAuditExtension _DocumentAuditExtension = new DocumentAuditExtension(); + [Serializable()] + partial class DocumentAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentAudit) + { + // Return the ToString value + return ((DocumentAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs index bb2d64b8..a288f552 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentAuditInfo.cs @@ -19,397 +19,387 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DocumentAuditInfoEvent(object sender); - /// - /// DocumentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentAuditInfoConverter))] - public partial class DocumentAuditInfo : ReadOnlyBase, IDisposable - { - public event DocumentAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocumentAuditInfo documentAuditInfo) - { - if (!_CacheList.Contains(documentAuditInfo)) _CacheList.Add(documentAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(DocumentAuditInfo documentAuditInfo) - { - while (_CacheList.Contains(documentAuditInfo)) _CacheList.Remove(documentAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DocumentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - DocumentAuditInfo tmp = _CacheList[0]; // Get the first DocumentAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DocumentAuditInfo - } - } - internal static void AddList(DocumentAuditInfoList lst) - { - foreach (DocumentAuditInfo item in lst) AddToCache(item); - } - protected static DocumentAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - } - private byte[] _DocContent; - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - } - private string _DocAscii = string.Empty; - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private string _FileExtension = string.Empty; - public string FileExtension - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileExtension", true); - return _FileExtension; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base DocumentAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DocumentAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentAuditInfo - protected override object GetIdValue() - { - return 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; } } - protected DocumentAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DocumentAuditInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listDocumentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listDocumentAuditInfo.Contains(this)) listDocumentAuditInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(DocumentAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocumentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocumentAudit tmp) - { - _DocID = tmp.DocID; - _LibTitle = tmp.LibTitle; - _DocContent = tmp.DocContent; - _DocAscii = tmp.DocAscii; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FileExtension = tmp.FileExtension; - _DeleteStatus = tmp.DeleteStatus; - _DocumentAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocumentAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DocumentAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.Constructor", ex); - throw new DbCslaException("DocumentAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _FileExtension = dr.GetString("FileExtension"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocumentAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension(); - [Serializable()] - partial class DocumentAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DocumentAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DocumentAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentAuditInfo) - { - // Return the ToString value - return ((DocumentAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DocumentAuditInfoEvent(object sender); + /// + /// DocumentAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentAuditInfoConverter))] + public partial class DocumentAuditInfo : ReadOnlyBase, IDisposable + { + public event DocumentAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocumentAuditInfo documentAuditInfo) + { + if (!_CacheList.Contains(documentAuditInfo)) _CacheList.Add(documentAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(DocumentAuditInfo documentAuditInfo) + { + while (_CacheList.Contains(documentAuditInfo)) _CacheList.Remove(documentAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocumentAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocumentAuditInfo tmp = _CacheList[0]; // Get the first DocumentAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DocumentAuditInfo + } + } + internal static void AddList(DocumentAuditInfoList lst) + { + foreach (DocumentAuditInfo item in lst) AddToCache(item); + } + protected static DocumentAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + } + private byte[] _DocContent; + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + } + private string _DocAscii = string.Empty; + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileExtension; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base DocumentAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocumentAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentAuditInfo + protected override object GetIdValue() + { + return 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; } } + protected DocumentAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DocumentAuditInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listDocumentAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listDocumentAuditInfo.Contains(this)) listDocumentAuditInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(DocumentAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocumentAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocumentAudit tmp) + { + _DocID = tmp.DocID; + _LibTitle = tmp.LibTitle; + _DocContent = tmp.DocContent; + _DocAscii = tmp.DocAscii; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FileExtension = tmp.FileExtension; + _DeleteStatus = tmp.DeleteStatus; + _DocumentAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocumentAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.Constructor", ex); + throw new DbCslaException("DocumentAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FileExtension = dr.GetString("FileExtension"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocumentAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocumentAuditInfoExtension _DocumentAuditInfoExtension = new DocumentAuditInfoExtension(); + [Serializable()] + partial class DocumentAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocumentAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocumentAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentAuditInfo) + { + // Return the ToString value + return ((DocumentAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs index e2ba3a55..b3c396de 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentDROUsage.cs @@ -20,570 +20,551 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocumentDROUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentDROUsageConverter))] - public partial class DocumentDROUsage : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _DROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int DROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DROUsageID", true); - if (_MyDROUsage != null) _DROUsageID = _MyDROUsage.DROUsageID; - return _DROUsageID; - } - } - private DROUsage _MyDROUsage; - [System.ComponentModel.DataObjectField(true, true)] - public DROUsage MyDROUsage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDROUsage", true); - if (_MyDROUsage == null && _DROUsageID != 0) _MyDROUsage = DROUsage.Get(_DROUsageID); - return _MyDROUsage; - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - _RODbID = value.RODbID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _RODb_ROName = string.Empty; - /// - /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion - /// - public string RODb_ROName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_ROName", true); - return _RODb_ROName; - } - } - private string _RODb_FolderPath = string.Empty; - /// - /// Path to the RO database - /// - public string RODb_FolderPath - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_FolderPath", true); - return _RODb_FolderPath; - } - } - private string _RODb_DBConnectionString = string.Empty; - /// - /// Connection String - Default could just be the full path and name of the database - /// - public string RODb_DBConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_DBConnectionString", true); - return _RODb_DBConnectionString; - } - } - private string _RODb_Config = string.Empty; - public string RODb_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_Config", true); - return _RODb_Config; - } - } - private DateTime _RODb_DTS = new DateTime(); - public DateTime RODb_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_DTS", true); - return _RODb_DTS; - } - } - private string _RODb_UserID = string.Empty; - public string RODb_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_UserID", true); - return _RODb_UserID; - } - } - // CSLATODO: Check DocumentDROUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentDROUsage - protected override object GetIdValue() - { - return MyDocumentDROUsageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base DocumentDROUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentDROUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - // CSLATODO: Add other validation rules - } - private static bool MyRODbRequired(DocumentDROUsage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - } - 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; } } - 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); - } - public DocumentDROUsage() - { - MarkAsChild(); - _DROUsageID = DROUsage.NextDROUsageID; - _DTS = _DocumentDROUsageExtension.DefaultDTS; - _UserID = _DocumentDROUsageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private DocumentDROUsage(string roid, RODb myRODb) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _DROUsageID = DROUsage.NextDROUsageID; - _DTS = _DocumentDROUsageExtension.DefaultDTS; - _UserID = _DocumentDROUsageExtension.DefaultUserID; - _ROID = roid; - _MyRODb = myRODb; - ValidationRules.CheckRules(); - } - internal DocumentDROUsage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~DocumentDROUsage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentDROUsage.FetchDR", GetHashCode()); - try - { - _DROUsageID = dr.GetInt32("DROUsageID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbID = dr.GetInt32("RODbID"); - _RODb_ROName = dr.GetString("RODb_ROName"); - _RODb_FolderPath = dr.GetString("RODb_FolderPath"); - _RODb_DBConnectionString = dr.GetString("RODb_DBConnectionString"); - _RODb_Config = dr.GetString("RODb_Config"); - _RODb_DTS = dr.GetDateTime("RODb_DTS"); - _RODb_UserID = dr.GetString("RODb_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentDROUsage.FetchDR", ex); - throw new DbCslaException("DocumentDROUsage.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - internal void DeleteSelf(Document myDocument) - { - // 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"]; - DROUsage.Remove(cn, _DROUsageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - DocumentDROUsageExtension _DocumentDROUsageExtension = new DocumentDROUsageExtension(); - [Serializable()] - partial class DocumentDROUsageExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentDROUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentDROUsage) - { - // Return the ToString value - return ((DocumentDROUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// DocumentDROUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentDROUsageConverter))] + public partial class DocumentDROUsage : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _DROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int DROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDROUsage != null) _DROUsageID = _MyDROUsage.DROUsageID; + return _DROUsageID; + } + } + private DROUsage _MyDROUsage; + [System.ComponentModel.DataObjectField(true, true)] + public DROUsage MyDROUsage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDROUsage == null && _DROUsageID != 0) _MyDROUsage = DROUsage.Get(_DROUsageID); + return _MyDROUsage; + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + _RODbID = value.RODbID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _RODb_ROName = string.Empty; + /// + /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion + /// + public string RODb_ROName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_ROName; + } + } + private string _RODb_FolderPath = string.Empty; + /// + /// Path to the RO database + /// + public string RODb_FolderPath + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_FolderPath; + } + } + private string _RODb_DBConnectionString = string.Empty; + /// + /// Connection String - Default could just be the full path and name of the database + /// + public string RODb_DBConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_DBConnectionString; + } + } + private string _RODb_Config = string.Empty; + public string RODb_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_Config; + } + } + private DateTime _RODb_DTS = new DateTime(); + public DateTime RODb_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_DTS; + } + } + private string _RODb_UserID = string.Empty; + public string RODb_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_UserID; + } + } + // CSLATODO: Check DocumentDROUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentDROUsage + protected override object GetIdValue() + { + return MyDocumentDROUsageUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base DocumentDROUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentDROUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + // CSLATODO: Add other validation rules + } + private static bool MyRODbRequired(DocumentDROUsage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + } + 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; } } + 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); + } + public DocumentDROUsage() + { + MarkAsChild(); + _DROUsageID = DROUsage.NextDROUsageID; + _DTS = _DocumentDROUsageExtension.DefaultDTS; + _UserID = _DocumentDROUsageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private DocumentDROUsage(string roid, RODb myRODb) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _DROUsageID = DROUsage.NextDROUsageID; + _DTS = _DocumentDROUsageExtension.DefaultDTS; + _UserID = _DocumentDROUsageExtension.DefaultUserID; + _ROID = roid; + _MyRODb = myRODb; + ValidationRules.CheckRules(); + } + internal DocumentDROUsage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~DocumentDROUsage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentDROUsage.FetchDR", GetHashCode()); + try + { + _DROUsageID = dr.GetInt32("DROUsageID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbID = dr.GetInt32("RODbID"); + _RODb_ROName = dr.GetString("RODb_ROName"); + _RODb_FolderPath = dr.GetString("RODb_FolderPath"); + _RODb_DBConnectionString = dr.GetString("RODb_DBConnectionString"); + _RODb_Config = dr.GetString("RODb_Config"); + _RODb_DTS = dr.GetDateTime("RODb_DTS"); + _RODb_UserID = dr.GetString("RODb_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentDROUsage.FetchDR", ex); + throw new DbCslaException("DocumentDROUsage.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + internal void DeleteSelf(Document myDocument) + { + // 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"]; + DROUsage.Remove(cn, _DROUsageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + DocumentDROUsageExtension _DocumentDROUsageExtension = new DocumentDROUsageExtension(); + [Serializable()] + partial class DocumentDROUsageExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentDROUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentDROUsage) + { + // Return the ToString value + return ((DocumentDROUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs index 19787070..310f0ffe 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentEntry.cs @@ -20,458 +20,445 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocumentEntry Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentEntryConverter))] - public partial class DocumentEntry : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyEntry != null) _ContentID = _MyEntry.ContentID; - return _ContentID; - } - } - private Entry _MyEntry; - [System.ComponentModel.DataObjectField(true, true)] - public Entry MyEntry - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyEntry", true); - if (_MyEntry == null && _ContentID != 0) _MyEntry = Entry.Get(_ContentID); - return _MyEntry; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // CSLATODO: Check DocumentEntry.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentEntry - protected override object GetIdValue() - { - return MyDocumentEntryUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base DocumentEntry.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentEntry - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public DocumentEntry() - { - MarkAsChild(); + /// + /// DocumentEntry Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentEntryConverter))] + public partial class DocumentEntry : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyEntry != null) _ContentID = _MyEntry.ContentID; + return _ContentID; + } + } + private Entry _MyEntry; + [System.ComponentModel.DataObjectField(true, true)] + public Entry MyEntry + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyEntry == null && _ContentID != 0) _MyEntry = Entry.Get(_ContentID); + return _MyEntry; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // CSLATODO: Check DocumentEntry.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentEntry + protected override object GetIdValue() + { + return MyDocumentEntryUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base DocumentEntry.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentEntry + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public DocumentEntry() + { + MarkAsChild(); - _DTS = _DocumentEntryExtension.DefaultDTS; - _UserID = _DocumentEntryExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private DocumentEntry(Entry myEntry) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _DTS = _DocumentEntryExtension.DefaultDTS; - _UserID = _DocumentEntryExtension.DefaultUserID; - _MyEntry = myEntry; - ValidationRules.CheckRules(); - } - internal DocumentEntry(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~DocumentEntry() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentEntry.FetchDR", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentEntry.FetchDR", ex); - throw new DbCslaException("DocumentEntry.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - internal void DeleteSelf(Document myDocument) - { - // 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"]; - Entry.Remove(cn, _ContentID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension(); - [Serializable()] - partial class DocumentEntryExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentEntryConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentEntry) - { - // Return the ToString value - return ((DocumentEntry)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _DocumentEntryExtension.DefaultDTS; + _UserID = _DocumentEntryExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private DocumentEntry(Entry myEntry) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _DTS = _DocumentEntryExtension.DefaultDTS; + _UserID = _DocumentEntryExtension.DefaultUserID; + _MyEntry = myEntry; + ValidationRules.CheckRules(); + } + internal DocumentEntry(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~DocumentEntry() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentEntry.FetchDR", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentEntry.FetchDR", ex); + throw new DbCslaException("DocumentEntry.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + internal void DeleteSelf(Document myDocument) + { + // 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"]; + Entry.Remove(cn, _ContentID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension(); + [Serializable()] + partial class DocumentEntryExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentEntryConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentEntry) + { + // Return the ToString value + return ((DocumentEntry)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs index 8beb8a58..073948a0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentInfo.cs @@ -19,496 +19,482 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DocumentInfoEvent(object sender); - /// - /// DocumentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentInfoConverter))] - public partial class DocumentInfo : ReadOnlyBase, IDisposable - { - public event DocumentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocumentInfo documentInfo) - { - if (!_CacheList.Contains(documentInfo)) _CacheList.Add(documentInfo); // In AddToCache - } - protected static void RemoveFromCache(DocumentInfo documentInfo) - { - while (_CacheList.Contains(documentInfo)) _CacheList.Remove(documentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move DocumentInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - DocumentInfo tmp = _CacheList[0]; // Get the first DocumentInfo - string pKey = tmp.DocID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first DocumentInfo - } - } - internal static void AddList(DocumentInfoList lst) - { - foreach (DocumentInfo item in lst) AddToCache(item); - } - protected static DocumentInfo GetCachedByPrimaryKey(int docID) - { - ConvertListToDictionary(); - string key = docID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - } - private byte[] _DocContent; - /// - /// Actual content of a Word Document (RTF, DOC or XML Format) - /// - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - } - private string _DocAscii = string.Empty; - /// - /// Used for searching - /// - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private string _FileExtension = string.Empty; - public string FileExtension - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileExtension", true); - return _FileExtension; - } - } - private int _DocumentDROUsageCount = 0; - /// - /// Count of DocumentDROUsages for this Document - /// - public int DocumentDROUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentDROUsageCount", true); - if (_DocumentDROUsageCount < 0) - _DocumentDROUsageCount = DocumentDROUsages.Count; - return _DocumentDROUsageCount; - } - } - private DROUsageInfoList _DocumentDROUsages = null; - [TypeConverter(typeof(DROUsageInfoListConverter))] - public DROUsageInfoList DocumentDROUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentDROUsages", true); - if (_DocumentDROUsageCount < 0 || (_DocumentDROUsageCount > 0 && _DocumentDROUsages == null)) - _DocumentDROUsages = DROUsageInfoList.GetByDocID(_DocID); - if (_DocumentDROUsageCount < 0) - _DocumentDROUsageCount = _DocumentDROUsages.Count; - return _DocumentDROUsages; - } - } - public void RefreshDocumentDROUsages() - { - _DocumentDROUsageCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) - foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) - tmp._DocumentDROUsageCount = -1; // This will cause the data to be requeried - } - private int _DocumentEntryCount = 0; - /// - /// Count of DocumentEntries for this Document - /// - public int DocumentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntryCount", true); - if (_DocumentEntryCount < 0) - _DocumentEntryCount = DocumentEntries.Count; - return _DocumentEntryCount; - } - } - private EntryInfoList _DocumentEntries = null; - [TypeConverter(typeof(EntryInfoListConverter))] - public EntryInfoList DocumentEntries - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntries", true); - if (_DocumentEntryCount < 0 || (_DocumentEntryCount > 0 && _DocumentEntries == null)) - _DocumentEntries = EntryInfoList.GetByDocID(_DocID); - if (_DocumentEntryCount < 0) - _DocumentEntryCount = _DocumentEntries.Count; - return _DocumentEntries; - } - } - public void RefreshDocumentEntries() - { - _DocumentEntryCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) - foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) - tmp._DocumentEntryCount = -1; // This will cause the data to be requeried - } - private int _DocumentPdfCount = 0; - /// - /// Count of DocumentPdfs for this Document - /// - public int DocumentPdfCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentPdfCount", true); - if (_DocumentPdfCount < 0) - _DocumentPdfCount = DocumentPdfs.Count; - return _DocumentPdfCount; - } - } - private PdfInfoList _DocumentPdfs = null; - [TypeConverter(typeof(PdfInfoListConverter))] - public PdfInfoList DocumentPdfs - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentPdfs", true); - if (_DocumentPdfCount < 0 || (_DocumentPdfCount > 0 && _DocumentPdfs == null)) - _DocumentPdfs = PdfInfoList.GetByDocID(_DocID); - if (_DocumentPdfCount < 0) - _DocumentPdfCount = _DocumentPdfs.Count; - return _DocumentPdfs; - } - } - public void RefreshDocumentPdfs() - { - _DocumentPdfCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) - foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) - tmp._DocumentPdfCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base DocumentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check DocumentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentInfo - protected override object GetIdValue() - { - return 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; } } - protected DocumentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~DocumentInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString())) return; - List listDocumentInfo = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items - while (listDocumentInfo.Contains(this)) listDocumentInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Document tmp) - { - string key = tmp.DocID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocumentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Document tmp) - { - _LibTitle = tmp.LibTitle; - _DocContent = tmp.DocContent; - _DocAscii = tmp.DocAscii; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FileExtension = tmp.FileExtension; - _DocumentInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(docID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocumentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DocumentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.Constructor", ex); - throw new DbCslaException("DocumentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DocID; - public int DocID - { get { return _DocID; } } - public PKCriteria(int docID) - { - _DocID = docID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.ReadData", GetHashCode()); - try - { - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _FileExtension = dr.GetString("FileExtension"); - _DocumentDROUsageCount = dr.GetInt32("DROUsageCount"); - _DocumentEntryCount = dr.GetInt32("EntryCount"); - _DocumentPdfCount = dr.GetInt32("PdfCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocument"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension(); - [Serializable()] - partial class DocumentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DocumentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DocumentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentInfo) - { - // Return the ToString value - return ((DocumentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DocumentInfoEvent(object sender); + /// + /// DocumentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentInfoConverter))] + public partial class DocumentInfo : ReadOnlyBase, IDisposable + { + public event DocumentInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocumentInfo documentInfo) + { + if (!_CacheList.Contains(documentInfo)) _CacheList.Add(documentInfo); // In AddToCache + } + protected static void RemoveFromCache(DocumentInfo documentInfo) + { + while (_CacheList.Contains(documentInfo)) _CacheList.Remove(documentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move DocumentInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + DocumentInfo tmp = _CacheList[0]; // Get the first DocumentInfo + string pKey = tmp.DocID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first DocumentInfo + } + } + internal static void AddList(DocumentInfoList lst) + { + foreach (DocumentInfo item in lst) AddToCache(item); + } + protected static DocumentInfo GetCachedByPrimaryKey(int docID) + { + ConvertListToDictionary(); + string key = docID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + } + private byte[] _DocContent; + /// + /// Actual content of a Word Document (RTF, DOC or XML Format) + /// + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + } + private string _DocAscii = string.Empty; + /// + /// Used for searching + /// + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private string _FileExtension = string.Empty; + public string FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileExtension; + } + } + private int _DocumentDROUsageCount = 0; + /// + /// Count of DocumentDROUsages for this Document + /// + public int DocumentDROUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentDROUsageCount < 0) + _DocumentDROUsageCount = DocumentDROUsages.Count; + return _DocumentDROUsageCount; + } + } + private DROUsageInfoList _DocumentDROUsages = null; + [TypeConverter(typeof(DROUsageInfoListConverter))] + public DROUsageInfoList DocumentDROUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentDROUsageCount < 0 || (_DocumentDROUsageCount > 0 && _DocumentDROUsages == null)) + _DocumentDROUsages = DROUsageInfoList.GetByDocID(_DocID); + if (_DocumentDROUsageCount < 0) + _DocumentDROUsageCount = _DocumentDROUsages.Count; + return _DocumentDROUsages; + } + } + public void RefreshDocumentDROUsages() + { + _DocumentDROUsageCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) + foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) + tmp._DocumentDROUsageCount = -1; // This will cause the data to be requeried + } + private int _DocumentEntryCount = 0; + /// + /// Count of DocumentEntries for this Document + /// + public int DocumentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentEntryCount < 0) + _DocumentEntryCount = DocumentEntries.Count; + return _DocumentEntryCount; + } + } + private EntryInfoList _DocumentEntries = null; + [TypeConverter(typeof(EntryInfoListConverter))] + public EntryInfoList DocumentEntries + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentEntryCount < 0 || (_DocumentEntryCount > 0 && _DocumentEntries == null)) + _DocumentEntries = EntryInfoList.GetByDocID(_DocID); + if (_DocumentEntryCount < 0) + _DocumentEntryCount = _DocumentEntries.Count; + return _DocumentEntries; + } + } + public void RefreshDocumentEntries() + { + _DocumentEntryCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) + foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) + tmp._DocumentEntryCount = -1; // This will cause the data to be requeried + } + private int _DocumentPdfCount = 0; + /// + /// Count of DocumentPdfs for this Document + /// + public int DocumentPdfCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentPdfCount < 0) + _DocumentPdfCount = DocumentPdfs.Count; + return _DocumentPdfCount; + } + } + private PdfInfoList _DocumentPdfs = null; + [TypeConverter(typeof(PdfInfoListConverter))] + public PdfInfoList DocumentPdfs + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentPdfCount < 0 || (_DocumentPdfCount > 0 && _DocumentPdfs == null)) + _DocumentPdfs = PdfInfoList.GetByDocID(_DocID); + if (_DocumentPdfCount < 0) + _DocumentPdfCount = _DocumentPdfs.Count; + return _DocumentPdfs; + } + } + public void RefreshDocumentPdfs() + { + _DocumentPdfCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) + foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) + tmp._DocumentPdfCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base DocumentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check DocumentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentInfo + protected override object GetIdValue() + { + return 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; } } + protected DocumentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~DocumentInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString())) return; + List listDocumentInfo = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items + while (listDocumentInfo.Contains(this)) listDocumentInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Document tmp) + { + string key = tmp.DocID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocumentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Document tmp) + { + _LibTitle = tmp.LibTitle; + _DocContent = tmp.DocContent; + _DocAscii = tmp.DocAscii; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FileExtension = tmp.FileExtension; + _DocumentInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocumentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.Constructor", ex); + throw new DbCslaException("DocumentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DocID; + public int DocID + { get { return _DocID; } } + public PKCriteria(int docID) + { + _DocID = docID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.ReadData", GetHashCode()); + try + { + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FileExtension = dr.GetString("FileExtension"); + _DocumentDROUsageCount = dr.GetInt32("DROUsageCount"); + _DocumentEntryCount = dr.GetInt32("EntryCount"); + _DocumentPdfCount = dr.GetInt32("PdfCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocument"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension(); + [Serializable()] + partial class DocumentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocumentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocumentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentInfo) + { + // Return the ToString value + return ((DocumentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs index a4e84f28..dbfedc0e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/DocumentPdf.cs @@ -20,471 +20,458 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocumentPdf Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentPdfConverter))] - public partial class DocumentPdf : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _DebugStatus; - /// - /// > 0 for Debug - /// - [System.ComponentModel.DataObjectField(true, true)] - public int DebugStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DebugStatus", true); - return _DebugStatus; - } - } - private int _TopRow; - [System.ComponentModel.DataObjectField(true, true)] - public int TopRow - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TopRow", true); - return _TopRow; - } - } - private int _PageLength; - [System.ComponentModel.DataObjectField(true, true)] - public int PageLength - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageLength", true); - return _PageLength; - } - } - private int _LeftMargin; - [System.ComponentModel.DataObjectField(true, true)] - public int LeftMargin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LeftMargin", true); - return _LeftMargin; - } - } - private int _PageWidth; - [System.ComponentModel.DataObjectField(true, true)] - public int PageWidth - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageWidth", true); - return _PageWidth; - } - } - private double _PageCount; - /// - /// Count of whole and partial pages - /// - public double PageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageCount", true); - return _PageCount; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PageCount", true); - if (_PageCount != value) - { - _PageCount = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocPdf; - public byte[] DocPdf - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocPdf", true); - return _DocPdf; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocPdf", true); - if (_DocPdf != value) - { - _DocPdf = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check DocumentPdf.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentPdf - protected override object GetIdValue() - { - return MyDocumentPdfUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base DocumentPdf.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentPdf - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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, ""); - //AuthorizationRules.AllowRead(TopRow, ""); - //AuthorizationRules.AllowRead(PageLength, ""); - //AuthorizationRules.AllowRead(LeftMargin, ""); - //AuthorizationRules.AllowRead(PageWidth, ""); - //AuthorizationRules.AllowRead(PageCount, ""); - //AuthorizationRules.AllowWrite(PageCount, ""); - //AuthorizationRules.AllowRead(DocPdf, ""); - //AuthorizationRules.AllowWrite(DocPdf, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public DocumentPdf() - { - MarkAsChild(); + /// + /// DocumentPdf Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentPdfConverter))] + public partial class DocumentPdf : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _DebugStatus; + /// + /// > 0 for Debug + /// + [System.ComponentModel.DataObjectField(true, true)] + public int DebugStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DebugStatus; + } + } + private int _TopRow; + [System.ComponentModel.DataObjectField(true, true)] + public int TopRow + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TopRow; + } + } + private int _PageLength; + [System.ComponentModel.DataObjectField(true, true)] + public int PageLength + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageLength; + } + } + private int _LeftMargin; + [System.ComponentModel.DataObjectField(true, true)] + public int LeftMargin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LeftMargin; + } + } + private int _PageWidth; + [System.ComponentModel.DataObjectField(true, true)] + public int PageWidth + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageWidth; + } + } + private double _PageCount; + /// + /// Count of whole and partial pages + /// + public double PageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageCount; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PageCount != value) + { + _PageCount = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocPdf; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocPdf != value) + { + _DocPdf = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check DocumentPdf.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentPdf + protected override object GetIdValue() + { + return MyDocumentPdfUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base DocumentPdf.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentPdf + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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, ""); + //AuthorizationRules.AllowRead(TopRow, ""); + //AuthorizationRules.AllowRead(PageLength, ""); + //AuthorizationRules.AllowRead(LeftMargin, ""); + //AuthorizationRules.AllowRead(PageWidth, ""); + //AuthorizationRules.AllowRead(PageCount, ""); + //AuthorizationRules.AllowWrite(PageCount, ""); + //AuthorizationRules.AllowRead(DocPdf, ""); + //AuthorizationRules.AllowWrite(DocPdf, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public DocumentPdf() + { + MarkAsChild(); - _DTS = _DocumentPdfExtension.DefaultDTS; - _UserID = _DocumentPdfExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private DocumentPdf(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _DTS = _DocumentPdfExtension.DefaultDTS; - _UserID = _DocumentPdfExtension.DefaultUserID; - _DebugStatus = debugStatus; - _TopRow = topRow; - _PageLength = pageLength; - _LeftMargin = leftMargin; - _PageWidth = pageWidth; - _PageCount = pageCount; - ValidationRules.CheckRules(); - } - internal DocumentPdf(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~DocumentPdf() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentPdf.FetchDR", GetHashCode()); - try - { - _DebugStatus = dr.GetInt32("DebugStatus"); - _TopRow = dr.GetInt32("TopRow"); - _PageLength = dr.GetInt32("PageLength"); - _LeftMargin = dr.GetInt32("LeftMargin"); - _PageWidth = dr.GetInt32("PageWidth"); - _PageCount = dr.GetDouble("PageCount"); - _DocPdf = (byte[])dr.GetValue("DocPdf"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentPdf.FetchDR", ex); - throw new DbCslaException("DocumentPdf.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - internal void DeleteSelf(Document myDocument) - { - // 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"]; - Pdf.Remove(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - DocumentPdfExtension _DocumentPdfExtension = new DocumentPdfExtension(); - [Serializable()] - partial class DocumentPdfExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentPdfConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentPdf) - { - // Return the ToString value - return ((DocumentPdf)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _DocumentPdfExtension.DefaultDTS; + _UserID = _DocumentPdfExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private DocumentPdf(int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _DTS = _DocumentPdfExtension.DefaultDTS; + _UserID = _DocumentPdfExtension.DefaultUserID; + _DebugStatus = debugStatus; + _TopRow = topRow; + _PageLength = pageLength; + _LeftMargin = leftMargin; + _PageWidth = pageWidth; + _PageCount = pageCount; + ValidationRules.CheckRules(); + } + internal DocumentPdf(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~DocumentPdf() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentPdf.FetchDR", GetHashCode()); + try + { + _DebugStatus = dr.GetInt32("DebugStatus"); + _TopRow = dr.GetInt32("TopRow"); + _PageLength = dr.GetInt32("PageLength"); + _LeftMargin = dr.GetInt32("LeftMargin"); + _PageWidth = dr.GetInt32("PageWidth"); + _PageCount = dr.GetDouble("PageCount"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentPdf.FetchDR", ex); + throw new DbCslaException("DocumentPdf.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + internal void DeleteSelf(Document myDocument) + { + // 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"]; + Pdf.Remove(cn, myDocument.DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + DocumentPdfExtension _DocumentPdfExtension = new DocumentPdfExtension(); + [Serializable()] + partial class DocumentPdfExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentPdfConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentPdf) + { + // Return the ToString value + return ((DocumentPdf)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs index 56b1133a..952061b9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Entry.cs @@ -20,982 +20,973 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Entry Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(EntryConverter))] - public partial class Entry : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshEntries = new List(); - private void AddToRefreshList(List refreshEntries) - { - if (IsDirty) - refreshEntries.Add(this); - } - private void ClearRefreshList() - { - _RefreshEntries = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshEntries); - } - private void ProcessRefreshList() - { - foreach (Entry tmp in _RefreshEntries) - { - EntryInfo.Refresh(tmp); - if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Entry entry) - { - if (!_CacheList.Contains(entry)) _CacheList.Add(entry); // In AddToCache - } - protected static void RemoveFromCache(Entry entry) - { - while (_CacheList.Contains(entry)) _CacheList.Remove(entry); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Entry(s) from temporary _CacheList to _CacheByPrimaryKey - { - Entry tmp = _CacheList[0]; // Get the first Entry - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Entry - } - } - protected static Entry GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private Document _MyDocument; - public Document MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); - return _MyDocument; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyDocument", true); - if (_MyDocument != value) - { - _MyDocument = value; - _DocID = value.DocID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)); - } - // CSLATODO: Replace base Entry.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Entry - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Entry.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Entry - protected override object GetIdValue() - { - return MyEntryUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _EntryExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _EntryExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyDocumentRequired(Entry target, Csla.Validation.RuleArgs e) - { - if (target._DocID == 0 && target._MyDocument == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _EntryExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 Entry() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Entry() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listEntry = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listEntry.Contains(this)) listEntry.Remove(this); // Remove the item from the list - if (listEntry.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static Entry New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Entry"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.New", ex); - } - } - public static Entry New(Content myContent, Document myDocument) - { - Entry tmp = Entry.New(); - tmp._MyContent = myContent; - tmp.MyDocument = myDocument; - return tmp; - } - public static Entry MakeEntry(Content myContent, Document myDocument) - { - Entry tmp = Entry.New(myContent, myDocument); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Entry New(Content myContent, Document myDocument, DateTime dts, string userID) - { - Entry tmp = Entry.New(); - tmp._MyContent = myContent; - tmp.MyDocument = myDocument; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Entry MakeEntry(Content myContent, Document myDocument, DateTime dts, string userID) - { - Entry tmp = Entry.New(myContent, myDocument, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Entry New(Content myContent) - { - Entry tmp = Entry.New(); - tmp._MyContent = myContent; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Entry - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.Get", ex); - } - } - public static Entry Get(SafeDataReader dr) - { - if (dr.Read()) return new Entry(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.Delete", ex); - } - } - 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(); - Entry entry = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(entry);//Refresh the item in AllList - ProcessRefreshList(); - return entry; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// Entry Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryConverter))] + public partial class Entry : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshEntries = new List(); + private void AddToRefreshList(List refreshEntries) + { + if (IsDirty) + refreshEntries.Add(this); + } + private void ClearRefreshList() + { + _RefreshEntries = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshEntries); + } + private void ProcessRefreshList() + { + foreach (Entry tmp in _RefreshEntries) + { + EntryInfo.Refresh(tmp); + if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Entry entry) + { + if (!_CacheList.Contains(entry)) _CacheList.Add(entry); // In AddToCache + } + protected static void RemoveFromCache(Entry entry) + { + while (_CacheList.Contains(entry)) _CacheList.Remove(entry); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Entry(s) from temporary _CacheList to _CacheByPrimaryKey + { + Entry tmp = _CacheList[0]; // Get the first Entry + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Entry + } + } + protected static Entry GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private Document _MyDocument; + public Document MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); + return _MyDocument; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyDocument != value) + { + _MyDocument = value; + _DocID = value.DocID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)); + } + // CSLATODO: Replace base Entry.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Entry + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Entry.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Entry + protected override object GetIdValue() + { + return MyEntryUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _EntryExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _EntryExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyDocumentRequired(Entry target, Csla.Validation.RuleArgs e) + { + if (target._DocID == 0 && target._MyDocument == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _EntryExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 Entry() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Entry() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listEntry = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listEntry.Contains(this)) listEntry.Remove(this); // Remove the item from the list + if (listEntry.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static Entry New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Entry"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.New", ex); + } + } + public static Entry New(Content myContent, Document myDocument) + { + Entry tmp = Entry.New(); + tmp._MyContent = myContent; + tmp.MyDocument = myDocument; + return tmp; + } + public static Entry MakeEntry(Content myContent, Document myDocument) + { + Entry tmp = Entry.New(myContent, myDocument); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Entry New(Content myContent, Document myDocument, DateTime dts, string userID) + { + Entry tmp = Entry.New(); + tmp._MyContent = myContent; + tmp.MyDocument = myDocument; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Entry MakeEntry(Content myContent, Document myDocument, DateTime dts, string userID) + { + Entry tmp = Entry.New(myContent, myDocument, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Entry New(Content myContent) + { + Entry tmp = Entry.New(); + tmp._MyContent = myContent; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Entry + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.Get", ex); + } + } + public static Entry Get(SafeDataReader dr) + { + if (dr.Read()) return new Entry(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.Delete", ex); + } + } + 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(); + Entry entry = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(entry);//Refresh the item in AllList + ProcessRefreshList(); + return entry; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _EntryExtension.DefaultDTS; - _UserID = _EntryExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _DocID = dr.GetInt32("DocID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Entry.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getEntry"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Entry.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Entry.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyDocument != null) _MyDocument.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myContent.ContentID); - cm.Parameters.AddWithValue("@DocID", myDocument.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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Add", ex); - throw new DbCslaException("Entry.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - 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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Content content) - { - if (!this.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); - 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 - // after original checkin) - if (_MyDocument != null) - { - _MyDocument.Update(); - _MyDocument.Reset_DocumentEntries(); - } - } - } - [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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateEntry"; - // 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("@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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Update", ex); - throw new DbCslaException("Entry.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}] Entry.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteEntry"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteEntry"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Remove", ex); - throw new DbCslaException("Entry.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsEntry"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Execute", ex); - throw new DbCslaException("Entry.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - EntryExtension _EntryExtension = new EntryExtension(); - [Serializable()] - partial class EntryExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class EntryConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Entry) - { - // Return the ToString value - return ((Entry)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _EntryExtension.DefaultDTS; + _UserID = _EntryExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Entry.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntry"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Entry.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Entry.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyDocument != null) _MyDocument.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myContent.ContentID); + cm.Parameters.AddWithValue("@DocID", myDocument.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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Add", ex); + throw new DbCslaException("Entry.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + 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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Content content) + { + if (!this.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); + 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 + // after original checkin) + if (_MyDocument != null) + { + _MyDocument.Update(); + _MyDocument.Reset_DocumentEntries(); + } + } + } + [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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateEntry"; + // 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("@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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Update", ex); + throw new DbCslaException("Entry.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}] Entry.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteEntry"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteEntry"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Remove", ex); + throw new DbCslaException("Entry.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsEntry"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Execute", ex); + throw new DbCslaException("Entry.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + EntryExtension _EntryExtension = new EntryExtension(); + [Serializable()] + partial class EntryExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class EntryConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Entry) + { + // Return the ToString value + return ((Entry)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs index 6480058e..1355ef3f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAudit.cs @@ -20,877 +20,866 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// EntryAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(EntryAuditConverter))] - public partial class EntryAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshEntryAudits = new List(); - private void AddToRefreshList(List refreshEntryAudits) - { - if (IsDirty) - refreshEntryAudits.Add(this); - } - private void ClearRefreshList() - { - _RefreshEntryAudits = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshEntryAudits); - } - private void ProcessRefreshList() - { - foreach (EntryAudit tmp in _RefreshEntryAudits) - { - EntryAuditInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(EntryAudit entryAudit) - { - if (!_CacheList.Contains(entryAudit)) _CacheList.Add(entryAudit); // In AddToCache - } - protected static void RemoveFromCache(EntryAudit entryAudit) - { - while (_CacheList.Contains(entryAudit)) _CacheList.Remove(entryAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move EntryAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - EntryAudit tmp = _CacheList[0]; // Get the first EntryAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first EntryAudit - } - } - protected static EntryAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocID", true); - if (_DocID != value) - { - _DocID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base EntryAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current EntryAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check EntryAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current EntryAudit - protected override object GetIdValue() - { - return MyEntryAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _EntryAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _EntryAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 EntryAudit() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~EntryAudit() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listEntryAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listEntryAudit.Contains(this)) listEntryAudit.Remove(this); // Remove the item from the list - if (listEntryAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static EntryAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a EntryAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryAudit.New", ex); - } - } - public static EntryAudit New(int contentID, int docID, DateTime dts, string userID, int deleteStatus) - { - EntryAudit tmp = EntryAudit.New(); - tmp.ContentID = contentID; - tmp.DocID = docID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static EntryAudit MakeEntryAudit(int contentID, int docID, DateTime dts, string userID, int deleteStatus) - { - EntryAudit tmp = EntryAudit.New(contentID, docID, dts, userID, deleteStatus); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up EntryAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryAudit.Get", ex); - } - } - public static EntryAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new EntryAudit(dr); - return null; - } - internal EntryAudit(SafeDataReader dr) - { - ReadData(dr); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryAudit.Delete", ex); - } - } - 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(); - EntryAudit entryAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(entryAudit);//Refresh the item in AllList - ProcessRefreshList(); - return entryAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// EntryAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryAuditConverter))] + public partial class EntryAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshEntryAudits = new List(); + private void AddToRefreshList(List refreshEntryAudits) + { + if (IsDirty) + refreshEntryAudits.Add(this); + } + private void ClearRefreshList() + { + _RefreshEntryAudits = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshEntryAudits); + } + private void ProcessRefreshList() + { + foreach (EntryAudit tmp in _RefreshEntryAudits) + { + EntryAuditInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(EntryAudit entryAudit) + { + if (!_CacheList.Contains(entryAudit)) _CacheList.Add(entryAudit); // In AddToCache + } + protected static void RemoveFromCache(EntryAudit entryAudit) + { + while (_CacheList.Contains(entryAudit)) _CacheList.Remove(entryAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move EntryAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + EntryAudit tmp = _CacheList[0]; // Get the first EntryAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first EntryAudit + } + } + protected static EntryAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocID != value) + { + _DocID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base EntryAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current EntryAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check EntryAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current EntryAudit + protected override object GetIdValue() + { + return MyEntryAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _EntryAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _EntryAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 EntryAudit() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~EntryAudit() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listEntryAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listEntryAudit.Contains(this)) listEntryAudit.Remove(this); // Remove the item from the list + if (listEntryAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static EntryAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a EntryAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.New", ex); + } + } + public static EntryAudit New(int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + EntryAudit tmp = EntryAudit.New(); + tmp.ContentID = contentID; + tmp.DocID = docID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static EntryAudit MakeEntryAudit(int contentID, int docID, DateTime dts, string userID, int deleteStatus) + { + EntryAudit tmp = EntryAudit.New(contentID, docID, dts, userID, deleteStatus); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up EntryAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.Get", ex); + } + } + public static EntryAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new EntryAudit(dr); + return null; + } + internal EntryAudit(SafeDataReader dr) + { + ReadData(dr); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAudit.Delete", ex); + } + } + 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(); + EntryAudit entryAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(entryAudit);//Refresh the item in AllList + ProcessRefreshList(); + return entryAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _DocID = dr.GetInt32("DocID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getEntryAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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); - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Add", ex); - throw new DbCslaException("EntryAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateEntryAudit"; - // Input All Fields - Except Calculated Columns - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteEntryAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteEntryAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Remove", ex); - throw new DbCslaException("EntryAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension(); - [Serializable()] - partial class EntryAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class EntryAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is EntryAudit) - { - // Return the ToString value - return ((EntryAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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); + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Add", ex); + throw new DbCslaException("EntryAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateEntryAudit"; + // Input All Fields - Except Calculated Columns + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteEntryAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAudit.Remove", ex); + throw new DbCslaException("EntryAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + EntryAuditExtension _EntryAuditExtension = new EntryAuditExtension(); + [Serializable()] + partial class EntryAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class EntryAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryAudit) + { + // Return the ToString value + return ((EntryAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfo.cs index d49eefc3..ca468c06 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryAuditInfo.cs @@ -19,349 +19,343 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void EntryAuditInfoEvent(object sender); - /// - /// EntryAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(EntryAuditInfoConverter))] - public partial class EntryAuditInfo : ReadOnlyBase, IDisposable - { - public event EntryAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(EntryAuditInfo entryAuditInfo) - { - if (!_CacheList.Contains(entryAuditInfo)) _CacheList.Add(entryAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(EntryAuditInfo entryAuditInfo) - { - while (_CacheList.Contains(entryAuditInfo)) _CacheList.Remove(entryAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move EntryAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - EntryAuditInfo tmp = _CacheList[0]; // Get the first EntryAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first EntryAuditInfo - } - } - internal static void AddList(EntryAuditInfoList lst) - { - foreach (EntryAuditInfo item in lst) AddToCache(item); - } - protected static EntryAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base EntryAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current EntryAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check EntryAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current EntryAuditInfo - protected override object GetIdValue() - { - return 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; } } - protected EntryAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~EntryAuditInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listEntryAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listEntryAuditInfo.Contains(this)) listEntryAuditInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(EntryAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (EntryAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(EntryAudit tmp) - { - _ContentID = tmp.ContentID; - _DocID = tmp.DocID; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _EntryAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up EntryAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal EntryAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.Constructor", ex); - throw new DbCslaException("EntryAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _DocID = dr.GetInt32("DocID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getEntryAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - EntryAuditInfoExtension _EntryAuditInfoExtension = new EntryAuditInfoExtension(); - [Serializable()] - partial class EntryAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(EntryAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class EntryAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is EntryAuditInfo) - { - // Return the ToString value - return ((EntryAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void EntryAuditInfoEvent(object sender); + /// + /// EntryAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryAuditInfoConverter))] + public partial class EntryAuditInfo : ReadOnlyBase, IDisposable + { + public event EntryAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(EntryAuditInfo entryAuditInfo) + { + if (!_CacheList.Contains(entryAuditInfo)) _CacheList.Add(entryAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(EntryAuditInfo entryAuditInfo) + { + while (_CacheList.Contains(entryAuditInfo)) _CacheList.Remove(entryAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move EntryAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + EntryAuditInfo tmp = _CacheList[0]; // Get the first EntryAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first EntryAuditInfo + } + } + internal static void AddList(EntryAuditInfoList lst) + { + foreach (EntryAuditInfo item in lst) AddToCache(item); + } + protected static EntryAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base EntryAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current EntryAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check EntryAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current EntryAuditInfo + protected override object GetIdValue() + { + return 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; } } + protected EntryAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~EntryAuditInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listEntryAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listEntryAuditInfo.Contains(this)) listEntryAuditInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(EntryAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(EntryAudit tmp) + { + _ContentID = tmp.ContentID; + _DocID = tmp.DocID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _EntryAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up EntryAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal EntryAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.Constructor", ex); + throw new DbCslaException("EntryAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntryAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + EntryAuditInfoExtension _EntryAuditInfoExtension = new EntryAuditInfoExtension(); + [Serializable()] + partial class EntryAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(EntryAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class EntryAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryAuditInfo) + { + // Return the ToString value + return ((EntryAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs index 0ead8c49..070f426c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/EntryInfo.cs @@ -19,371 +19,365 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void EntryInfoEvent(object sender); - /// - /// EntryInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(EntryInfoConverter))] - public partial class EntryInfo : ReadOnlyBase, IDisposable - { - public event EntryInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(EntryInfo entryInfo) - { - if (!_CacheList.Contains(entryInfo)) _CacheList.Add(entryInfo); // In AddToCache - } - protected static void RemoveFromCache(EntryInfo entryInfo) - { - while (_CacheList.Contains(entryInfo)) _CacheList.Remove(entryInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move EntryInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - EntryInfo tmp = _CacheList[0]; // Get the first EntryInfo - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first EntryInfo - } - } - internal static void AddList(EntryInfoList lst) - { - foreach (EntryInfo item in lst) AddToCache(item); - } - protected static EntryInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private DocumentInfo _MyDocument; - public DocumentInfo MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); - return _MyDocument; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base EntryInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current EntryInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check EntryInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current EntryInfo - protected override object GetIdValue() - { - return 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; } } - protected EntryInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~EntryInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listEntryInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listEntryInfo.Contains(this)) listEntryInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Entry tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Entry tmp) - { - if (_DocID != tmp.DocID) - { - if (MyDocument != null) 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 - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _EntryInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(DocumentEntry tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocumentEntry tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _EntryInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up EntryInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal EntryInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.Constructor", ex); - throw new DbCslaException("EntryInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _DocID = dr.GetInt32("DocID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getEntry"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension(); - [Serializable()] - partial class EntryInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(EntryInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class EntryInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is EntryInfo) - { - // Return the ToString value - return ((EntryInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void EntryInfoEvent(object sender); + /// + /// EntryInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryInfoConverter))] + public partial class EntryInfo : ReadOnlyBase, IDisposable + { + public event EntryInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(EntryInfo entryInfo) + { + if (!_CacheList.Contains(entryInfo)) _CacheList.Add(entryInfo); // In AddToCache + } + protected static void RemoveFromCache(EntryInfo entryInfo) + { + while (_CacheList.Contains(entryInfo)) _CacheList.Remove(entryInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move EntryInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + EntryInfo tmp = _CacheList[0]; // Get the first EntryInfo + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first EntryInfo + } + } + internal static void AddList(EntryInfoList lst) + { + foreach (EntryInfo item in lst) AddToCache(item); + } + protected static EntryInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private DocumentInfo _MyDocument; + public DocumentInfo MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); + return _MyDocument; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base EntryInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current EntryInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check EntryInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current EntryInfo + protected override object GetIdValue() + { + return 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; } } + protected EntryInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~EntryInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listEntryInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listEntryInfo.Contains(this)) listEntryInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Entry tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Entry tmp) + { + if (_DocID != tmp.DocID) + { + if (MyDocument != null) 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 + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _EntryInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(DocumentEntry tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocumentEntry tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _EntryInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up EntryInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal EntryInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.Constructor", ex); + throw new DbCslaException("EntryInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntry"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension(); + [Serializable()] + partial class EntryInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(EntryInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class EntryInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryInfo) + { + // Return the ToString value + return ((EntryInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Figure.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Figure.cs index 8a46c8e6..03cbc464 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Figure.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Figure.cs @@ -20,1156 +20,1143 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Figure Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FigureConverter))] - public partial class Figure : BusinessBase
, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List
_RefreshFigures = new List
(); - private void AddToRefreshList(List
refreshFigures) - { - if (IsDirty) - refreshFigures.Add(this); - } - private void ClearRefreshList() - { - _RefreshFigures = new List
(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshFigures); - } - private void ProcessRefreshList() - { - foreach (Figure tmp in _RefreshFigures) - { - FigureInfo.Refresh(tmp); - if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); - if (tmp._MyROImage != null) ROImageInfo.Refresh(tmp._MyROImage); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List
_CacheList = new List
(); - protected static void AddToCache(Figure figure) - { - if (!_CacheList.Contains(figure)) _CacheList.Add(figure); // In AddToCache - } - protected static void RemoveFromCache(Figure figure) - { - while (_CacheList.Contains(figure)) _CacheList.Remove(figure); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByROFstID_ImageID = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Figure(s) from temporary _CacheList to _CacheByPrimaryKey - { - Figure tmp = _CacheList[0]; // Get the first Figure - string pKey = tmp.FigureID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List
(); // Add new list for PrimaryKey - _CacheByROFstID_ImageID[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()] = new List
(); // Add new list for ROFstID_ImageID - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByROFstID_ImageID[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first Figure - } - } - protected static Figure GetCachedByPrimaryKey(int figureID) - { - ConvertListToDictionary(); - string key = figureID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Figure GetCachedByROFstID_ImageID(int rOFstID, int imageID) - { - ConvertListToDictionary(); - string key = rOFstID.ToString() + "_" + imageID.ToString(); - if (_CacheByROFstID_ImageID.ContainsKey(key)) return _CacheByROFstID_ImageID[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextFigureID = -1; - public static int NextFigureID - { - get { return _nextFigureID--; } - } - private int _FigureID; - [System.ComponentModel.DataObjectField(true, true)] - public int FigureID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FigureID", true); - return _FigureID; - } - } - private int _ROFstID; - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyROFst", true); - if (_MyROFst != value) - { - _MyROFst = value; - _ROFstID = value.ROFstID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _ImageID; - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImage _MyROImage; - public ROImage MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash - return _MyROImage; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyROImage", true); - if (_MyROImage != value) - { - _MyROImage = value; - _ImageID = value.ImageID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)) && (_MyROImage == null ? true : _MyROImage.IsValidList(list)); - } - // CSLATODO: Replace base Figure.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Figure - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Figure.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Figure - protected override object GetIdValue() - { - return MyFigureUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; - if (_MyROImage != null && (hasBrokenRules = _MyROImage.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule
(MyROFstRequired, "MyROFst"); - ValidationRules.AddRule
(MyROImageRequired, "MyROImage"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _FigureExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _FigureExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyROFstRequired(Figure target, Csla.Validation.RuleArgs e) - { - if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyROImageRequired(Figure target, Csla.Validation.RuleArgs e) - { - if (target._ImageID == 0 && target._MyROImage == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(ImageID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ROFstID, ""); - //AuthorizationRules.AllowWrite(ImageID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _FigureExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 Figure() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Figure() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(FigureID.ToString())) - { - List
listFigure = _CacheByPrimaryKey[FigureID.ToString()]; // Get the list of items - while (listFigure.Contains(this)) listFigure.Remove(this); // Remove the item from the list - if (listFigure.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(FigureID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByROFstID_ImageID.Keys) - if (_CacheByROFstID_ImageID[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List
listFigure = _CacheByROFstID_ImageID[myKey]; // Get the list of items - listFigure.Remove(this); // Remove the item from the list - if (listFigure.Count == 0) //If there are no items left in the list - _CacheByROFstID_ImageID.Remove(myKey); // remove the list - } - } - public static Figure New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Figure"); - try - { - return DataPortal.Create
(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Figure.New", ex); - } - } - public static Figure New(ROFst myROFst, ROImage myROImage) - { - Figure tmp = Figure.New(); - tmp.MyROFst = myROFst; - tmp.MyROImage = myROImage; - return tmp; - } - public static Figure New(ROFst myROFst, ROImage myROImage, string config, DateTime dts, string userID) - { - Figure tmp = Figure.New(); - tmp.MyROFst = myROFst; - tmp.MyROImage = myROImage; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Figure MakeFigure(ROFst myROFst, ROImage myROImage, string config, DateTime dts, string userID) - { - Figure tmp = Figure.New(myROFst, myROImage, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Figure New(ROFst myROFst, ROImage myROImage, string config) - { - Figure tmp = Figure.New(); - tmp.MyROFst = myROFst; - tmp.MyROImage = myROImage; - tmp.Config = config; - return tmp; - } - public static Figure MakeFigure(ROFst myROFst, ROImage myROImage, string config) - { - Figure tmp = Figure.New(myROFst, myROImage, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch
(new PKCriteria(figureID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Figure - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Figure.Get", ex); - } - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch
(new ROFstID_ImageIDCriteria(rOFstID, imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Figure - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Figure.GetByROFstID_ImageID", ex); - } - } - public static Figure Get(SafeDataReader dr) - { - if (dr.Read()) return new Figure(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Figure.Delete", ex); - } - } - 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(); - Figure figure = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(figure);//Refresh the item in AllList - ProcessRefreshList(); - return figure; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _FigureID; - public int FigureID - { get { return _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; } } - public ROFstID_ImageIDCriteria(int rOFstID, int imageID) - { - _ROFstID = rOFstID; - _ImageID = imageID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _FigureID = NextFigureID; - // Database Defaults - _DTS = _FigureExtension.DefaultDTS; - _UserID = _FigureExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.ReadData", GetHashCode()); - try - { - _FigureID = dr.GetInt32("FigureID"); - _ROFstID = dr.GetInt32("ROFstID"); - _ImageID = dr.GetInt32("ImageID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Figure.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFigure"; - cm.Parameters.AddWithValue("@FigureID", criteria.FigureID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Figure.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(ROFstID_ImageIDCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFigureByROFstID_ImageID"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Figure.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Figure.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyROFst != null) _MyROFst.Update(); - if (_MyROImage != null) _MyROImage.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myROFst.ROFstID); - cm.Parameters.AddWithValue("@ImageID", myROImage.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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.Add", ex); - throw new DbCslaException("Figure.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - 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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateFigure"; - // Input All Fields - Except Calculated Columns - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteFigure"; - cm.Parameters.AddWithValue("@FigureID", criteria.FigureID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteFigure"; - // Input PK Fields - cm.Parameters.AddWithValue("@FigureID", figureID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.Remove", ex); - throw new DbCslaException("Figure.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int figureID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(figureID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Figure.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _FigureID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int figureID) - { - _FigureID = figureID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsFigure"; - cm.Parameters.AddWithValue("@FigureID", _FigureID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Execute", ex); - throw new DbCslaException("Figure.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - FigureExtension _FigureExtension = new FigureExtension(); - [Serializable()] - partial class FigureExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FigureConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Figure) - { - // Return the ToString value - return ((Figure)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Figure Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FigureConverter))] + public partial class Figure : BusinessBase
, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List
_RefreshFigures = new List
(); + private void AddToRefreshList(List
refreshFigures) + { + if (IsDirty) + refreshFigures.Add(this); + } + private void ClearRefreshList() + { + _RefreshFigures = new List
(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshFigures); + } + private void ProcessRefreshList() + { + foreach (Figure tmp in _RefreshFigures) + { + FigureInfo.Refresh(tmp); + if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); + if (tmp._MyROImage != null) ROImageInfo.Refresh(tmp._MyROImage); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List
_CacheList = new List
(); + protected static void AddToCache(Figure figure) + { + if (!_CacheList.Contains(figure)) _CacheList.Add(figure); // In AddToCache + } + protected static void RemoveFromCache(Figure figure) + { + while (_CacheList.Contains(figure)) _CacheList.Remove(figure); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByROFstID_ImageID = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Figure(s) from temporary _CacheList to _CacheByPrimaryKey + { + Figure tmp = _CacheList[0]; // Get the first Figure + string pKey = tmp.FigureID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List
(); // Add new list for PrimaryKey + _CacheByROFstID_ImageID[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()] = new List
(); // Add new list for ROFstID_ImageID + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByROFstID_ImageID[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first Figure + } + } + protected static Figure GetCachedByPrimaryKey(int figureID) + { + ConvertListToDictionary(); + string key = figureID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Figure GetCachedByROFstID_ImageID(int rOFstID, int imageID) + { + ConvertListToDictionary(); + string key = rOFstID.ToString() + "_" + imageID.ToString(); + if (_CacheByROFstID_ImageID.ContainsKey(key)) return _CacheByROFstID_ImageID[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextFigureID = -1; + public static int NextFigureID + { + get { return _nextFigureID--; } + } + private int _FigureID; + [System.ComponentModel.DataObjectField(true, true)] + public int FigureID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FigureID; + } + } + private int _ROFstID; + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyROFst != value) + { + _MyROFst = value; + _ROFstID = value.ROFstID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _ImageID; + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImage _MyROImage; + public ROImage MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash + return _MyROImage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyROImage != value) + { + _MyROImage = value; + _ImageID = value.ImageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)) && (_MyROImage == null ? true : _MyROImage.IsValidList(list)); + } + // CSLATODO: Replace base Figure.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Figure + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Figure.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Figure + protected override object GetIdValue() + { + return MyFigureUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; + if (_MyROImage != null && (hasBrokenRules = _MyROImage.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule
(MyROFstRequired, "MyROFst"); + ValidationRules.AddRule
(MyROImageRequired, "MyROImage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _FigureExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _FigureExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyROFstRequired(Figure target, Csla.Validation.RuleArgs e) + { + if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyROImageRequired(Figure target, Csla.Validation.RuleArgs e) + { + if (target._ImageID == 0 && target._MyROImage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(ImageID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ROFstID, ""); + //AuthorizationRules.AllowWrite(ImageID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _FigureExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 Figure() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Figure() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(FigureID.ToString())) + { + List
listFigure = _CacheByPrimaryKey[FigureID.ToString()]; // Get the list of items + while (listFigure.Contains(this)) listFigure.Remove(this); // Remove the item from the list + if (listFigure.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(FigureID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByROFstID_ImageID.Keys) + if (_CacheByROFstID_ImageID[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List
listFigure = _CacheByROFstID_ImageID[myKey]; // Get the list of items + listFigure.Remove(this); // Remove the item from the list + if (listFigure.Count == 0) //If there are no items left in the list + _CacheByROFstID_ImageID.Remove(myKey); // remove the list + } + } + public static Figure New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Figure"); + try + { + return DataPortal.Create
(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Figure.New", ex); + } + } + public static Figure New(ROFst myROFst, ROImage myROImage) + { + Figure tmp = Figure.New(); + tmp.MyROFst = myROFst; + tmp.MyROImage = myROImage; + return tmp; + } + public static Figure New(ROFst myROFst, ROImage myROImage, string config, DateTime dts, string userID) + { + Figure tmp = Figure.New(); + tmp.MyROFst = myROFst; + tmp.MyROImage = myROImage; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Figure MakeFigure(ROFst myROFst, ROImage myROImage, string config, DateTime dts, string userID) + { + Figure tmp = Figure.New(myROFst, myROImage, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Figure New(ROFst myROFst, ROImage myROImage, string config) + { + Figure tmp = Figure.New(); + tmp.MyROFst = myROFst; + tmp.MyROImage = myROImage; + tmp.Config = config; + return tmp; + } + public static Figure MakeFigure(ROFst myROFst, ROImage myROImage, string config) + { + Figure tmp = Figure.New(myROFst, myROImage, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch
(new PKCriteria(figureID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Figure + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Figure.Get", ex); + } + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch
(new ROFstID_ImageIDCriteria(rOFstID, imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Figure + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Figure.GetByROFstID_ImageID", ex); + } + } + public static Figure Get(SafeDataReader dr) + { + if (dr.Read()) return new Figure(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Figure.Delete", ex); + } + } + 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(); + Figure figure = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(figure);//Refresh the item in AllList + ProcessRefreshList(); + return figure; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _FigureID; + public int FigureID + { get { return _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; } } + public ROFstID_ImageIDCriteria(int rOFstID, int imageID) + { + _ROFstID = rOFstID; + _ImageID = imageID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _FigureID = NextFigureID; + // Database Defaults + _DTS = _FigureExtension.DefaultDTS; + _UserID = _FigureExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.ReadData", GetHashCode()); + try + { + _FigureID = dr.GetInt32("FigureID"); + _ROFstID = dr.GetInt32("ROFstID"); + _ImageID = dr.GetInt32("ImageID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Figure.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFigure"; + cm.Parameters.AddWithValue("@FigureID", criteria.FigureID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Figure.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(ROFstID_ImageIDCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFigureByROFstID_ImageID"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Figure.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Figure.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyROFst != null) _MyROFst.Update(); + if (_MyROImage != null) _MyROImage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myROFst.ROFstID); + cm.Parameters.AddWithValue("@ImageID", myROImage.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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.Add", ex); + throw new DbCslaException("Figure.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + 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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateFigure"; + // Input All Fields - Except Calculated Columns + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteFigure"; + cm.Parameters.AddWithValue("@FigureID", criteria.FigureID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteFigure"; + // Input PK Fields + cm.Parameters.AddWithValue("@FigureID", figureID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.Remove", ex); + throw new DbCslaException("Figure.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int figureID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(figureID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Figure.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _FigureID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int figureID) + { + _FigureID = figureID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Figure.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsFigure"; + cm.Parameters.AddWithValue("@FigureID", _FigureID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Figure.DataPortal_Execute", ex); + throw new DbCslaException("Figure.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + FigureExtension _FigureExtension = new FigureExtension(); + [Serializable()] + partial class FigureExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FigureConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Figure) + { + // Return the ToString value + return ((Figure)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FigureInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FigureInfo.cs index f28c751f..9d2167f6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FigureInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FigureInfo.cs @@ -19,446 +19,437 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void FigureInfoEvent(object sender); - /// - /// FigureInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FigureInfoConverter))] - public partial class FigureInfo : ReadOnlyBase, IDisposable - { - public event FigureInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(FigureInfo figureInfo) - { - if (!_CacheList.Contains(figureInfo)) _CacheList.Add(figureInfo); // In AddToCache - } - protected static void RemoveFromCache(FigureInfo figureInfo) - { - while (_CacheList.Contains(figureInfo)) _CacheList.Remove(figureInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move FigureInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - FigureInfo tmp = _CacheList[0]; // Get the first FigureInfo - string pKey = tmp.FigureID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first FigureInfo - } - } - internal static void AddList(FigureInfoList lst) - { - foreach (FigureInfo item in lst) AddToCache(item); - } - protected static FigureInfo GetCachedByPrimaryKey(int figureID) - { - ConvertListToDictionary(); - string key = figureID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FigureID", true); - return _FigureID; - } - } - private int _ROFstID; - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFstInfo _MyROFst; - public ROFstInfo MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); - return _MyROFst; - } - } - private int _ImageID; - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImageInfo _MyROImage; - public ROImageInfo MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImageInfo.Get(_ImageID); - return _MyROImage; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base FigureInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FigureInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check FigureInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FigureInfo - protected override object GetIdValue() - { - return 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; } } - protected FigureInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~FigureInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(FigureID.ToString())) return; - List listFigureInfo = _CacheByPrimaryKey[FigureID.ToString()]; // Get the list of items - while (listFigureInfo.Contains(this)) listFigureInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Figure tmp) - { - string key = tmp.FigureID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FigureInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Figure tmp) - { - if (_ROFstID != tmp.ROFstID) - { - if (MyROFst != null) 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 - if (_ImageID != tmp.ImageID) - { - if (MyROImage != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FigureInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ROFstFigure tmp) - { - string key = tmp.FigureID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FigureInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROFstFigure tmp) - { - if (_ImageID != tmp.ImageID) - { - if (MyROImage != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FigureInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ROImageFigure tmp) - { - string key = tmp.FigureID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FigureInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROImageFigure tmp) - { - if (_ROFstID != tmp.ROFstID) - { - if (MyROFst != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FigureInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(figureID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up FigureInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on FigureInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal FigureInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FigureInfo.Constructor", ex); - throw new DbCslaException("FigureInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _FigureID; - public int FigureID - { get { return _FigureID; } } - public PKCriteria(int figureID) - { - _FigureID = figureID; - } - } - private string _ROImage_FileName = string.Empty; - public string ROImage_FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_FileName", true); - return _ROImage_FileName; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.ReadData", GetHashCode()); - try - { - _FigureID = dr.GetInt32("FigureID"); - _ROFstID = dr.GetInt32("ROFstID"); - _ImageID = dr.GetInt32("ImageID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - for (int i = 0; i < dr.FieldCount; i++) - { - if (dr.GetName(i) == "ROImage_FileName") - _ROImage_FileName = dr.GetString("ROImage_FileName"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FigureInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FigureInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFigure"; - cm.Parameters.AddWithValue("@FigureID", criteria.FigureID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FigureInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FigureInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - FigureInfoExtension _FigureInfoExtension = new FigureInfoExtension(); - [Serializable()] - partial class FigureInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(FigureInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class FigureInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FigureInfo) - { - // Return the ToString value - return ((FigureInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void FigureInfoEvent(object sender); + /// + /// FigureInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FigureInfoConverter))] + public partial class FigureInfo : ReadOnlyBase, IDisposable + { + public event FigureInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(FigureInfo figureInfo) + { + if (!_CacheList.Contains(figureInfo)) _CacheList.Add(figureInfo); // In AddToCache + } + protected static void RemoveFromCache(FigureInfo figureInfo) + { + while (_CacheList.Contains(figureInfo)) _CacheList.Remove(figureInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move FigureInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + FigureInfo tmp = _CacheList[0]; // Get the first FigureInfo + string pKey = tmp.FigureID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first FigureInfo + } + } + internal static void AddList(FigureInfoList lst) + { + foreach (FigureInfo item in lst) AddToCache(item); + } + protected static FigureInfo GetCachedByPrimaryKey(int figureID) + { + ConvertListToDictionary(); + string key = figureID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FigureID; + } + } + private int _ROFstID; + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFstInfo _MyROFst; + public ROFstInfo MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); + return _MyROFst; + } + } + private int _ImageID; + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImageInfo _MyROImage; + public ROImageInfo MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImageInfo.Get(_ImageID); + return _MyROImage; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base FigureInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FigureInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check FigureInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FigureInfo + protected override object GetIdValue() + { + return 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; } } + protected FigureInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~FigureInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(FigureID.ToString())) return; + List listFigureInfo = _CacheByPrimaryKey[FigureID.ToString()]; // Get the list of items + while (listFigureInfo.Contains(this)) listFigureInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Figure tmp) + { + string key = tmp.FigureID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FigureInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Figure tmp) + { + if (_ROFstID != tmp.ROFstID) + { + if (MyROFst != null) 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 + if (_ImageID != tmp.ImageID) + { + if (MyROImage != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FigureInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ROFstFigure tmp) + { + string key = tmp.FigureID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FigureInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROFstFigure tmp) + { + if (_ImageID != tmp.ImageID) + { + if (MyROImage != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FigureInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ROImageFigure tmp) + { + string key = tmp.FigureID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FigureInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROImageFigure tmp) + { + if (_ROFstID != tmp.ROFstID) + { + if (MyROFst != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FigureInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(figureID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FigureInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FigureInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal FigureInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FigureInfo.Constructor", ex); + throw new DbCslaException("FigureInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _FigureID; + public int FigureID + { get { return _FigureID; } } + public PKCriteria(int figureID) + { + _FigureID = figureID; + } + } + private string _ROImage_FileName = string.Empty; + public string ROImage_FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_FileName; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.ReadData", GetHashCode()); + try + { + _FigureID = dr.GetInt32("FigureID"); + _ROFstID = dr.GetInt32("ROFstID"); + _ImageID = dr.GetInt32("ImageID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + for (int i = 0; i < dr.FieldCount; i++) + { + if (dr.GetName(i) == "ROImage_FileName") + _ROImage_FileName = dr.GetString("ROImage_FileName"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FigureInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FigureInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFigure"; + cm.Parameters.AddWithValue("@FigureID", criteria.FigureID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FigureInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FigureInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + FigureInfoExtension _FigureInfoExtension = new FigureInfoExtension(); + [Serializable()] + partial class FigureInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(FigureInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class FigureInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FigureInfo) + { + // Return the ToString value + return ((FigureInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs index e2b73a00..fb8a0a45 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Folder.cs @@ -20,1563 +20,1533 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Folder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderConverter))] - public partial class Folder : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshFolders = new List(); - private List _RefreshFolderAssignments = new List(); - private List _RefreshFolderDocVersions = new List(); - private void AddToRefreshList(List refreshFolders, List refreshFolderAssignments, List refreshFolderDocVersions) - { - if (IsDirty) - refreshFolders.Add(this); - if (_FolderAssignments != null && _FolderAssignments.IsDirty) - { - foreach (FolderAssignment tmp in _FolderAssignments) - { - if (tmp.IsDirty) refreshFolderAssignments.Add(tmp); - } - } - if (_FolderDocVersions != null && _FolderDocVersions.IsDirty) - { - foreach (FolderDocVersion tmp in _FolderDocVersions) - { - if (tmp.IsDirty) refreshFolderDocVersions.Add(tmp); - } - } - if (_ChildFolders != null && _ChildFolders.IsDirty) - { - foreach (Folder tmp in _ChildFolders) - { - tmp.AddToRefreshList(refreshFolders, refreshFolderAssignments, refreshFolderDocVersions); - } - } - } - private void ClearRefreshList() - { - _RefreshFolders = new List(); - _RefreshFolderAssignments = new List(); - _RefreshFolderDocVersions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshFolders, _RefreshFolderAssignments, _RefreshFolderDocVersions); - } - private void ProcessRefreshList() - { - foreach (Folder tmp in _RefreshFolders) - { - FolderInfo.Refresh(tmp); - if (tmp._MyConnection != null) ConnectionInfo.Refresh(tmp._MyConnection); - if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); - } - foreach (FolderAssignment tmp in _RefreshFolderAssignments) - { - AssignmentInfo.Refresh(tmp); - } - foreach (FolderDocVersion tmp in _RefreshFolderDocVersions) - { - DocVersionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Folder folder) - { - if (!_CacheList.Contains(folder)) _CacheList.Add(folder); // In AddToCache - } - protected static void RemoveFromCache(Folder folder) - { - while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByParentID_Name = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Folder(s) from temporary _CacheList to _CacheByPrimaryKey - { - Folder tmp = _CacheList[0]; // Get the first Folder - string pKey = tmp.FolderID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first Folder - } - } - protected static Folder GetCachedByPrimaryKey(int folderID) - { - ConvertListToDictionary(); - string key = folderID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Folder GetCachedByParentID_Name(int parentID, string name) - { - ConvertListToDictionary(); - string key = parentID.ToString() + "_" + name.ToString(); - if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextFolderID = -1; - public static int NextFolderID - { - get { return _nextFolderID--; } - } - private int _FolderID; - [System.ComponentModel.DataObjectField(true, true)] - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - return _FolderID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private Folder _MyParent; - public Folder MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - _ParentID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _DBID; - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - if (_MyConnection != null) _DBID = _MyConnection.DBID; - return _DBID; - } - } - private Connection _MyConnection; - public Connection MyConnection - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyConnection", true); - if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); - return _MyConnection; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyConnection", true); - if (_MyConnection != value) - { - _MyConnection = value; - _DBID = value.DBID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ShortName", true); - if (value == null) value = string.Empty; - if (_ShortName != value) - { - _ShortName = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ManualOrder", true); - if (_ManualOrder != value) - { - _ManualOrder = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _FolderAssignmentCount = 0; - /// - /// Count of FolderAssignments for this Folder - /// - public int FolderAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignmentCount", true); - return _FolderAssignmentCount; - } - } - private FolderAssignments _FolderAssignments = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FolderAssignmentsConverter))] - public FolderAssignments FolderAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignments", true); - if (_FolderAssignmentCount < 0 || (_FolderAssignmentCount > 0 && _FolderAssignments == null)) - _FolderAssignments = FolderAssignments.GetByFolderID(FolderID); - if (_FolderAssignmentCount < 0 ) - _FolderAssignmentCount = _FolderAssignments == null ? 0 : _FolderAssignments.Count; - if (_FolderAssignments == null) - _FolderAssignments = FolderAssignments.New(); - return _FolderAssignments; - } - } - public void Reset_FolderAssignments() - { - _FolderAssignmentCount = -1; - } - private int _FolderDocVersionCount = 0; - /// - /// Count of FolderDocVersions for this Folder - /// - public int FolderDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersionCount", true); - return _FolderDocVersionCount; - } - } - private FolderDocVersions _FolderDocVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FolderDocVersionsConverter))] - public FolderDocVersions FolderDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersions", true); - if (_FolderDocVersionCount < 0 || (_FolderDocVersionCount > 0 && _FolderDocVersions == null)) - _FolderDocVersions = FolderDocVersions.GetByFolderID(FolderID); - if (_FolderDocVersionCount < 0 ) - _FolderDocVersionCount = _FolderDocVersions == null ? 0 : _FolderDocVersions.Count; - if (_FolderDocVersions == null) - _FolderDocVersions = FolderDocVersions.New(); - return _FolderDocVersions; - } - } - public void Reset_FolderDocVersions() - { - _FolderDocVersionCount = -1; - } - private int _ChildFolderCount = 0; - /// - /// Count of ChildFolders for this Folder - /// - public int ChildFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolderCount", true); - return _ChildFolderCount; - } - } - private ChildFolders _ChildFolders = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ChildFoldersConverter))] - public ChildFolders ChildFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolders", true); - if (_ChildFolderCount < 0 || (_ChildFolderCount > 0 && _ChildFolders == null)) - _ChildFolders = ChildFolders.GetByParentID(FolderID); - if (_ChildFolderCount < 0 ) - _ChildFolderCount = _ChildFolders == null ? 0 : _ChildFolders.Count; - if (_ChildFolders == null) - _ChildFolders = ChildFolders.New(); - return _ChildFolders; - } - } - public void Reset_ChildFolders() - { - _ChildFolderCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : 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)); - } - // CSLATODO: Replace base Folder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Folder - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Folder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Folder - protected override object GetIdValue() - { - return MyFolderUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_FolderAssignments != null && (hasBrokenRules = _FolderAssignments.HasBrokenRules) != null) return hasBrokenRules; - if (_FolderDocVersions != null && (hasBrokenRules = _FolderDocVersions.HasBrokenRules) != null) return hasBrokenRules; - if (_ChildFolders != null && (hasBrokenRules = _ChildFolders.HasBrokenRules) != null) return hasBrokenRules; - if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ShortName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _FolderExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _FolderExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyConnectionRequired(Folder target, Csla.Validation.RuleArgs e) - { - if (target._DBID == 0 && target._MyConnection == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowRead(DBID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ShortName, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(ManualOrder, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowWrite(DBID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ShortName, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(ManualOrder, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _FolderExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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; } } - 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 Folder() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Folder() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) - { - List listFolder = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items - while (listFolder.Contains(this)) listFolder.Remove(this); // Remove the item from the list - if (listFolder.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByParentID_Name.Keys) - if (_CacheByParentID_Name[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listFolder = _CacheByParentID_Name[myKey]; // Get the list of items - listFolder.Remove(this); // Remove the item from the list - if (listFolder.Count == 0) //If there are no items left in the list - _CacheByParentID_Name.Remove(myKey); // remove the list - } - } - public static Folder New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Folder"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.New", ex); - } - } - public static Folder New(Folder myParent, string name, string shortName) - { - Folder tmp = Folder.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.ShortName = shortName; - return tmp; - } - public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) - { - Folder tmp = Folder.New(); - tmp.MyParent = myParent; - tmp.MyConnection = myConnection; - tmp.Name = name; - tmp.Title = title; - tmp.ShortName = shortName; - tmp.MyFormat = myFormat; - tmp.ManualOrder = manualOrder; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) - { - Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config, dts, usrID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) - { - Folder tmp = Folder.New(); - tmp.MyParent = myParent; - tmp.MyConnection = myConnection; - tmp.Name = name; - tmp.Title = title; - tmp.ShortName = shortName; - tmp.MyFormat = myFormat; - tmp.ManualOrder = manualOrder; - tmp.Config = config; - return tmp; - } - public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) - { - Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(folderID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Folder - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.Get", ex); - } - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Folder - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.GetByParentID_Name", ex); - } - } - public static Folder Get(SafeDataReader dr, Folder parent) - { - if (dr.Read()) return new Folder(dr, parent); - return null; - } - internal Folder(SafeDataReader dr) - { - ReadData(dr); - } - private Folder(SafeDataReader dr, Folder parent) - { - ReadData(dr); - MarkAsChild(); - } - internal Folder(SafeDataReader dr, int parentID) - { - ReadData(dr); - MarkAsChild(); - } - 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: - Folder tmp = Folder.Get(folderID); - tmp.RemoveFromDictionaries(); - DataPortal.Delete(new PKCriteria(folderID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.Delete", ex); - } - } - 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(); - Folder folder = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(folder);//Refresh the item in AllList - ProcessRefreshList(); - return folder; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _FolderID; - public int FolderID - { get { return _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; } } - public ParentID_NameCriteria(int parentID, string name) - { - _ParentID = parentID; - _Name = name; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _FolderID = NextFolderID; - // Database Defaults - _ParentID = _FolderExtension.DefaultParentID; - _DBID = _FolderExtension.DefaultDBID; - _DTS = _FolderExtension.DefaultDTS; - _UsrID = _FolderExtension.DefaultUsrID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.ReadData", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _FormatID = (int?)dr.GetValue("FormatID"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); - _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); - _ChildFolderCount = dr.GetInt32("ChildCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFolder"; - cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _FolderAssignments = FolderAssignments.Get(dr); - // load child objects - dr.NextResult(); - _FolderDocVersions = FolderDocVersions.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(ParentID_NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFolderByParentID_Name"; - cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); - cm.Parameters.AddWithValue("@Name", criteria.Name); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyConnection != null) _MyConnection.Update(); - if (_MyFormat != null) _MyFormat.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_FolderAssignments != null) _FolderAssignments.Update(this); - if (_FolderDocVersions != null) _FolderDocVersions.Update(this); - if (_ChildFolders != null) _ChildFolders.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myParent.FolderID); - cm.Parameters.AddWithValue("@DBID", myConnection.DBID); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - cm.Parameters.AddWithValue("@ShortName", shortName); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Add", ex); - throw new DbCslaException("Folder.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) - if(!ex.Message.Contains("Cannot insert duplicate key row in object 'dbo.Folders' with unique index 'IX_UniqueChildFolders'")) - _MyLog.Error("Folder.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - 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); - 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; - } - } - 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) - if(!ex.Message.Contains("Cannot insert duplicate key row in object 'dbo.Folders' with unique index 'IX_UniqueChildFolders'")) - _MyLog.Error("Folder.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - MarkOld(); - } - if (_FolderAssignments != null) _FolderAssignments.Update(this); - if (_FolderDocVersions != null) _FolderDocVersions.Update(this); - if (_ChildFolders != null) _ChildFolders.Update(this); - } - internal void DeleteSelf(Folder folder) - { - // 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"]; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateFolder"; - // Input All Fields - Except Calculated Columns - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Update", ex); - throw new DbCslaException("Folder.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_FolderID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteFolder"; - cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteFolder"; - // Input PK Fields - cm.Parameters.AddWithValue("@FolderID", folderID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Remove", ex); - throw new DbCslaException("Folder.Remove", ex); - } - } + /// + /// Folder Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderConverter))] + public partial class Folder : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshFolders = new List(); + private List _RefreshFolderAssignments = new List(); + private List _RefreshFolderDocVersions = new List(); + private void AddToRefreshList(List refreshFolders, List refreshFolderAssignments, List refreshFolderDocVersions) + { + if (IsDirty) + refreshFolders.Add(this); + if (_FolderAssignments != null && _FolderAssignments.IsDirty) + { + foreach (FolderAssignment tmp in _FolderAssignments) + { + if (tmp.IsDirty) refreshFolderAssignments.Add(tmp); + } + } + if (_FolderDocVersions != null && _FolderDocVersions.IsDirty) + { + foreach (FolderDocVersion tmp in _FolderDocVersions) + { + if (tmp.IsDirty) refreshFolderDocVersions.Add(tmp); + } + } + if (_ChildFolders != null && _ChildFolders.IsDirty) + { + foreach (Folder tmp in _ChildFolders) + { + tmp.AddToRefreshList(refreshFolders, refreshFolderAssignments, refreshFolderDocVersions); + } + } + } + private void ClearRefreshList() + { + _RefreshFolders = new List(); + _RefreshFolderAssignments = new List(); + _RefreshFolderDocVersions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshFolders, _RefreshFolderAssignments, _RefreshFolderDocVersions); + } + private void ProcessRefreshList() + { + foreach (Folder tmp in _RefreshFolders) + { + FolderInfo.Refresh(tmp); + if (tmp._MyConnection != null) ConnectionInfo.Refresh(tmp._MyConnection); + if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); + } + foreach (FolderAssignment tmp in _RefreshFolderAssignments) + { + AssignmentInfo.Refresh(tmp); + } + foreach (FolderDocVersion tmp in _RefreshFolderDocVersions) + { + DocVersionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Folder folder) + { + if (!_CacheList.Contains(folder)) _CacheList.Add(folder); // In AddToCache + } + protected static void RemoveFromCache(Folder folder) + { + while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByParentID_Name = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Folder(s) from temporary _CacheList to _CacheByPrimaryKey + { + Folder tmp = _CacheList[0]; // Get the first Folder + string pKey = tmp.FolderID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first Folder + } + } + protected static Folder GetCachedByPrimaryKey(int folderID) + { + ConvertListToDictionary(); + string key = folderID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Folder GetCachedByParentID_Name(int parentID, string name) + { + ConvertListToDictionary(); + string key = parentID.ToString() + "_" + name.ToString(); + if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextFolderID = -1; + public static int NextFolderID + { + get { return _nextFolderID--; } + } + private int _FolderID; + [System.ComponentModel.DataObjectField(true, true)] + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private Folder _MyParent; + public Folder MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + _ParentID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _DBID; + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection != null) _DBID = _MyConnection.DBID; + return _DBID; + } + } + private Connection _MyConnection; + public Connection MyConnection + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); + return _MyConnection; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyConnection != value) + { + _MyConnection = value; + _DBID = value.DBID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ShortName != value) + { + _ShortName = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ManualOrder != value) + { + _ManualOrder = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _FolderAssignmentCount = 0; + /// + /// Count of FolderAssignments for this Folder + /// + public int FolderAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderAssignmentCount; + } + } + private FolderAssignments _FolderAssignments = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FolderAssignmentsConverter))] + public FolderAssignments FolderAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderAssignmentCount < 0 || (_FolderAssignmentCount > 0 && _FolderAssignments == null)) + _FolderAssignments = FolderAssignments.GetByFolderID(FolderID); + if (_FolderAssignmentCount < 0) + _FolderAssignmentCount = _FolderAssignments == null ? 0 : _FolderAssignments.Count; + if (_FolderAssignments == null) + _FolderAssignments = FolderAssignments.New(); + return _FolderAssignments; + } + } + public void Reset_FolderAssignments() + { + _FolderAssignmentCount = -1; + } + private int _FolderDocVersionCount = 0; + /// + /// Count of FolderDocVersions for this Folder + /// + public int FolderDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderDocVersionCount; + } + } + private FolderDocVersions _FolderDocVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FolderDocVersionsConverter))] + public FolderDocVersions FolderDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderDocVersionCount < 0 || (_FolderDocVersionCount > 0 && _FolderDocVersions == null)) + _FolderDocVersions = FolderDocVersions.GetByFolderID(FolderID); + if (_FolderDocVersionCount < 0) + _FolderDocVersionCount = _FolderDocVersions == null ? 0 : _FolderDocVersions.Count; + if (_FolderDocVersions == null) + _FolderDocVersions = FolderDocVersions.New(); + return _FolderDocVersions; + } + } + public void Reset_FolderDocVersions() + { + _FolderDocVersionCount = -1; + } + private int _ChildFolderCount = 0; + /// + /// Count of ChildFolders for this Folder + /// + public int ChildFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ChildFolderCount; + } + } + private ChildFolders _ChildFolders = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ChildFoldersConverter))] + public ChildFolders ChildFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFolderCount < 0 || (_ChildFolderCount > 0 && _ChildFolders == null)) + _ChildFolders = ChildFolders.GetByParentID(FolderID); + if (_ChildFolderCount < 0) + _ChildFolderCount = _ChildFolders == null ? 0 : _ChildFolders.Count; + if (_ChildFolders == null) + _ChildFolders = ChildFolders.New(); + return _ChildFolders; + } + } + public void Reset_ChildFolders() + { + _ChildFolderCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : 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)); + } + // CSLATODO: Replace base Folder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Folder + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Folder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Folder + protected override object GetIdValue() + { + return MyFolderUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_FolderAssignments != null && (hasBrokenRules = _FolderAssignments.HasBrokenRules) != null) return hasBrokenRules; + if (_FolderDocVersions != null && (hasBrokenRules = _FolderDocVersions.HasBrokenRules) != null) return hasBrokenRules; + if (_ChildFolders != null && (hasBrokenRules = _ChildFolders.HasBrokenRules) != null) return hasBrokenRules; + if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ShortName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _FolderExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _FolderExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyConnectionRequired(Folder target, Csla.Validation.RuleArgs e) + { + if (target._DBID == 0 && target._MyConnection == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowRead(DBID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(ShortName, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowWrite(DBID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(ShortName, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _FolderExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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; } } + 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 Folder() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Folder() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) + { + List listFolder = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items + while (listFolder.Contains(this)) listFolder.Remove(this); // Remove the item from the list + if (listFolder.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByParentID_Name.Keys) + if (_CacheByParentID_Name[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listFolder = _CacheByParentID_Name[myKey]; // Get the list of items + listFolder.Remove(this); // Remove the item from the list + if (listFolder.Count == 0) //If there are no items left in the list + _CacheByParentID_Name.Remove(myKey); // remove the list + } + } + public static Folder New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Folder"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.New", ex); + } + } + public static Folder New(Folder myParent, string name, string shortName) + { + Folder tmp = Folder.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.ShortName = shortName; + return tmp; + } + public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) + { + Folder tmp = Folder.New(); + tmp.MyParent = myParent; + tmp.MyConnection = myConnection; + tmp.Name = name; + tmp.Title = title; + tmp.ShortName = shortName; + tmp.MyFormat = myFormat; + tmp.ManualOrder = manualOrder; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) + { + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config, dts, usrID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) + { + Folder tmp = Folder.New(); + tmp.MyParent = myParent; + tmp.MyConnection = myConnection; + tmp.Name = name; + tmp.Title = title; + tmp.ShortName = shortName; + tmp.MyFormat = myFormat; + tmp.ManualOrder = manualOrder; + tmp.Config = config; + return tmp; + } + public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) + { + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(folderID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Folder + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.Get", ex); + } + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Folder + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.GetByParentID_Name", ex); + } + } + public static Folder Get(SafeDataReader dr, Folder parent) + { + if (dr.Read()) return new Folder(dr, parent); + return null; + } + internal Folder(SafeDataReader dr) + { + ReadData(dr); + } + private Folder(SafeDataReader dr, Folder parent) + { + ReadData(dr); + MarkAsChild(); + } + internal Folder(SafeDataReader dr, int parentID) + { + ReadData(dr); + MarkAsChild(); + } + 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: + Folder tmp = Folder.Get(folderID); + tmp.RemoveFromDictionaries(); + DataPortal.Delete(new PKCriteria(folderID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.Delete", ex); + } + } + 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(); + Folder folder = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(folder);//Refresh the item in AllList + ProcessRefreshList(); + return folder; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _FolderID; + public int FolderID + { get { return _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; } } + public ParentID_NameCriteria(int parentID, string name) + { + _ParentID = parentID; + _Name = name; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _FolderID = NextFolderID; + // Database Defaults + _ParentID = _FolderExtension.DefaultParentID; + _DBID = _FolderExtension.DefaultDBID; + _DTS = _FolderExtension.DefaultDTS; + _UsrID = _FolderExtension.DefaultUsrID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.ReadData", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); + _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); + _ChildFolderCount = dr.GetInt32("ChildCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolder"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _FolderAssignments = FolderAssignments.Get(dr); + // load child objects + dr.NextResult(); + _FolderDocVersions = FolderDocVersions.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(ParentID_NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolderByParentID_Name"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + cm.Parameters.AddWithValue("@Name", criteria.Name); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyConnection != null) _MyConnection.Update(); + if (_MyFormat != null) _MyFormat.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_FolderAssignments != null) _FolderAssignments.Update(this); + if (_FolderDocVersions != null) _FolderDocVersions.Update(this); + if (_ChildFolders != null) _ChildFolders.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myParent.FolderID); + cm.Parameters.AddWithValue("@DBID", myConnection.DBID); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + cm.Parameters.AddWithValue("@ShortName", shortName); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Add", ex); + throw new DbCslaException("Folder.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) + if (!ex.Message.Contains("Cannot insert duplicate key row in object 'dbo.Folders' with unique index 'IX_UniqueChildFolders'")) + _MyLog.Error("Folder.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + 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); + 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; + } + } + 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) + if (!ex.Message.Contains("Cannot insert duplicate key row in object 'dbo.Folders' with unique index 'IX_UniqueChildFolders'")) + _MyLog.Error("Folder.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + MarkOld(); + } + if (_FolderAssignments != null) _FolderAssignments.Update(this); + if (_FolderDocVersions != null) _FolderDocVersions.Update(this); + if (_ChildFolders != null) _ChildFolders.Update(this); + } + internal void DeleteSelf(Folder folder) + { + // 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"]; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateFolder"; + // Input All Fields - Except Calculated Columns + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Update", ex); + throw new DbCslaException("Folder.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_FolderID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteFolder"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteFolder"; + // Input PK Fields + cm.Parameters.AddWithValue("@FolderID", folderID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Remove", ex); + throw new DbCslaException("Folder.Remove", ex); + } + } - [Transactional(TransactionalTypes.TransactionScope)] - public static void DeleteFolderAdmin(int folderID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Remove", 0); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteFolderAdmin"; - cm.Parameters.AddWithValue("@FolderID", folderID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Remove", ex); - throw new DbCslaException("Folder.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int folderID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(folderID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _FolderID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int folderID) - { - _FolderID = folderID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsFolder"; - cm.Parameters.AddWithValue("@FolderID", _FolderID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Execute", ex); - throw new DbCslaException("Folder.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - FolderExtension _FolderExtension = new FolderExtension(); - [Serializable()] - partial class FolderExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FolderConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Folder) - { - // Return the ToString value - return ((Folder)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + [Transactional(TransactionalTypes.TransactionScope)] + public static void DeleteFolderAdmin(int folderID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Remove", 0); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteFolderAdmin"; + cm.Parameters.AddWithValue("@FolderID", folderID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Remove", ex); + throw new DbCslaException("Folder.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int folderID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(folderID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _FolderID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int folderID) + { + _FolderID = folderID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsFolder"; + cm.Parameters.AddWithValue("@FolderID", _FolderID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Execute", ex); + throw new DbCslaException("Folder.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + FolderExtension _FolderExtension = new FolderExtension(); + [Serializable()] + partial class FolderExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FolderConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Folder) + { + // Return the ToString value + return ((Folder)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignment.cs index 66421b1e..c0ac2e5f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderAssignment.cs @@ -20,683 +20,658 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FolderAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderAssignmentConverter))] - public partial class FolderAssignment : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - if (_MyAssignment != null) _AID = _MyAssignment.AID; - return _AID; - } - } - private Assignment _MyAssignment; - [System.ComponentModel.DataObjectField(true, true)] - public Assignment MyAssignment - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssignment", true); - if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); - return _MyAssignment; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - _GID = value.GID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private Role _MyRole; - public Role MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); - return _MyRole; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRole", true); - if (_MyRole != value) - { - _MyRole = value; - _RID = value.RID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Group_GroupName = string.Empty; - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupName", true); - return _Group_GroupName; - } - } - private int? _Group_GroupType; - public int? Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupType", true); - return _Group_GroupType; - } - } - private string _Group_Config = string.Empty; - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_Config", true); - return _Group_Config; - } - } - private DateTime _Group_DTS = new DateTime(); - public DateTime Group_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_DTS", true); - return _Group_DTS; - } - } - private string _Group_UsrID = string.Empty; - public string Group_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_UsrID", true); - return _Group_UsrID; - } - } - private string _Role_Name = string.Empty; - public string Role_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Name", true); - return _Role_Name; - } - } - private string _Role_Title = string.Empty; - public string Role_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Title", true); - return _Role_Title; - } - } - private DateTime _Role_DTS = new DateTime(); - public DateTime Role_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_DTS", true); - return _Role_DTS; - } - } - private string _Role_UsrID = string.Empty; - public string Role_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_UsrID", true); - return _Role_UsrID; - } - } - // CSLATODO: Check FolderAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderAssignment - protected override object GetIdValue() - { - return MyFolderAssignmentUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base FolderAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyRole == null ? true : _MyRole.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule(MyRoleRequired, "MyRole"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyGroupRequired(FolderAssignment target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyRoleRequired(FolderAssignment target, Csla.Validation.RuleArgs e) - { - if (target._RID == 0 && target._MyRole == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowWrite(RID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - 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); - } - public FolderAssignment() - { - MarkAsChild(); - _AID = Assignment.NextAID; - _StartDate = _FolderAssignmentExtension.DefaultStartDate; - _DTS = _FolderAssignmentExtension.DefaultDTS; - _UsrID = _FolderAssignmentExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private FolderAssignment(Group myGroup, Role myRole) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _AID = Assignment.NextAID; - _StartDate = _FolderAssignmentExtension.DefaultStartDate; - _DTS = _FolderAssignmentExtension.DefaultDTS; - _UsrID = _FolderAssignmentExtension.DefaultUsrID; - _MyGroup = myGroup; - _MyRole = myRole; - ValidationRules.CheckRules(); - } - internal FolderAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~FolderAssignment() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderAssignment.FetchDR", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _GID = dr.GetInt32("GID"); - _RID = dr.GetInt32("RID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Group_GroupName = dr.GetString("Group_GroupName"); - _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); - _Group_Config = dr.GetString("Group_Config"); - _Group_DTS = dr.GetDateTime("Group_DTS"); - _Group_UsrID = dr.GetString("Group_UsrID"); - _Role_Name = dr.GetString("Role_Name"); - _Role_Title = dr.GetString("Role_Title"); - _Role_DTS = dr.GetDateTime("Role_DTS"); - _Role_UsrID = dr.GetString("Role_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderAssignment.FetchDR", ex); - throw new DbCslaException("FolderAssignment.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - internal void DeleteSelf(Folder myFolder) - { - // 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension(); - [Serializable()] - partial class FolderAssignmentExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FolderAssignmentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FolderAssignment) - { - // Return the ToString value - return ((FolderAssignment)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FolderAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderAssignmentConverter))] + public partial class FolderAssignment : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment != null) _AID = _MyAssignment.AID; + return _AID; + } + } + private Assignment _MyAssignment; + [System.ComponentModel.DataObjectField(true, true)] + public Assignment MyAssignment + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); + return _MyAssignment; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + _GID = value.GID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private Role _MyRole; + public Role MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); + return _MyRole; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRole != value) + { + _MyRole = value; + _RID = value.RID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Group_GroupName = string.Empty; + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupName; + } + } + private int? _Group_GroupType; + public int? Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupType; + } + } + private string _Group_Config = string.Empty; + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_Config; + } + } + private DateTime _Group_DTS = new DateTime(); + public DateTime Group_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_DTS; + } + } + private string _Group_UsrID = string.Empty; + public string Group_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_UsrID; + } + } + private string _Role_Name = string.Empty; + public string Role_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Name; + } + } + private string _Role_Title = string.Empty; + public string Role_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Title; + } + } + private DateTime _Role_DTS = new DateTime(); + public DateTime Role_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_DTS; + } + } + private string _Role_UsrID = string.Empty; + public string Role_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_UsrID; + } + } + // CSLATODO: Check FolderAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderAssignment + protected override object GetIdValue() + { + return MyFolderAssignmentUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base FolderAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyRole == null ? true : _MyRole.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule(MyRoleRequired, "MyRole"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyGroupRequired(FolderAssignment target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyRoleRequired(FolderAssignment target, Csla.Validation.RuleArgs e) + { + if (target._RID == 0 && target._MyRole == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowWrite(RID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + 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); + } + public FolderAssignment() + { + MarkAsChild(); + _AID = Assignment.NextAID; + _StartDate = _FolderAssignmentExtension.DefaultStartDate; + _DTS = _FolderAssignmentExtension.DefaultDTS; + _UsrID = _FolderAssignmentExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private FolderAssignment(Group myGroup, Role myRole) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _AID = Assignment.NextAID; + _StartDate = _FolderAssignmentExtension.DefaultStartDate; + _DTS = _FolderAssignmentExtension.DefaultDTS; + _UsrID = _FolderAssignmentExtension.DefaultUsrID; + _MyGroup = myGroup; + _MyRole = myRole; + ValidationRules.CheckRules(); + } + internal FolderAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~FolderAssignment() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderAssignment.FetchDR", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _GID = dr.GetInt32("GID"); + _RID = dr.GetInt32("RID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Group_GroupName = dr.GetString("Group_GroupName"); + _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); + _Group_Config = dr.GetString("Group_Config"); + _Group_DTS = dr.GetDateTime("Group_DTS"); + _Group_UsrID = dr.GetString("Group_UsrID"); + _Role_Name = dr.GetString("Role_Name"); + _Role_Title = dr.GetString("Role_Title"); + _Role_DTS = dr.GetDateTime("Role_DTS"); + _Role_UsrID = dr.GetString("Role_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderAssignment.FetchDR", ex); + throw new DbCslaException("FolderAssignment.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + internal void DeleteSelf(Folder myFolder) + { + // 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension(); + [Serializable()] + partial class FolderAssignmentExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FolderAssignmentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderAssignment) + { + // Return the ToString value + return ((FolderAssignment)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs index b1edbc9f..6f7b15ed 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderDocVersion.cs @@ -20,565 +20,545 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FolderDocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderDocVersionConverter))] - public partial class FolderDocVersion : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyItem = value; - _ItemID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check FolderDocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderDocVersion - protected override object GetIdValue() - { - return MyFolderDocVersionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base FolderDocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderDocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public FolderDocVersion() - { - MarkAsChild(); - _VersionID = DocVersion.NextVersionID; - _VersionType = _FolderDocVersionExtension.DefaultVersionType; - _DTS = _FolderDocVersionExtension.DefaultDTS; - _UserID = _FolderDocVersionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private FolderDocVersion(string name) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _VersionID = DocVersion.NextVersionID; - _VersionType = _FolderDocVersionExtension.DefaultVersionType; - _DTS = _FolderDocVersionExtension.DefaultDTS; - _UserID = _FolderDocVersionExtension.DefaultUserID; - _Name = name; - ValidationRules.CheckRules(); - } - internal FolderDocVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~FolderDocVersion() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderDocVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderDocVersion.FetchDR", ex); - throw new DbCslaException("FolderDocVersion.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - internal void DeleteSelf(Folder myFolder) - { - // 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension(); - [Serializable()] - partial class FolderDocVersionExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FolderDocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FolderDocVersion) - { - // Return the ToString value - return ((FolderDocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FolderDocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderDocVersionConverter))] + public partial class FolderDocVersion : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyItem = value; + _ItemID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check FolderDocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderDocVersion + protected override object GetIdValue() + { + return MyFolderDocVersionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base FolderDocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderDocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public FolderDocVersion() + { + MarkAsChild(); + _VersionID = DocVersion.NextVersionID; + _VersionType = _FolderDocVersionExtension.DefaultVersionType; + _DTS = _FolderDocVersionExtension.DefaultDTS; + _UserID = _FolderDocVersionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private FolderDocVersion(string name) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _VersionID = DocVersion.NextVersionID; + _VersionType = _FolderDocVersionExtension.DefaultVersionType; + _DTS = _FolderDocVersionExtension.DefaultDTS; + _UserID = _FolderDocVersionExtension.DefaultUserID; + _Name = name; + ValidationRules.CheckRules(); + } + internal FolderDocVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~FolderDocVersion() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderDocVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderDocVersion.FetchDR", ex); + throw new DbCslaException("FolderDocVersion.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + internal void DeleteSelf(Folder myFolder) + { + // 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension(); + [Serializable()] + partial class FolderDocVersionExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FolderDocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderDocVersion) + { + // Return the ToString value + return ((FolderDocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs index ab16899c..f05c9869 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FolderInfo.cs @@ -19,648 +19,628 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void FolderInfoEvent(object sender); - /// - /// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderInfoConverter))] - public partial class FolderInfo : ReadOnlyBase, IDisposable - { - public event FolderInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(FolderInfo folderInfo) - { - if (!_CacheList.Contains(folderInfo)) _CacheList.Add(folderInfo); // In AddToCache - } - protected static void RemoveFromCache(FolderInfo folderInfo) - { - while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move FolderInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - FolderInfo tmp = _CacheList[0]; // Get the first FolderInfo - string pKey = tmp.FolderID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first FolderInfo - } - } - internal static void AddList(FolderInfoList lst) - { - foreach (FolderInfo item in lst) AddToCache(item); - } - protected static FolderInfo GetCachedByPrimaryKey(int folderID) - { - ConvertListToDictionary(); - string key = folderID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - return _FolderID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private FolderInfo _MyParent; - public FolderInfo MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = FolderInfo.Get(_ParentID); - return _MyParent; - } - } - private int _DBID; - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - if (_MyConnection != null) _DBID = _MyConnection.DBID; - return _DBID; - } - } - private ConnectionInfo _MyConnection; - public ConnectionInfo MyConnection - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyConnection", true); - if (_MyConnection == null && _DBID != 0) _MyConnection = ConnectionInfo.Get(_DBID); - return _MyConnection; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private FormatInfo _MyFormat; - public FormatInfo MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); - return _MyFormat; - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _FolderAssignmentCount = 0; - /// - /// Count of FolderAssignments for this Folder - /// - public int FolderAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignmentCount", true); - if (_FolderAssignmentCount < 0) - _FolderAssignmentCount = FolderAssignments.Count; - return _FolderAssignmentCount; - } - } - private AssignmentInfoList _FolderAssignments = null; - [TypeConverter(typeof(AssignmentInfoListConverter))] - public AssignmentInfoList FolderAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignments", true); - if (_FolderAssignmentCount < 0 || (_FolderAssignmentCount > 0 && _FolderAssignments == null)) - _FolderAssignments = AssignmentInfoList.GetByFolderID(_FolderID); - if (_FolderAssignmentCount < 0) - _FolderAssignmentCount = _FolderAssignments.Count; - return _FolderAssignments; - } - } - public void RefreshFolderAssignments() - { - _FolderAssignmentCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) - tmp._FolderAssignmentCount = -1; // This will cause the data to be requeried - } - private int _FolderDocVersionCount = 0; - /// - /// Count of FolderDocVersions for this Folder - /// - public int FolderDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersionCount", true); - if (_FolderDocVersionCount < 0) - _FolderDocVersionCount = FolderDocVersions.Count; - return _FolderDocVersionCount; - } - } - private DocVersionInfoList _FolderDocVersions = null; - [TypeConverter(typeof(DocVersionInfoListConverter))] - public DocVersionInfoList FolderDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersions", true); - if (_FolderDocVersionCount < 0 || (_FolderDocVersionCount > 0 && _FolderDocVersions == null)) - _FolderDocVersions = DocVersionInfoList.GetByFolderID(_FolderID); - if (_FolderDocVersionCount < 0) - _FolderDocVersionCount = _FolderDocVersions.Count; - return _FolderDocVersions; - } - } - public void RefreshFolderDocVersions() - { - _FolderDocVersionCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) - tmp._FolderDocVersionCount = -1; // This will cause the data to be requeried - } - private int _ChildFolderCount = 0; - /// - /// Count of ChildFolders for this Folder - /// - public int ChildFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolderCount", true); - if (_ChildFolderCount < 0) - _ChildFolderCount = ChildFolders.Count; - return _ChildFolderCount; - } - } - private FolderInfoList _ChildFolders = null; - [TypeConverter(typeof(FolderInfoListConverter))] - public FolderInfoList ChildFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolders", true); - if (_ChildFolderCount < 0 || (_ChildFolderCount > 0 && _ChildFolders == null)) - _ChildFolders = FolderInfoList.GetChildren(_FolderID); - if (_ChildFolderCount < 0) - _ChildFolderCount = _ChildFolders.Count; - return _ChildFolders; - } - } - public void RefreshChildFolders() - { - _ChildFolderCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) - 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 - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderInfo - protected override object GetIdValue() - { - return 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; } } - protected FolderInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~FolderInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) return; - List listFolderInfo = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items - while (listFolderInfo.Contains(this)) listFolderInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Folder tmp) - { - string key = tmp.FolderID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Folder tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - if (_DBID != tmp.DBID) - { - if (MyConnection != null) 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 - _Name = tmp.Name; - _Title = tmp.Title; - _ShortName = tmp.ShortName; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _ManualOrder = tmp.ManualOrder; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _FolderInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ConnectionFolder tmp) - { - string key = tmp.FolderID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ConnectionFolder tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - _Name = tmp.Name; - _Title = tmp.Title; - _ShortName = tmp.ShortName; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _ManualOrder = tmp.ManualOrder; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _FolderInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(FormatFolder tmp) - { - string key = tmp.FolderID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FormatFolder tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - if (_DBID != tmp.DBID) - { - if (MyConnection != null) 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 - _Name = tmp.Name; - _Title = tmp.Title; - _ShortName = tmp.ShortName; - _ManualOrder = tmp.ManualOrder; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _FolderInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(folderID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up FolderInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on FolderInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal FolderInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.Constructor", ex); - throw new DbCslaException("FolderInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _FolderID; - public int FolderID - { get { return _FolderID; } } - public PKCriteria(int folderID) - { - _FolderID = folderID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.ReadData", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _FormatID = (int?)dr.GetValue("FormatID"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); - _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); - _ChildFolderCount = dr.GetInt32("ChildCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FolderInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFolder"; - cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FolderInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension(); - [Serializable()] - partial class FolderInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(FolderInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class FolderInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FolderInfo) - { - // Return the ToString value - return ((FolderInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void FolderInfoEvent(object sender); + /// + /// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderInfoConverter))] + public partial class FolderInfo : ReadOnlyBase, IDisposable + { + public event FolderInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(FolderInfo folderInfo) + { + if (!_CacheList.Contains(folderInfo)) _CacheList.Add(folderInfo); // In AddToCache + } + protected static void RemoveFromCache(FolderInfo folderInfo) + { + while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move FolderInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + FolderInfo tmp = _CacheList[0]; // Get the first FolderInfo + string pKey = tmp.FolderID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first FolderInfo + } + } + internal static void AddList(FolderInfoList lst) + { + foreach (FolderInfo item in lst) AddToCache(item); + } + protected static FolderInfo GetCachedByPrimaryKey(int folderID) + { + ConvertListToDictionary(); + string key = folderID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private FolderInfo _MyParent; + public FolderInfo MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = FolderInfo.Get(_ParentID); + return _MyParent; + } + } + private int _DBID; + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection != null) _DBID = _MyConnection.DBID; + return _DBID; + } + } + private ConnectionInfo _MyConnection; + public ConnectionInfo MyConnection + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection == null && _DBID != 0) _MyConnection = ConnectionInfo.Get(_DBID); + return _MyConnection; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private FormatInfo _MyFormat; + public FormatInfo MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); + return _MyFormat; + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _FolderAssignmentCount = 0; + /// + /// Count of FolderAssignments for this Folder + /// + public int FolderAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderAssignmentCount < 0) + _FolderAssignmentCount = FolderAssignments.Count; + return _FolderAssignmentCount; + } + } + private AssignmentInfoList _FolderAssignments = null; + [TypeConverter(typeof(AssignmentInfoListConverter))] + public AssignmentInfoList FolderAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderAssignmentCount < 0 || (_FolderAssignmentCount > 0 && _FolderAssignments == null)) + _FolderAssignments = AssignmentInfoList.GetByFolderID(_FolderID); + if (_FolderAssignmentCount < 0) + _FolderAssignmentCount = _FolderAssignments.Count; + return _FolderAssignments; + } + } + public void RefreshFolderAssignments() + { + _FolderAssignmentCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) + tmp._FolderAssignmentCount = -1; // This will cause the data to be requeried + } + private int _FolderDocVersionCount = 0; + /// + /// Count of FolderDocVersions for this Folder + /// + public int FolderDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderDocVersionCount < 0) + _FolderDocVersionCount = FolderDocVersions.Count; + return _FolderDocVersionCount; + } + } + private DocVersionInfoList _FolderDocVersions = null; + [TypeConverter(typeof(DocVersionInfoListConverter))] + public DocVersionInfoList FolderDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderDocVersionCount < 0 || (_FolderDocVersionCount > 0 && _FolderDocVersions == null)) + _FolderDocVersions = DocVersionInfoList.GetByFolderID(_FolderID); + if (_FolderDocVersionCount < 0) + _FolderDocVersionCount = _FolderDocVersions.Count; + return _FolderDocVersions; + } + } + public void RefreshFolderDocVersions() + { + _FolderDocVersionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) + tmp._FolderDocVersionCount = -1; // This will cause the data to be requeried + } + private int _ChildFolderCount = 0; + /// + /// Count of ChildFolders for this Folder + /// + public int ChildFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFolderCount < 0) + _ChildFolderCount = ChildFolders.Count; + return _ChildFolderCount; + } + } + private FolderInfoList _ChildFolders = null; + [TypeConverter(typeof(FolderInfoListConverter))] + public FolderInfoList ChildFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFolderCount < 0 || (_ChildFolderCount > 0 && _ChildFolders == null)) + _ChildFolders = FolderInfoList.GetChildren(_FolderID); + if (_ChildFolderCount < 0) + _ChildFolderCount = _ChildFolders.Count; + return _ChildFolders; + } + } + public void RefreshChildFolders() + { + _ChildFolderCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + 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 + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderInfo + protected override object GetIdValue() + { + return 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; } } + protected FolderInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~FolderInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) return; + List listFolderInfo = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items + while (listFolderInfo.Contains(this)) listFolderInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Folder tmp) + { + string key = tmp.FolderID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Folder tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + if (_DBID != tmp.DBID) + { + if (MyConnection != null) 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 + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _ManualOrder = tmp.ManualOrder; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ConnectionFolder tmp) + { + string key = tmp.FolderID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ConnectionFolder tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _ManualOrder = tmp.ManualOrder; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(FormatFolder tmp) + { + string key = tmp.FolderID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FormatFolder tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + if (_DBID != tmp.DBID) + { + if (MyConnection != null) 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 + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + _ManualOrder = tmp.ManualOrder; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(folderID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FolderInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal FolderInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.Constructor", ex); + throw new DbCslaException("FolderInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _FolderID; + public int FolderID + { get { return _FolderID; } } + public PKCriteria(int folderID) + { + _FolderID = folderID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.ReadData", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); + _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); + _ChildFolderCount = dr.GetInt32("ChildCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FolderInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolder"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FolderInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension(); + [Serializable()] + partial class FolderInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(FolderInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class FolderInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderInfo) + { + // Return the ToString value + return ((FolderInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs index a0d0be3f..db2c8869 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs @@ -20,1500 +20,1474 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Format Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatConverter))] - public partial class Format : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshFormats = new List(); - private List _RefreshFormatContents = new List(); - private List _RefreshFormatDocVersions = new List(); - private List _RefreshFormatFolders = new List(); - private void AddToRefreshList(List refreshFormats, List refreshFormatContents, List refreshFormatDocVersions, List refreshFormatFolders) - { - if (IsDirty) - refreshFormats.Add(this); - if (_FormatContents != null && _FormatContents.IsDirty) - { - foreach (FormatContent tmp in _FormatContents) - { - if (tmp.IsDirty) refreshFormatContents.Add(tmp); - } - } - if (_FormatDocVersions != null && _FormatDocVersions.IsDirty) - { - foreach (FormatDocVersion tmp in _FormatDocVersions) - { - if (tmp.IsDirty) refreshFormatDocVersions.Add(tmp); - } - } - if (_FormatFolders != null && _FormatFolders.IsDirty) - { - foreach (FormatFolder tmp in _FormatFolders) - { - if (tmp.IsDirty) refreshFormatFolders.Add(tmp); - } - } - if (_ChildFormats != null && _ChildFormats.IsDirty) - { - foreach (Format tmp in _ChildFormats) - { - tmp.AddToRefreshList(refreshFormats, refreshFormatContents, refreshFormatDocVersions, refreshFormatFolders); - } - } - } - private void ClearRefreshList() - { - _RefreshFormats = new List(); - _RefreshFormatContents = new List(); - _RefreshFormatDocVersions = new List(); - _RefreshFormatFolders = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshFormats, _RefreshFormatContents, _RefreshFormatDocVersions, _RefreshFormatFolders); - } - private void ProcessRefreshList() - { - foreach (Format tmp in _RefreshFormats) - { - FormatInfo.Refresh(tmp); - } - foreach (FormatContent tmp in _RefreshFormatContents) - { - ContentInfo.Refresh(tmp); - } - foreach (FormatDocVersion tmp in _RefreshFormatDocVersions) - { - DocVersionInfo.Refresh(tmp); - } - foreach (FormatFolder tmp in _RefreshFormatFolders) - { - FolderInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Format format) - { - if (!_CacheList.Contains(format)) _CacheList.Add(format); // In AddToCache - } - protected static void RemoveFromCache(Format format) - { - while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByParentID_Name = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Format(s) from temporary _CacheList to _CacheByPrimaryKey - { - Format tmp = _CacheList[0]; // Get the first Format - string pKey = tmp.FormatID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first Format - } - } - protected static Format GetCachedByPrimaryKey(int formatID) - { - ConvertListToDictionary(); - string key = formatID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Format GetCachedByParentID_Name(int parentID, string name) - { - ConvertListToDictionary(); - string key = parentID.ToString() + "_" + name.ToString(); - if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextFormatID = -1; - public static int NextFormatID - { - get { return _nextFormatID--; } - } - private int _FormatID; - [System.ComponentModel.DataObjectField(true, true)] - public int FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FormatID; - return _ParentID; - } - } - private Format _MyParent; - public Format MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FormatID) _MyParent = Format.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - _ParentID = value.FormatID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Description = string.Empty; - public string Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Description", true); - return _Description; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Description", true); - if (value == null) value = string.Empty; - if (_Description != value) - { - _Description = value; - PropertyHasChanged(); - } - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Data", true); - if (value == null) value = string.Empty; - if (_Data != value) - { - _Data = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private string _GenMac = string.Empty; - public string GenMac - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GenMac", true); - return _GenMac; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("GenMac", true); - if (value == null) value = string.Empty; - if (_GenMac != value) - { - _GenMac = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _FormatContentCount = 0; - /// - /// Count of FormatContents for this Format - /// - public int FormatContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContentCount", true); - return _FormatContentCount; - } - } - private FormatContents _FormatContents = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FormatContentsConverter))] - public FormatContents FormatContents - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContents", true); - if (_FormatContentCount < 0 || (_FormatContentCount > 0 && _FormatContents == null)) - _FormatContents = FormatContents.GetByFormatID(FormatID); - if (_FormatContentCount < 0 ) - _FormatContentCount = _FormatContents == null ? 0 : _FormatContents.Count; - if (_FormatContents == null) - _FormatContents = FormatContents.New(); - return _FormatContents; - } - } - public void Reset_FormatContents() - { - _FormatContentCount = -1; - } - private int _FormatDocVersionCount = 0; - /// - /// Count of FormatDocVersions for this Format - /// - public int FormatDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersionCount", true); - return _FormatDocVersionCount; - } - } - private FormatDocVersions _FormatDocVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FormatDocVersionsConverter))] - public FormatDocVersions FormatDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersions", true); - if (_FormatDocVersionCount < 0 || (_FormatDocVersionCount > 0 && _FormatDocVersions == null)) - _FormatDocVersions = FormatDocVersions.GetByFormatID(FormatID); - if (_FormatDocVersionCount < 0 ) - _FormatDocVersionCount = _FormatDocVersions == null ? 0 : _FormatDocVersions.Count; - if (_FormatDocVersions == null) - _FormatDocVersions = FormatDocVersions.New(); - return _FormatDocVersions; - } - } - public void Reset_FormatDocVersions() - { - _FormatDocVersionCount = -1; - } - private int _FormatFolderCount = 0; - /// - /// Count of FormatFolders for this Format - /// - public int FormatFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolderCount", true); - return _FormatFolderCount; - } - } - private FormatFolders _FormatFolders = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FormatFoldersConverter))] - public FormatFolders FormatFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolders", true); - if (_FormatFolderCount < 0 || (_FormatFolderCount > 0 && _FormatFolders == null)) - _FormatFolders = FormatFolders.GetByFormatID(FormatID); - if (_FormatFolderCount < 0 ) - _FormatFolderCount = _FormatFolders == null ? 0 : _FormatFolders.Count; - if (_FormatFolders == null) - _FormatFolders = FormatFolders.New(); - return _FormatFolders; - } - } - public void Reset_FormatFolders() - { - _FormatFolderCount = -1; - } - private int _ChildFormatCount = 0; - /// - /// Count of ChildFormats for this Format - /// - public int ChildFormatCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormatCount", true); - return _ChildFormatCount; - } - } - private ChildFormats _ChildFormats = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ChildFormatsConverter))] - public ChildFormats ChildFormats - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormats", true); - if (_ChildFormatCount < 0 || (_ChildFormatCount > 0 && _ChildFormats == null)) - _ChildFormats = ChildFormats.GetByParentID(FormatID); - if (_ChildFormatCount < 0 ) - _ChildFormatCount = _ChildFormats == null ? 0 : _ChildFormats.Count; - if (_ChildFormats == null) - _ChildFormats = ChildFormats.New(); - return _ChildFormats; - } - } - public void Reset_ChildFormats() - { - _ChildFormatCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : 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)); - } - // CSLATODO: Replace base Format.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Format - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Format.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Format - protected override object GetIdValue() - { - return MyFormatUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_FormatFolders != null && (hasBrokenRules = _FormatFolders.HasBrokenRules) != null) return hasBrokenRules; - if (_FormatContents != null && (hasBrokenRules = _FormatContents.HasBrokenRules) != null) return hasBrokenRules; - if (_FormatDocVersions != null && (hasBrokenRules = _FormatDocVersions.HasBrokenRules) != null) return hasBrokenRules; - if (_ChildFormats != null && (hasBrokenRules = _ChildFormats.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 250)); + /// + /// Format Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatConverter))] + public partial class Format : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshFormats = new List(); + private List _RefreshFormatContents = new List(); + private List _RefreshFormatDocVersions = new List(); + private List _RefreshFormatFolders = new List(); + private void AddToRefreshList(List refreshFormats, List refreshFormatContents, List refreshFormatDocVersions, List refreshFormatFolders) + { + if (IsDirty) + refreshFormats.Add(this); + if (_FormatContents != null && _FormatContents.IsDirty) + { + foreach (FormatContent tmp in _FormatContents) + { + if (tmp.IsDirty) refreshFormatContents.Add(tmp); + } + } + if (_FormatDocVersions != null && _FormatDocVersions.IsDirty) + { + foreach (FormatDocVersion tmp in _FormatDocVersions) + { + if (tmp.IsDirty) refreshFormatDocVersions.Add(tmp); + } + } + if (_FormatFolders != null && _FormatFolders.IsDirty) + { + foreach (FormatFolder tmp in _FormatFolders) + { + if (tmp.IsDirty) refreshFormatFolders.Add(tmp); + } + } + if (_ChildFormats != null && _ChildFormats.IsDirty) + { + foreach (Format tmp in _ChildFormats) + { + tmp.AddToRefreshList(refreshFormats, refreshFormatContents, refreshFormatDocVersions, refreshFormatFolders); + } + } + } + private void ClearRefreshList() + { + _RefreshFormats = new List(); + _RefreshFormatContents = new List(); + _RefreshFormatDocVersions = new List(); + _RefreshFormatFolders = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshFormats, _RefreshFormatContents, _RefreshFormatDocVersions, _RefreshFormatFolders); + } + private void ProcessRefreshList() + { + foreach (Format tmp in _RefreshFormats) + { + FormatInfo.Refresh(tmp); + } + foreach (FormatContent tmp in _RefreshFormatContents) + { + ContentInfo.Refresh(tmp); + } + foreach (FormatDocVersion tmp in _RefreshFormatDocVersions) + { + DocVersionInfo.Refresh(tmp); + } + foreach (FormatFolder tmp in _RefreshFormatFolders) + { + FolderInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Format format) + { + if (!_CacheList.Contains(format)) _CacheList.Add(format); // In AddToCache + } + protected static void RemoveFromCache(Format format) + { + while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByParentID_Name = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Format(s) from temporary _CacheList to _CacheByPrimaryKey + { + Format tmp = _CacheList[0]; // Get the first Format + string pKey = tmp.FormatID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first Format + } + } + protected static Format GetCachedByPrimaryKey(int formatID) + { + ConvertListToDictionary(); + string key = formatID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Format GetCachedByParentID_Name(int parentID, string name) + { + ConvertListToDictionary(); + string key = parentID.ToString() + "_" + name.ToString(); + if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextFormatID = -1; + public static int NextFormatID + { + get { return _nextFormatID--; } + } + private int _FormatID; + [System.ComponentModel.DataObjectField(true, true)] + public int FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FormatID; + return _ParentID; + } + } + private Format _MyParent; + public Format MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FormatID) _MyParent = Format.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + _ParentID = value.FormatID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Description; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Description != value) + { + _Description = value; + PropertyHasChanged(); + } + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Data != value) + { + _Data = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private string _GenMac = string.Empty; + public string GenMac + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GenMac; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_GenMac != value) + { + _GenMac = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _FormatContentCount = 0; + /// + /// Count of FormatContents for this Format + /// + public int FormatContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatContentCount; + } + } + private FormatContents _FormatContents = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FormatContentsConverter))] + public FormatContents FormatContents + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatContentCount < 0 || (_FormatContentCount > 0 && _FormatContents == null)) + _FormatContents = FormatContents.GetByFormatID(FormatID); + if (_FormatContentCount < 0) + _FormatContentCount = _FormatContents == null ? 0 : _FormatContents.Count; + if (_FormatContents == null) + _FormatContents = FormatContents.New(); + return _FormatContents; + } + } + public void Reset_FormatContents() + { + _FormatContentCount = -1; + } + private int _FormatDocVersionCount = 0; + /// + /// Count of FormatDocVersions for this Format + /// + public int FormatDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatDocVersionCount; + } + } + private FormatDocVersions _FormatDocVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FormatDocVersionsConverter))] + public FormatDocVersions FormatDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatDocVersionCount < 0 || (_FormatDocVersionCount > 0 && _FormatDocVersions == null)) + _FormatDocVersions = FormatDocVersions.GetByFormatID(FormatID); + if (_FormatDocVersionCount < 0) + _FormatDocVersionCount = _FormatDocVersions == null ? 0 : _FormatDocVersions.Count; + if (_FormatDocVersions == null) + _FormatDocVersions = FormatDocVersions.New(); + return _FormatDocVersions; + } + } + public void Reset_FormatDocVersions() + { + _FormatDocVersionCount = -1; + } + private int _FormatFolderCount = 0; + /// + /// Count of FormatFolders for this Format + /// + public int FormatFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatFolderCount; + } + } + private FormatFolders _FormatFolders = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FormatFoldersConverter))] + public FormatFolders FormatFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatFolderCount < 0 || (_FormatFolderCount > 0 && _FormatFolders == null)) + _FormatFolders = FormatFolders.GetByFormatID(FormatID); + if (_FormatFolderCount < 0) + _FormatFolderCount = _FormatFolders == null ? 0 : _FormatFolders.Count; + if (_FormatFolders == null) + _FormatFolders = FormatFolders.New(); + return _FormatFolders; + } + } + public void Reset_FormatFolders() + { + _FormatFolderCount = -1; + } + private int _ChildFormatCount = 0; + /// + /// Count of ChildFormats for this Format + /// + public int ChildFormatCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ChildFormatCount; + } + } + private ChildFormats _ChildFormats = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ChildFormatsConverter))] + public ChildFormats ChildFormats + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFormatCount < 0 || (_ChildFormatCount > 0 && _ChildFormats == null)) + _ChildFormats = ChildFormats.GetByParentID(FormatID); + if (_ChildFormatCount < 0) + _ChildFormatCount = _ChildFormats == null ? 0 : _ChildFormats.Count; + if (_ChildFormats == null) + _ChildFormats = ChildFormats.New(); + return _ChildFormats; + } + } + public void Reset_ChildFormats() + { + _ChildFormatCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : 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)); + } + // CSLATODO: Replace base Format.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Format + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Format.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Format + protected override object GetIdValue() + { + return MyFormatUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_FormatFolders != null && (hasBrokenRules = _FormatFolders.HasBrokenRules) != null) return hasBrokenRules; + if (_FormatContents != null && (hasBrokenRules = _FormatContents.HasBrokenRules) != null) return hasBrokenRules; + if (_FormatDocVersions != null && (hasBrokenRules = _FormatDocVersions.HasBrokenRules) != null) return hasBrokenRules; + if (_ChildFormats != null && (hasBrokenRules = _ChildFormats.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + 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)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("GenMac", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _FormatExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Description, ""); - //AuthorizationRules.AllowRead(Data, ""); - //AuthorizationRules.AllowRead(GenMac, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Description, ""); - //AuthorizationRules.AllowWrite(Data, ""); - //AuthorizationRules.AllowWrite(GenMac, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _FormatExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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; } } - 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 Format() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Format() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) - { - List listFormat = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items - while (listFormat.Contains(this)) listFormat.Remove(this); // Remove the item from the list - if (listFormat.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByParentID_Name.Keys) - if (_CacheByParentID_Name[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listFormat = _CacheByParentID_Name[myKey]; // Get the list of items - listFormat.Remove(this); // Remove the item from the list - if (listFormat.Count == 0) //If there are no items left in the list - _CacheByParentID_Name.Remove(myKey); // remove the list - } - } - public static Format New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Format"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.New", ex); - } - } - public static Format New(Format myParent, string name, string data) - { - Format tmp = Format.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.Data = data; - return tmp; - } - public static Format New(Format myParent, string name, string description, string data, string config, string genMac, DateTime dts, string userID) - { - Format tmp = Format.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.Description = description; - tmp.Data = data; - tmp.Config = config; - tmp.GenMac = genMac; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) - { - Format tmp = Format.New(myParent, name, description, data, null, genMac, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Format New(Format myParent, string name, string description, string data, string config, string genMac) - { - Format tmp = Format.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.Description = description; - tmp.Data = data; - tmp.Config = config; - tmp.GenMac = genMac; - return tmp; - } - public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac) - { - Format tmp = Format.New(myParent, name, description, data, null, genMac); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(formatID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Format - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.Get", ex); - } - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Format - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.GetByParentID_Name", ex); - } - } - public static Format Get(SafeDataReader dr, Format parent) - { - if (dr.Read()) return new Format(dr, parent); - return null; - } - internal Format(SafeDataReader dr) - { - ReadData(dr); - } - private Format(SafeDataReader dr, Format parent) - { - ReadData(dr); - MarkAsChild(); - } - internal Format(SafeDataReader dr, int parentID) - { - ReadData(dr); - MarkAsChild(); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.Delete", ex); - } - } - 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(); - Format format = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(format);//Refresh the item in AllList - ProcessRefreshList(); - return format; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _FormatID; - public int FormatID - { get { return _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; } } - public ParentID_NameCriteria(int parentID, string name) - { - _ParentID = parentID; - _Name = name; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _FormatID = NextFormatID; - // Database Defaults - _ParentID = _FormatExtension.DefaultParentID; - _DTS = _FormatExtension.DefaultDTS; - _UserID = _FormatExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - public static string Failed - { - get { return FormatInfo._Failed; } - set { FormatInfo._Failed = value; } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.ReadData", GetHashCode()); - try - { - _FormatID = dr.GetInt32("FormatID"); - _ParentID = dr.GetInt32("ParentID"); - _Name = dr.GetString("Name"); - _Description = dr.GetString("Description"); - _Data = dr.GetString("Data"); - try // B2019-107 Added Error Handling for missing Config field - { - _Config = dr.GetString("Config"); - } - catch(Exception ex) - { - if (Failed==null) - { - Failed = string.Format("\r\n*** PromsFixes.SQL may not be up to date - {0} - {1}", ex.GetType().Name, ex.Message); - } - } - _GenMac = dr.GetString("GenMac"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _FormatContentCount = dr.GetInt32("ContentCount"); - _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); - _FormatFolderCount = dr.GetInt32("FolderCount"); - _ChildFormatCount = dr.GetInt32("ChildCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFormat"; - cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _FormatContents = FormatContents.Get(dr); - // load child objects - dr.NextResult(); - _FormatDocVersions = FormatDocVersions.Get(dr); - // load child objects - dr.NextResult(); - _FormatFolders = FormatFolders.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(ParentID_NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFormatByParentID_Name"; - cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); - cm.Parameters.AddWithValue("@Name", criteria.Name); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - 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); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myParent.FormatID); - 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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Add", ex); - throw new DbCslaException("Format.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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); - 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; - } - } - 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - } - internal void DeleteSelf(Format format) - { - // 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"]; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateFormat"; - // Input All Fields - Except Calculated Columns - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteFormat"; - cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteFormat"; - // Input PK Fields - cm.Parameters.AddWithValue("@FormatID", formatID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Remove", ex); - throw new DbCslaException("Format.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int formatID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(formatID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _FormatID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int formatID) - { - _FormatID = formatID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsFormat"; - cm.Parameters.AddWithValue("@FormatID", _FormatID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Execute", ex); - throw new DbCslaException("Format.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - FormatExtension _FormatExtension = new FormatExtension(); - [Serializable()] - partial class FormatExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Format) - { - // Return the ToString value - return ((Format)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("GenMac", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _FormatExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Description, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(GenMac, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Description, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(GenMac, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _FormatExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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; } } + 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 Format() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Format() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) + { + List listFormat = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items + while (listFormat.Contains(this)) listFormat.Remove(this); // Remove the item from the list + if (listFormat.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByParentID_Name.Keys) + if (_CacheByParentID_Name[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listFormat = _CacheByParentID_Name[myKey]; // Get the list of items + listFormat.Remove(this); // Remove the item from the list + if (listFormat.Count == 0) //If there are no items left in the list + _CacheByParentID_Name.Remove(myKey); // remove the list + } + } + public static Format New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Format"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.New", ex); + } + } + public static Format New(Format myParent, string name, string data) + { + Format tmp = Format.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.Data = data; + return tmp; + } + public static Format New(Format myParent, string name, string description, string data, string config, string genMac, DateTime dts, string userID) + { + Format tmp = Format.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.Description = description; + tmp.Data = data; + tmp.Config = config; + tmp.GenMac = genMac; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) + { + Format tmp = Format.New(myParent, name, description, data, null, genMac, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Format New(Format myParent, string name, string description, string data, string config, string genMac) + { + Format tmp = Format.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.Description = description; + tmp.Data = data; + tmp.Config = config; + tmp.GenMac = genMac; + return tmp; + } + public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac) + { + Format tmp = Format.New(myParent, name, description, data, null, genMac); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(formatID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Format + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.Get", ex); + } + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Format + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.GetByParentID_Name", ex); + } + } + public static Format Get(SafeDataReader dr, Format parent) + { + if (dr.Read()) return new Format(dr, parent); + return null; + } + internal Format(SafeDataReader dr) + { + ReadData(dr); + } + private Format(SafeDataReader dr, Format parent) + { + ReadData(dr); + MarkAsChild(); + } + internal Format(SafeDataReader dr, int parentID) + { + ReadData(dr); + MarkAsChild(); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.Delete", ex); + } + } + 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(); + Format format = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(format);//Refresh the item in AllList + ProcessRefreshList(); + return format; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _FormatID; + public int FormatID + { get { return _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; } } + public ParentID_NameCriteria(int parentID, string name) + { + _ParentID = parentID; + _Name = name; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _FormatID = NextFormatID; + // Database Defaults + _ParentID = _FormatExtension.DefaultParentID; + _DTS = _FormatExtension.DefaultDTS; + _UserID = _FormatExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + public static string Failed + { + get { return FormatInfo._Failed; } + set { FormatInfo._Failed = value; } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.ReadData", GetHashCode()); + try + { + _FormatID = dr.GetInt32("FormatID"); + _ParentID = dr.GetInt32("ParentID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _Data = dr.GetString("Data"); + try // B2019-107 Added Error Handling for missing Config field + { + _Config = dr.GetString("Config"); + } + catch (Exception ex) + { + if (Failed == null) + { + Failed = string.Format("\r\n*** PromsFixes.SQL may not be up to date - {0} - {1}", ex.GetType().Name, ex.Message); + } + } + _GenMac = dr.GetString("GenMac"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _FormatContentCount = dr.GetInt32("ContentCount"); + _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); + _FormatFolderCount = dr.GetInt32("FolderCount"); + _ChildFormatCount = dr.GetInt32("ChildCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormat"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _FormatContents = FormatContents.Get(dr); + // load child objects + dr.NextResult(); + _FormatDocVersions = FormatDocVersions.Get(dr); + // load child objects + dr.NextResult(); + _FormatFolders = FormatFolders.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(ParentID_NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormatByParentID_Name"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + cm.Parameters.AddWithValue("@Name", criteria.Name); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + 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); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myParent.FormatID); + 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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Add", ex); + throw new DbCslaException("Format.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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); + 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; + } + } + 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + } + internal void DeleteSelf(Format format) + { + // 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"]; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateFormat"; + // Input All Fields - Except Calculated Columns + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteFormat"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteFormat"; + // Input PK Fields + cm.Parameters.AddWithValue("@FormatID", formatID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Remove", ex); + throw new DbCslaException("Format.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int formatID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(formatID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _FormatID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int formatID) + { + _FormatID = formatID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsFormat"; + cm.Parameters.AddWithValue("@FormatID", _FormatID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Execute", ex); + throw new DbCslaException("Format.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + FormatExtension _FormatExtension = new FormatExtension(); + [Serializable()] + partial class FormatExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Format) + { + // Return the ToString value + return ((Format)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatContent.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatContent.cs index 1d1139eb..d70e2dde 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FormatContent.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatContent.cs @@ -20,476 +20,462 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FormatContent Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatContentConverter))] - public partial class FormatContent : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private string _Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Number", true); - if (value == null) value = string.Empty; - if (_Number != value) - { - _Number = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private int? _Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Type", true); - if (_Type != value) - { - _Type = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check FormatContent.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatContent - protected override object GetIdValue() - { - return MyFormatContentUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base FormatContent.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatContent - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 256)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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, ""); - //AuthorizationRules.AllowRead(Number, ""); - //AuthorizationRules.AllowWrite(Number, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowRead(Type, ""); - //AuthorizationRules.AllowWrite(Type, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public FormatContent() - { - MarkAsChild(); - _ContentID = Content.NextContentID; - _DTS = _FormatContentExtension.DefaultDTS; - _UserID = _FormatContentExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - internal FormatContent(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~FormatContent() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatContent.FetchDR", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatContent.FetchDR", ex); - throw new DbCslaException("FormatContent.Fetch", ex); - } - MarkOld(); - } - 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 = 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); - MarkOld(); - } - 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FormatContentExtension _FormatContentExtension = new FormatContentExtension(); - [Serializable()] - partial class FormatContentExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatContentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatContent) - { - // Return the ToString value - return ((FormatContent)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FormatContent Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatContentConverter))] + public partial class FormatContent : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private string _Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Number != value) + { + _Number = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private int? _Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Type != value) + { + _Type = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check FormatContent.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatContent + protected override object GetIdValue() + { + return MyFormatContentUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base FormatContent.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatContent + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 256)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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, ""); + //AuthorizationRules.AllowRead(Number, ""); + //AuthorizationRules.AllowWrite(Number, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowRead(Type, ""); + //AuthorizationRules.AllowWrite(Type, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public FormatContent() + { + MarkAsChild(); + _ContentID = Content.NextContentID; + _DTS = _FormatContentExtension.DefaultDTS; + _UserID = _FormatContentExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + internal FormatContent(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~FormatContent() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatContent.FetchDR", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatContent.FetchDR", ex); + throw new DbCslaException("FormatContent.Fetch", ex); + } + MarkOld(); + } + 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 = 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); + MarkOld(); + } + 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FormatContentExtension _FormatContentExtension = new FormatContentExtension(); + [Serializable()] + partial class FormatContentExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatContentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatContent) + { + // Return the ToString value + return ((FormatContent)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersion.cs index 0f6a05b7..76da2512 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatDocVersion.cs @@ -20,697 +20,667 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FormatDocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatDocVersionConverter))] - public partial class FormatDocVersion : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - _FolderID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyItem = value; - _ItemID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - // CSLATODO: Check FormatDocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatDocVersion - protected override object GetIdValue() - { - return MyFormatDocVersionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base FormatDocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatDocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyFolderRequired(FormatDocVersion target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public FormatDocVersion() - { - MarkAsChild(); - _VersionID = DocVersion.NextVersionID; - _VersionType = _FormatDocVersionExtension.DefaultVersionType; - _DTS = _FormatDocVersionExtension.DefaultDTS; - _UserID = _FormatDocVersionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private FormatDocVersion(Folder myFolder, string name) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _VersionID = DocVersion.NextVersionID; - _VersionType = _FormatDocVersionExtension.DefaultVersionType; - _DTS = _FormatDocVersionExtension.DefaultDTS; - _UserID = _FormatDocVersionExtension.DefaultUserID; - _MyFolder = myFolder; - _Name = name; - ValidationRules.CheckRules(); - } - internal FormatDocVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~FormatDocVersion() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatDocVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatDocVersion.FetchDR", ex); - throw new DbCslaException("FormatDocVersion.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - 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"]; - DocVersion.Remove(cn, _VersionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension(); - [Serializable()] - partial class FormatDocVersionExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatDocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatDocVersion) - { - // Return the ToString value - return ((FormatDocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FormatDocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatDocVersionConverter))] + public partial class FormatDocVersion : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + _FolderID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyItem = value; + _ItemID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + // CSLATODO: Check FormatDocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatDocVersion + protected override object GetIdValue() + { + return MyFormatDocVersionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base FormatDocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatDocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyFolderRequired(FormatDocVersion target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public FormatDocVersion() + { + MarkAsChild(); + _VersionID = DocVersion.NextVersionID; + _VersionType = _FormatDocVersionExtension.DefaultVersionType; + _DTS = _FormatDocVersionExtension.DefaultDTS; + _UserID = _FormatDocVersionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private FormatDocVersion(Folder myFolder, string name) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _VersionID = DocVersion.NextVersionID; + _VersionType = _FormatDocVersionExtension.DefaultVersionType; + _DTS = _FormatDocVersionExtension.DefaultDTS; + _UserID = _FormatDocVersionExtension.DefaultUserID; + _MyFolder = myFolder; + _Name = name; + ValidationRules.CheckRules(); + } + internal FormatDocVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~FormatDocVersion() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatDocVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatDocVersion.FetchDR", ex); + throw new DbCslaException("FormatDocVersion.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + 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"]; + DocVersion.Remove(cn, _VersionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension(); + [Serializable()] + partial class FormatDocVersionExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatDocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatDocVersion) + { + // Return the ToString value + return ((FormatDocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolder.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolder.cs index 484d01e1..c9dfe407 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolder.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatFolder.cs @@ -20,710 +20,681 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FormatFolder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatFolderConverter))] - public partial class FormatFolder : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _FolderID; - [System.ComponentModel.DataObjectField(true, true)] - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - [System.ComponentModel.DataObjectField(true, true)] - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private Folder _MyParent; - public Folder MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - _ParentID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _DBID; - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - if (_MyConnection != null) _DBID = _MyConnection.DBID; - return _DBID; - } - } - private Connection _MyConnection; - public Connection MyConnection - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyConnection", true); - if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); - return _MyConnection; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyConnection", true); - if (_MyConnection != value) - { - _MyConnection = value; - _DBID = value.DBID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ShortName", true); - if (value == null) value = string.Empty; - if (_ShortName != value) - { - _ShortName = value; - PropertyHasChanged(); - } - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ManualOrder", true); - if (_ManualOrder != value) - { - _ManualOrder = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Connection_Name = string.Empty; - public string Connection_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_Name", true); - return _Connection_Name; - } - } - private string _Connection_Title = string.Empty; - public string Connection_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_Title", true); - return _Connection_Title; - } - } - private string _Connection_ConnectionString = string.Empty; - public string Connection_ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_ConnectionString", true); - return _Connection_ConnectionString; - } - } - private int _Connection_ServerType; - /// - /// 0 SQL Server - /// - public int Connection_ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_ServerType", true); - return _Connection_ServerType; - } - } - private string _Connection_Config = string.Empty; - public string Connection_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_Config", true); - return _Connection_Config; - } - } - private DateTime _Connection_DTS = new DateTime(); - public DateTime Connection_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_DTS", true); - return _Connection_DTS; - } - } - private string _Connection_UsrID = string.Empty; - public string Connection_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_UsrID", true); - return _Connection_UsrID; - } - } - // CSLATODO: Check FormatFolder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatFolder - protected override object GetIdValue() - { - return MyFormatFolderUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base FormatFolder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatFolder - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyConnection == null ? true : _MyConnection.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ShortName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyFolderRequired(FormatFolder target, Csla.Validation.RuleArgs e) - { - if (target._ParentID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyConnectionRequired(FormatFolder target, Csla.Validation.RuleArgs e) - { - if (target._DBID == 0 && target._MyConnection == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowRead(DBID, ""); - //AuthorizationRules.AllowWrite(DBID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ShortName, ""); - //AuthorizationRules.AllowWrite(ShortName, ""); - //AuthorizationRules.AllowRead(ManualOrder, ""); - //AuthorizationRules.AllowWrite(ManualOrder, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - 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); - } - public FormatFolder() - { - MarkAsChild(); - _FolderID = Folder.NextFolderID; - _ParentID = _FormatFolderExtension.DefaultParentID; - _DBID = _FormatFolderExtension.DefaultDBID; - _DTS = _FormatFolderExtension.DefaultDTS; - _UsrID = _FormatFolderExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private FormatFolder(Folder myParent, string name, string shortName) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _FolderID = Folder.NextFolderID; - _ParentID = _FormatFolderExtension.DefaultParentID; - _DBID = _FormatFolderExtension.DefaultDBID; - _DTS = _FormatFolderExtension.DefaultDTS; - _UsrID = _FormatFolderExtension.DefaultUsrID; - _MyParent = myParent; - _Name = name; - _ShortName = shortName; - ValidationRules.CheckRules(); - } - internal FormatFolder(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~FormatFolder() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatFolder.FetchDR", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Connection_Name = dr.GetString("Connection_Name"); - _Connection_Title = dr.GetString("Connection_Title"); - _Connection_ConnectionString = dr.GetString("Connection_ConnectionString"); - _Connection_ServerType = dr.GetInt32("Connection_ServerType"); - _Connection_Config = dr.GetString("Connection_Config"); - _Connection_DTS = dr.GetDateTime("Connection_DTS"); - _Connection_UsrID = dr.GetString("Connection_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatFolder.FetchDR", ex); - throw new DbCslaException("FormatFolder.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - 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"]; - Folder.Remove(cn, _FolderID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension(); - [Serializable()] - partial class FormatFolderExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatFolderConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatFolder) - { - // Return the ToString value - return ((FormatFolder)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FormatFolder Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatFolderConverter))] + public partial class FormatFolder : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _FolderID; + [System.ComponentModel.DataObjectField(true, true)] + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + [System.ComponentModel.DataObjectField(true, true)] + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private Folder _MyParent; + public Folder MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + _ParentID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _DBID; + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection != null) _DBID = _MyConnection.DBID; + return _DBID; + } + } + private Connection _MyConnection; + public Connection MyConnection + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); + return _MyConnection; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyConnection != value) + { + _MyConnection = value; + _DBID = value.DBID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ShortName != value) + { + _ShortName = value; + PropertyHasChanged(); + } + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ManualOrder != value) + { + _ManualOrder = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Connection_Name = string.Empty; + public string Connection_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_Name; + } + } + private string _Connection_Title = string.Empty; + public string Connection_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_Title; + } + } + private string _Connection_ConnectionString = string.Empty; + public string Connection_ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_ConnectionString; + } + } + private int _Connection_ServerType; + /// + /// 0 SQL Server + /// + public int Connection_ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_ServerType; + } + } + private string _Connection_Config = string.Empty; + public string Connection_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_Config; + } + } + private DateTime _Connection_DTS = new DateTime(); + public DateTime Connection_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_DTS; + } + } + private string _Connection_UsrID = string.Empty; + public string Connection_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_UsrID; + } + } + // CSLATODO: Check FormatFolder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatFolder + protected override object GetIdValue() + { + return MyFormatFolderUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base FormatFolder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatFolder + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)) && (_MyConnection == null ? true : _MyConnection.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ShortName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyFolderRequired(FormatFolder target, Csla.Validation.RuleArgs e) + { + if (target._ParentID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyConnectionRequired(FormatFolder target, Csla.Validation.RuleArgs e) + { + if (target._DBID == 0 && target._MyConnection == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowRead(DBID, ""); + //AuthorizationRules.AllowWrite(DBID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ShortName, ""); + //AuthorizationRules.AllowWrite(ShortName, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + 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); + } + public FormatFolder() + { + MarkAsChild(); + _FolderID = Folder.NextFolderID; + _ParentID = _FormatFolderExtension.DefaultParentID; + _DBID = _FormatFolderExtension.DefaultDBID; + _DTS = _FormatFolderExtension.DefaultDTS; + _UsrID = _FormatFolderExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private FormatFolder(Folder myParent, string name, string shortName) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _FolderID = Folder.NextFolderID; + _ParentID = _FormatFolderExtension.DefaultParentID; + _DBID = _FormatFolderExtension.DefaultDBID; + _DTS = _FormatFolderExtension.DefaultDTS; + _UsrID = _FormatFolderExtension.DefaultUsrID; + _MyParent = myParent; + _Name = name; + _ShortName = shortName; + ValidationRules.CheckRules(); + } + internal FormatFolder(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~FormatFolder() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatFolder.FetchDR", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Connection_Name = dr.GetString("Connection_Name"); + _Connection_Title = dr.GetString("Connection_Title"); + _Connection_ConnectionString = dr.GetString("Connection_ConnectionString"); + _Connection_ServerType = dr.GetInt32("Connection_ServerType"); + _Connection_Config = dr.GetString("Connection_Config"); + _Connection_DTS = dr.GetDateTime("Connection_DTS"); + _Connection_UsrID = dr.GetString("Connection_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatFolder.FetchDR", ex); + throw new DbCslaException("FormatFolder.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + 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"]; + Folder.Remove(cn, _FolderID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension(); + [Serializable()] + partial class FormatFolderExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatFolderConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatFolder) + { + // Return the ToString value + return ((FormatFolder)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs index e1f73bc0..cb47915c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs @@ -19,586 +19,567 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void FormatInfoEvent(object sender); - /// - /// FormatInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatInfoConverter))] - public partial class FormatInfo : ReadOnlyBase, IDisposable - { - public event FormatInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(FormatInfo formatInfo) - { - if (!_CacheList.Contains(formatInfo)) _CacheList.Add(formatInfo); // In AddToCache - } - protected static void RemoveFromCache(FormatInfo formatInfo) - { - while (_CacheList.Contains(formatInfo)) _CacheList.Remove(formatInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move FormatInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - FormatInfo tmp = _CacheList[0]; // Get the first FormatInfo - string pKey = tmp.FormatID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first FormatInfo - } - } - internal static void AddList(FormatInfoList lst) - { - foreach (FormatInfo item in lst) AddToCache(item); - } - protected static FormatInfo GetCachedByPrimaryKey(int formatID) - { - ConvertListToDictionary(); - string key = formatID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FormatID; - return _ParentID; - } - } - private FormatInfo _MyParent; - public FormatInfo MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FormatID) _MyParent = FormatInfo.Get(_ParentID); - return _MyParent; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Description = string.Empty; - public string Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Description", true); - return _Description; - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private string _GenMac = string.Empty; - public string GenMac - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GenMac", true); - return _GenMac; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ApplicablePlant = 0; - public int ApplicablePlant - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ApplicablePlant", true); - return _ApplicablePlant; - } - } - private int _FormatContentCount = 0; - /// - /// Count of FormatContents for this Format - /// - public int FormatContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContentCount", true); - if (_FormatContentCount < 0) - _FormatContentCount = FormatContents.Count; - return _FormatContentCount; - } - } - private ContentInfoList _FormatContents = null; - [TypeConverter(typeof(ContentInfoListConverter))] - public ContentInfoList FormatContents - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContents", true); - if (_FormatContentCount < 0 || (_FormatContentCount > 0 && _FormatContents == null)) - _FormatContents = ContentInfoList.GetByFormatID(_FormatID); - if (_FormatContentCount < 0) - _FormatContentCount = _FormatContents.Count; - return _FormatContents; - } - } - public void RefreshFormatContents() - { - _FormatContentCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) - tmp._FormatContentCount = -1; // This will cause the data to be requeried - } - private int _FormatDocVersionCount = 0; - /// - /// Count of FormatDocVersions for this Format - /// - public int FormatDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersionCount", true); - if (_FormatDocVersionCount < 0) - _FormatDocVersionCount = FormatDocVersions.Count; - return _FormatDocVersionCount; - } - } - private DocVersionInfoList _FormatDocVersions = null; - [TypeConverter(typeof(DocVersionInfoListConverter))] - public DocVersionInfoList FormatDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersions", true); - if (_FormatDocVersionCount < 0 || (_FormatDocVersionCount > 0 && _FormatDocVersions == null)) - _FormatDocVersions = DocVersionInfoList.GetByFormatID(_FormatID); - if (_FormatDocVersionCount < 0) - _FormatDocVersionCount = _FormatDocVersions.Count; - return _FormatDocVersions; - } - } - public void RefreshFormatDocVersions() - { - _FormatDocVersionCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) - tmp._FormatDocVersionCount = -1; // This will cause the data to be requeried - } - private int _FormatFolderCount = 0; - /// - /// Count of FormatFolders for this Format - /// - public int FormatFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolderCount", true); - if (_FormatFolderCount < 0) - _FormatFolderCount = FormatFolders.Count; - return _FormatFolderCount; - } - } - private FolderInfoList _FormatFolders = null; - [TypeConverter(typeof(FolderInfoListConverter))] - public FolderInfoList FormatFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolders", true); - if (_FormatFolderCount < 0 || (_FormatFolderCount > 0 && _FormatFolders == null)) - _FormatFolders = FolderInfoList.GetByFormatID(_FormatID); - if (_FormatFolderCount < 0) - _FormatFolderCount = _FormatFolders.Count; - return _FormatFolders; - } - } - public void RefreshFormatFolders() - { - _FormatFolderCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) - tmp._FormatFolderCount = -1; // This will cause the data to be requeried - } - private int _ChildFormatCount = 0; - /// - /// Count of ChildFormats for this Format - /// - public int ChildFormatCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormatCount", true); - if (_ChildFormatCount < 0) - _ChildFormatCount = ChildFormats.Count; - return _ChildFormatCount; - } - } - private FormatInfoList _ChildFormats = null; - [TypeConverter(typeof(FormatInfoListConverter))] - public FormatInfoList ChildFormats - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormats", true); - if (_ChildFormatCount < 0 || (_ChildFormatCount > 0 && _ChildFormats == null)) - _ChildFormats = FormatInfoList.GetChildren(_FormatID); - if (_ChildFormatCount < 0) - _ChildFormatCount = _ChildFormats.Count; - return _ChildFormats; - } - } - public void RefreshChildFormats() - { - _ChildFormatCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - 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 - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check FormatInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatInfo - protected override object GetIdValue() - { - return 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; } } - protected FormatInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~FormatInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) return; - List listFormatInfo = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items - while (listFormatInfo.Contains(this)) listFormatInfo.Remove(this); // Remove the item from the list - if (listFormatInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list - } - public virtual Format Get() - { - return _Editable = Format.Get(_FormatID); - } - public static void Refresh(Format tmp) - { - string key = tmp.FormatID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FormatInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Format tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - _Name = tmp.Name; - _Description = tmp.Description; - _Data = tmp.Data; - _Config = tmp.Config; - _GenMac = tmp.GenMac; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FormatInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(formatID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up FormatInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on FormatInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal FormatInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.Constructor", ex); - throw new DbCslaException("FormatInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _FormatID; - public int FormatID - { get { return _FormatID; } } - public PKCriteria(int formatID) - { - _FormatID = formatID; - } - } - public static string _Failed = null; - public static string Failed - { - get { return FormatInfo._Failed; } - set { FormatInfo._Failed = value; } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.ReadData", GetHashCode()); - try - { - _FormatID = dr.GetInt32("FormatID"); - _ParentID = dr.GetInt32("ParentID"); - _Name = dr.GetString("Name"); - _Description = dr.GetString("Description"); - _Data = dr.GetString("Data"); - try // B2019-107 Added Error Handling for missing Config field - { - _Config = dr.GetString("Config"); - } - catch (Exception ex) - { - if (Failed == null) - { - Failed = string.Format("\r\n*** PromsFixes.SQL may not be up to date - {0} - {1}", ex.GetType().Name, ex.Message); - } - } - _GenMac = dr.GetString("GenMac"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _FormatContentCount = dr.GetInt32("ContentCount"); - _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); - _FormatFolderCount = dr.GetInt32("FolderCount"); - _ChildFormatCount = dr.GetInt32("ChildCount"); - _ApplicablePlant = dr.GetInt32("ApplicablePlant"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FormatInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getJustFormat"; - cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension(); - [Serializable()] - partial class FormatInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(FormatInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class FormatInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatInfo) - { - // Return the ToString value - return ((FormatInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void FormatInfoEvent(object sender); + /// + /// FormatInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatInfoConverter))] + public partial class FormatInfo : ReadOnlyBase, IDisposable + { + public event FormatInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(FormatInfo formatInfo) + { + if (!_CacheList.Contains(formatInfo)) _CacheList.Add(formatInfo); // In AddToCache + } + protected static void RemoveFromCache(FormatInfo formatInfo) + { + while (_CacheList.Contains(formatInfo)) _CacheList.Remove(formatInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move FormatInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + FormatInfo tmp = _CacheList[0]; // Get the first FormatInfo + string pKey = tmp.FormatID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first FormatInfo + } + } + internal static void AddList(FormatInfoList lst) + { + foreach (FormatInfo item in lst) AddToCache(item); + } + protected static FormatInfo GetCachedByPrimaryKey(int formatID) + { + ConvertListToDictionary(); + string key = formatID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FormatID; + return _ParentID; + } + } + private FormatInfo _MyParent; + public FormatInfo MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FormatID) _MyParent = FormatInfo.Get(_ParentID); + return _MyParent; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Description; + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private string _GenMac = string.Empty; + public string GenMac + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GenMac; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ApplicablePlant = 0; + public int ApplicablePlant + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ApplicablePlant; + } + } + private int _FormatContentCount = 0; + /// + /// Count of FormatContents for this Format + /// + public int FormatContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatContentCount < 0) + _FormatContentCount = FormatContents.Count; + return _FormatContentCount; + } + } + private ContentInfoList _FormatContents = null; + [TypeConverter(typeof(ContentInfoListConverter))] + public ContentInfoList FormatContents + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatContentCount < 0 || (_FormatContentCount > 0 && _FormatContents == null)) + _FormatContents = ContentInfoList.GetByFormatID(_FormatID); + if (_FormatContentCount < 0) + _FormatContentCount = _FormatContents.Count; + return _FormatContents; + } + } + public void RefreshFormatContents() + { + _FormatContentCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) + tmp._FormatContentCount = -1; // This will cause the data to be requeried + } + private int _FormatDocVersionCount = 0; + /// + /// Count of FormatDocVersions for this Format + /// + public int FormatDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatDocVersionCount < 0) + _FormatDocVersionCount = FormatDocVersions.Count; + return _FormatDocVersionCount; + } + } + private DocVersionInfoList _FormatDocVersions = null; + [TypeConverter(typeof(DocVersionInfoListConverter))] + public DocVersionInfoList FormatDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatDocVersionCount < 0 || (_FormatDocVersionCount > 0 && _FormatDocVersions == null)) + _FormatDocVersions = DocVersionInfoList.GetByFormatID(_FormatID); + if (_FormatDocVersionCount < 0) + _FormatDocVersionCount = _FormatDocVersions.Count; + return _FormatDocVersions; + } + } + public void RefreshFormatDocVersions() + { + _FormatDocVersionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) + tmp._FormatDocVersionCount = -1; // This will cause the data to be requeried + } + private int _FormatFolderCount = 0; + /// + /// Count of FormatFolders for this Format + /// + public int FormatFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatFolderCount < 0) + _FormatFolderCount = FormatFolders.Count; + return _FormatFolderCount; + } + } + private FolderInfoList _FormatFolders = null; + [TypeConverter(typeof(FolderInfoListConverter))] + public FolderInfoList FormatFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatFolderCount < 0 || (_FormatFolderCount > 0 && _FormatFolders == null)) + _FormatFolders = FolderInfoList.GetByFormatID(_FormatID); + if (_FormatFolderCount < 0) + _FormatFolderCount = _FormatFolders.Count; + return _FormatFolders; + } + } + public void RefreshFormatFolders() + { + _FormatFolderCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) + tmp._FormatFolderCount = -1; // This will cause the data to be requeried + } + private int _ChildFormatCount = 0; + /// + /// Count of ChildFormats for this Format + /// + public int ChildFormatCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFormatCount < 0) + _ChildFormatCount = ChildFormats.Count; + return _ChildFormatCount; + } + } + private FormatInfoList _ChildFormats = null; + [TypeConverter(typeof(FormatInfoListConverter))] + public FormatInfoList ChildFormats + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFormatCount < 0 || (_ChildFormatCount > 0 && _ChildFormats == null)) + _ChildFormats = FormatInfoList.GetChildren(_FormatID); + if (_ChildFormatCount < 0) + _ChildFormatCount = _ChildFormats.Count; + return _ChildFormats; + } + } + public void RefreshChildFormats() + { + _ChildFormatCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + 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 + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check FormatInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatInfo + protected override object GetIdValue() + { + return 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; } } + protected FormatInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~FormatInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) return; + List listFormatInfo = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items + while (listFormatInfo.Contains(this)) listFormatInfo.Remove(this); // Remove the item from the list + if (listFormatInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list + } + public virtual Format Get() + { + return _Editable = Format.Get(_FormatID); + } + public static void Refresh(Format tmp) + { + string key = tmp.FormatID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FormatInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Format tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + _Name = tmp.Name; + _Description = tmp.Description; + _Data = tmp.Data; + _Config = tmp.Config; + _GenMac = tmp.GenMac; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FormatInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(formatID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FormatInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal FormatInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.Constructor", ex); + throw new DbCslaException("FormatInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _FormatID; + public int FormatID + { get { return _FormatID; } } + public PKCriteria(int formatID) + { + _FormatID = formatID; + } + } + public static string _Failed = null; + public static string Failed + { + get { return FormatInfo._Failed; } + set { FormatInfo._Failed = value; } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.ReadData", GetHashCode()); + try + { + _FormatID = dr.GetInt32("FormatID"); + _ParentID = dr.GetInt32("ParentID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _Data = dr.GetString("Data"); + try // B2019-107 Added Error Handling for missing Config field + { + _Config = dr.GetString("Config"); + } + catch (Exception ex) + { + if (Failed == null) + { + Failed = string.Format("\r\n*** PromsFixes.SQL may not be up to date - {0} - {1}", ex.GetType().Name, ex.Message); + } + } + _GenMac = dr.GetString("GenMac"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FormatContentCount = dr.GetInt32("ContentCount"); + _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); + _FormatFolderCount = dr.GetInt32("FolderCount"); + _ChildFormatCount = dr.GetInt32("ChildCount"); + _ApplicablePlant = dr.GetInt32("ApplicablePlant"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FormatInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getJustFormat"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension(); + [Serializable()] + partial class FormatInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(FormatInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class FormatInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatInfo) + { + // Return the ToString value + return ((FormatInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Grid.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Grid.cs index d3415a72..551a2541 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Grid.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Grid.cs @@ -20,982 +20,972 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Grid Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GridConverter))] - public partial class Grid : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshGrids = new List(); - private void AddToRefreshList(List refreshGrids) - { - if (IsDirty) - refreshGrids.Add(this); - } - private void ClearRefreshList() - { - _RefreshGrids = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshGrids); - } - private void ProcessRefreshList() - { - foreach (Grid tmp in _RefreshGrids) - { - GridInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Grid grid) - { - if (!_CacheList.Contains(grid)) _CacheList.Add(grid); // In AddToCache - } - protected static void RemoveFromCache(Grid grid) - { - while (_CacheList.Contains(grid)) _CacheList.Remove(grid); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Grid(s) from temporary _CacheList to _CacheByPrimaryKey - { - Grid tmp = _CacheList[0]; // Get the first Grid - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Grid - } - } - protected static Grid GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Data", true); - if (value == null) value = string.Empty; - if (_Data != value) - { - _Data = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base Grid.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Grid - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Grid.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Grid - protected override object GetIdValue() - { - return MyGridUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Data"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _GridExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(Data, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(Data, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _GridExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 Grid() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Grid() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listGrid = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listGrid.Contains(this)) listGrid.Remove(this); // Remove the item from the list - if (listGrid.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static Grid New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Grid"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Grid.New", ex); - } - } - public static Grid New(Content myContent, string data) - { - Grid tmp = Grid.New(); - tmp._MyContent = myContent; - tmp.Data = data; - return tmp; - } - public static Grid New(Content myContent, string data, string config, DateTime dts, string userID) - { - Grid tmp = Grid.New(); - tmp._MyContent = myContent; - tmp.Data = data; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Grid MakeGrid(Content myContent, string data, string config, DateTime dts, string userID) - { - Grid tmp = Grid.New(myContent, data, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Grid New(Content myContent, string data, string config) - { - Grid tmp = Grid.New(); - tmp._MyContent = myContent; - tmp.Data = data; - tmp.Config = config; - return tmp; - } - public static Grid MakeGrid(Content myContent, string data, string config) - { - Grid tmp = Grid.New(myContent, data, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Grid New(Content myContent) - { - Grid tmp = Grid.New(); - tmp._MyContent = myContent; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Grid - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Grid.Get", ex); - } - } - public static Grid Get(SafeDataReader dr) - { - if (dr.Read()) return new Grid(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Grid.Delete", ex); - } - } - 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(); - Grid grid = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(grid);//Refresh the item in AllList - ProcessRefreshList(); - return grid; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// Grid Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GridConverter))] + public partial class Grid : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshGrids = new List(); + private void AddToRefreshList(List refreshGrids) + { + if (IsDirty) + refreshGrids.Add(this); + } + private void ClearRefreshList() + { + _RefreshGrids = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshGrids); + } + private void ProcessRefreshList() + { + foreach (Grid tmp in _RefreshGrids) + { + GridInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Grid grid) + { + if (!_CacheList.Contains(grid)) _CacheList.Add(grid); // In AddToCache + } + protected static void RemoveFromCache(Grid grid) + { + while (_CacheList.Contains(grid)) _CacheList.Remove(grid); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Grid(s) from temporary _CacheList to _CacheByPrimaryKey + { + Grid tmp = _CacheList[0]; // Get the first Grid + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Grid + } + } + protected static Grid GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Data != value) + { + _Data = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base Grid.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Grid + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Grid.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Grid + protected override object GetIdValue() + { + return MyGridUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Data"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _GridExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _GridExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 Grid() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Grid() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listGrid = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listGrid.Contains(this)) listGrid.Remove(this); // Remove the item from the list + if (listGrid.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static Grid New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Grid"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Grid.New", ex); + } + } + public static Grid New(Content myContent, string data) + { + Grid tmp = Grid.New(); + tmp._MyContent = myContent; + tmp.Data = data; + return tmp; + } + public static Grid New(Content myContent, string data, string config, DateTime dts, string userID) + { + Grid tmp = Grid.New(); + tmp._MyContent = myContent; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Grid MakeGrid(Content myContent, string data, string config, DateTime dts, string userID) + { + Grid tmp = Grid.New(myContent, data, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Grid New(Content myContent, string data, string config) + { + Grid tmp = Grid.New(); + tmp._MyContent = myContent; + tmp.Data = data; + tmp.Config = config; + return tmp; + } + public static Grid MakeGrid(Content myContent, string data, string config) + { + Grid tmp = Grid.New(myContent, data, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Grid New(Content myContent) + { + Grid tmp = Grid.New(); + tmp._MyContent = myContent; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Grid + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Grid.Get", ex); + } + } + public static Grid Get(SafeDataReader dr) + { + if (dr.Read()) return new Grid(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Grid.Delete", ex); + } + } + 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(); + Grid grid = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(grid);//Refresh the item in AllList + ProcessRefreshList(); + return grid; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _GridExtension.DefaultDTS; - _UserID = _GridExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Data = dr.GetString("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Grid.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGrid"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Grid.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Grid.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myContent.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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.Add", ex); - throw new DbCslaException("Grid.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Content content) - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateGrid"; - // 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("@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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteGrid"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteGrid"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.Remove", ex); - throw new DbCslaException("Grid.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Grid.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsGrid"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Execute", ex); - throw new DbCslaException("Grid.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - GridExtension _GridExtension = new GridExtension(); - [Serializable()] - partial class GridExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GridConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Grid) - { - // Return the ToString value - return ((Grid)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _GridExtension.DefaultDTS; + _UserID = _GridExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Grid.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGrid"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Grid.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Grid.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myContent.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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.Add", ex); + throw new DbCslaException("Grid.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Content content) + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateGrid"; + // 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("@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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteGrid"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteGrid"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.Remove", ex); + throw new DbCslaException("Grid.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Grid.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Grid.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsGrid"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Grid.DataPortal_Execute", ex); + throw new DbCslaException("Grid.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + GridExtension _GridExtension = new GridExtension(); + [Serializable()] + partial class GridExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GridConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Grid) + { + // Return the ToString value + return ((Grid)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs index 454a1808..9ee0d7a6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GridAudit.cs @@ -20,1038 +20,1023 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// GridAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GridAuditConverter))] - public partial class GridAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshGridAudits = new List(); - private void AddToRefreshList(List refreshGridAudits) - { - if (IsDirty) - refreshGridAudits.Add(this); - } - private void ClearRefreshList() - { - _RefreshGridAudits = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshGridAudits); - } - private void ProcessRefreshList() - { - foreach (GridAudit tmp in _RefreshGridAudits) - { - GridAuditInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(GridAudit gridAudit) - { - if (!_CacheList.Contains(gridAudit)) _CacheList.Add(gridAudit); // In AddToCache - } - protected static void RemoveFromCache(GridAudit gridAudit) - { - while (_CacheList.Contains(gridAudit)) _CacheList.Remove(gridAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move GridAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - GridAudit tmp = _CacheList[0]; // Get the first GridAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first GridAudit - } - } - protected static GridAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Data", true); - if (value == null) value = string.Empty; - if (_Data != value) - { - _Data = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - private long _ContentAuditID; - public long ContentAuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentAuditID", true); - return _ContentAuditID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentAuditID", true); - if (_ContentAuditID != value) - { - _ContentAuditID = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base GridAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GridAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check GridAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GridAudit - protected override object GetIdValue() - { - return MyGridAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Data"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _GridAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(Data, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowRead(ContentAuditID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(Data, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ContentAuditID, ""); - _GridAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 GridAudit() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~GridAudit() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listGridAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listGridAudit.Contains(this)) listGridAudit.Remove(this); // Remove the item from the list - if (listGridAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static GridAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a GridAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on GridAudit.New", ex); - } - } - public static GridAudit New(int contentID, string data, DateTime dts, string userID, int deleteStatus) - { - GridAudit tmp = GridAudit.New(); - tmp.ContentID = contentID; - tmp.Data = data; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static GridAudit New(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) - { - GridAudit tmp = GridAudit.New(); - tmp.ContentID = contentID; - tmp.Data = data; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - tmp.ContentAuditID = contentAuditID; - return tmp; - } - public static GridAudit MakeGridAudit(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) - { - GridAudit tmp = GridAudit.New(contentID, data, config, dts, userID, deleteStatus, contentAuditID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static GridAudit New(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus) - { - GridAudit tmp = GridAudit.New(); - tmp.ContentID = contentID; - tmp.Data = data; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static GridAudit MakeGridAudit(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus) - { - GridAudit tmp = GridAudit.New(contentID, data, config, dts, userID, deleteStatus); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up GridAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on GridAudit.Get", ex); - } - } - public static GridAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new GridAudit(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on GridAudit.Delete", ex); - } - } - 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(); - GridAudit gridAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(gridAudit);//Refresh the item in AllList - ProcessRefreshList(); - return gridAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults - _ContentAuditID = _GridAuditExtension.DefaultContentAuditID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _Data = dr.GetString("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - _ContentAuditID = dr.GetInt64("ContentAuditID"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GridAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGridAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GridAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GridAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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); - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Add", ex); - throw new DbCslaException("GridAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateGridAudit"; - // Input All Fields - Except Calculated Columns - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteGridAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteGridAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Remove", ex); - throw new DbCslaException("GridAudit.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(long auditID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(auditID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on GridAudit.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private long _AuditID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(long auditID) - { - _AuditID = auditID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsGridAudit"; - cm.Parameters.AddWithValue("@AuditID", _AuditID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Execute", ex); - throw new DbCslaException("GridAudit.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - GridAuditExtension _GridAuditExtension = new GridAuditExtension(); - [Serializable()] - partial class GridAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual long DefaultContentAuditID - { - get { return 0; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GridAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GridAudit) - { - // Return the ToString value - return ((GridAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// GridAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GridAuditConverter))] + public partial class GridAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshGridAudits = new List(); + private void AddToRefreshList(List refreshGridAudits) + { + if (IsDirty) + refreshGridAudits.Add(this); + } + private void ClearRefreshList() + { + _RefreshGridAudits = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshGridAudits); + } + private void ProcessRefreshList() + { + foreach (GridAudit tmp in _RefreshGridAudits) + { + GridAuditInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(GridAudit gridAudit) + { + if (!_CacheList.Contains(gridAudit)) _CacheList.Add(gridAudit); // In AddToCache + } + protected static void RemoveFromCache(GridAudit gridAudit) + { + while (_CacheList.Contains(gridAudit)) _CacheList.Remove(gridAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move GridAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + GridAudit tmp = _CacheList[0]; // Get the first GridAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first GridAudit + } + } + protected static GridAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Data != value) + { + _Data = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + private long _ContentAuditID; + public long ContentAuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentAuditID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentAuditID != value) + { + _ContentAuditID = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base GridAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GridAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check GridAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GridAudit + protected override object GetIdValue() + { + return MyGridAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Data"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _GridAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowRead(ContentAuditID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentAuditID, ""); + _GridAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 GridAudit() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~GridAudit() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listGridAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listGridAudit.Contains(this)) listGridAudit.Remove(this); // Remove the item from the list + if (listGridAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static GridAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a GridAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.New", ex); + } + } + public static GridAudit New(int contentID, string data, DateTime dts, string userID, int deleteStatus) + { + GridAudit tmp = GridAudit.New(); + tmp.ContentID = contentID; + tmp.Data = data; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static GridAudit New(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) + { + GridAudit tmp = GridAudit.New(); + tmp.ContentID = contentID; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + tmp.ContentAuditID = contentAuditID; + return tmp; + } + public static GridAudit MakeGridAudit(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus, long contentAuditID) + { + GridAudit tmp = GridAudit.New(contentID, data, config, dts, userID, deleteStatus, contentAuditID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static GridAudit New(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus) + { + GridAudit tmp = GridAudit.New(); + tmp.ContentID = contentID; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static GridAudit MakeGridAudit(int contentID, string data, string config, DateTime dts, string userID, int deleteStatus) + { + GridAudit tmp = GridAudit.New(contentID, data, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up GridAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.Get", ex); + } + } + public static GridAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new GridAudit(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.Delete", ex); + } + } + 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(); + GridAudit gridAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(gridAudit);//Refresh the item in AllList + ProcessRefreshList(); + return gridAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults + _ContentAuditID = _GridAuditExtension.DefaultContentAuditID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + _ContentAuditID = dr.GetInt64("ContentAuditID"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGridAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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); + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Add", ex); + throw new DbCslaException("GridAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateGridAudit"; + // Input All Fields - Except Calculated Columns + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteGridAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteGridAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.Remove", ex); + throw new DbCslaException("GridAudit.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(long auditID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(auditID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAudit.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private long _AuditID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(long auditID) + { + _AuditID = auditID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAudit.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsGridAudit"; + cm.Parameters.AddWithValue("@AuditID", _AuditID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAudit.DataPortal_Execute", ex); + throw new DbCslaException("GridAudit.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + GridAuditExtension _GridAuditExtension = new GridAuditExtension(); + [Serializable()] + partial class GridAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual long DefaultContentAuditID + { + get { return 0; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GridAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GridAudit) + { + // Return the ToString value + return ((GridAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfo.cs index 5f457b08..3bb48ca0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GridAuditInfo.cs @@ -19,373 +19,365 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void GridAuditInfoEvent(object sender); - /// - /// GridAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GridAuditInfoConverter))] - public partial class GridAuditInfo : ReadOnlyBase, IDisposable - { - public event GridAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(GridAuditInfo gridAuditInfo) - { - if (!_CacheList.Contains(gridAuditInfo)) _CacheList.Add(gridAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(GridAuditInfo gridAuditInfo) - { - while (_CacheList.Contains(gridAuditInfo)) _CacheList.Remove(gridAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move GridAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - GridAuditInfo tmp = _CacheList[0]; // Get the first GridAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first GridAuditInfo - } - } - internal static void AddList(GridAuditInfoList lst) - { - foreach (GridAuditInfo item in lst) AddToCache(item); - } - protected static GridAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - private long _ContentAuditID; - public long ContentAuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentAuditID", true); - return _ContentAuditID; - } - } - // CSLATODO: Replace base GridAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GridAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check GridAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GridAuditInfo - protected override object GetIdValue() - { - return 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; } } - protected GridAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~GridAuditInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listGridAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listGridAuditInfo.Contains(this)) listGridAuditInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(GridAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (GridAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(GridAudit tmp) - { - _ContentID = tmp.ContentID; - _Data = tmp.Data; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _ContentAuditID = tmp.ContentAuditID; - _GridAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up GridAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on GridAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal GridAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.Constructor", ex); - throw new DbCslaException("GridAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _Data = dr.GetString("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - _ContentAuditID = dr.GetInt64("ContentAuditID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GridAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGridAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GridAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - GridAuditInfoExtension _GridAuditInfoExtension = new GridAuditInfoExtension(); - [Serializable()] - partial class GridAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(GridAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class GridAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GridAuditInfo) - { - // Return the ToString value - return ((GridAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void GridAuditInfoEvent(object sender); + /// + /// GridAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GridAuditInfoConverter))] + public partial class GridAuditInfo : ReadOnlyBase, IDisposable + { + public event GridAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(GridAuditInfo gridAuditInfo) + { + if (!_CacheList.Contains(gridAuditInfo)) _CacheList.Add(gridAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(GridAuditInfo gridAuditInfo) + { + while (_CacheList.Contains(gridAuditInfo)) _CacheList.Remove(gridAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move GridAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + GridAuditInfo tmp = _CacheList[0]; // Get the first GridAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first GridAuditInfo + } + } + internal static void AddList(GridAuditInfoList lst) + { + foreach (GridAuditInfo item in lst) AddToCache(item); + } + protected static GridAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + private long _ContentAuditID; + public long ContentAuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentAuditID; + } + } + // CSLATODO: Replace base GridAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GridAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check GridAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GridAuditInfo + protected override object GetIdValue() + { + return 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; } } + protected GridAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~GridAuditInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listGridAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listGridAuditInfo.Contains(this)) listGridAuditInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(GridAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (GridAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(GridAudit tmp) + { + _ContentID = tmp.ContentID; + _Data = tmp.Data; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ContentAuditID = tmp.ContentAuditID; + _GridAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up GridAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal GridAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.Constructor", ex); + throw new DbCslaException("GridAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + _ContentAuditID = dr.GetInt64("ContentAuditID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGridAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + GridAuditInfoExtension _GridAuditInfoExtension = new GridAuditInfoExtension(); + [Serializable()] + partial class GridAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(GridAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class GridAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GridAuditInfo) + { + // Return the ToString value + return ((GridAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GridInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GridInfo.cs index fe198ab3..7791c5c7 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/GridInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GridInfo.cs @@ -17,348 +17,364 @@ using System.Configuration; using System.IO; using System.ComponentModel; using System.Collections.Generic; +using System.Linq; + namespace VEPROMS.CSLA.Library { - public delegate void GridInfoEvent(object sender); - /// - /// GridInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GridInfoConverter))] - public partial class GridInfo : ReadOnlyBase, IDisposable - { - public event GridInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(GridInfo gridInfo) - { - if (!_CacheList.Contains(gridInfo)) _CacheList.Add(gridInfo); // In AddToCache - } - protected static void RemoveFromCache(GridInfo gridInfo) - { - while (_CacheList.Contains(gridInfo)) _CacheList.Remove(gridInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move GridInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - GridInfo tmp = _CacheList[0]; // Get the first GridInfo - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first GridInfo - } - } - protected static GridInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base GridInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GridInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check GridInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GridInfo - protected override object GetIdValue() - { - return 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; } } - protected GridInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~GridInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listGridInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listGridInfo.Contains(this)) listGridInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Grid tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (GridInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Grid tmp) - { - _Data = tmp.Data; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _GridInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up GridInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on GridInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal GridInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridInfo.Constructor", ex); - throw new DbCslaException("GridInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Data = dr.GetString("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GridInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGrid"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GridInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GridInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - GridInfoExtension _GridInfoExtension = new GridInfoExtension(); - [Serializable()] - partial class GridInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(GridInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class GridInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GridInfo) - { - // Return the ToString value - return ((GridInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void GridInfoEvent(object sender); + /// + /// GridInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GridInfoConverter))] + public partial class GridInfo : ReadOnlyBase, IDisposable + { + public event GridInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(GridInfo gridInfo) + { + if (!_CacheList.Contains(gridInfo)) _CacheList.Add(gridInfo); // In AddToCache + } + protected static void RemoveFromCache(GridInfo gridInfo) + { + while (_CacheList.Contains(gridInfo)) _CacheList.Remove(gridInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move GridInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + GridInfo tmp = _CacheList[0]; // Get the first GridInfo + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first GridInfo + } + } + protected static GridInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + + public static void ClearGridInfoCache() + { + while (_CacheByPrimaryKey.Count > 0) + { + var ii = _CacheByPrimaryKey.FirstOrDefault(); + + while (ii.Value.Count > 0) + { + if (ii.Value[0]?.MyContent?.ContentParts != null) + { foreach (PartInfo pi in ii.Value[0]?.MyContent?.ContentParts) pi.Dispose(); } + ii.Value[0].Dispose(); + } + _CacheByPrimaryKey.Remove(ii.Key); + } + while (_CacheList.Count > 0) + { + _CacheList[0].Dispose(); + } + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base GridInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GridInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check GridInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GridInfo + protected override object GetIdValue() + { + return 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; } } + protected GridInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~GridInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listGridInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listGridInfo.Contains(this)) listGridInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Grid tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (GridInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Grid tmp) + { + _Data = tmp.Data; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _GridInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up GridInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GridInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal GridInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridInfo.Constructor", ex); + throw new DbCslaException("GridInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GridInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGrid"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GridInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GridInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + GridInfoExtension _GridInfoExtension = new GridInfoExtension(); + [Serializable()] + partial class GridInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(GridInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class GridInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GridInfo) + { + // Return the ToString value + return ((GridInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Group.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Group.cs index 3e844af3..123c62ae 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Group.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Group.cs @@ -20,1232 +20,1217 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Group Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupConverter))] - public partial class Group : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshGroups = new List(); - private List _RefreshGroupAssignments = new List(); - private List _RefreshGroupMemberships = new List(); - private void AddToRefreshList(List refreshGroups, List refreshGroupAssignments, List refreshGroupMemberships) - { - if (IsDirty) - refreshGroups.Add(this); - if (_GroupAssignments != null && _GroupAssignments.IsDirty) - { - foreach (GroupAssignment tmp in _GroupAssignments) - { - if (tmp.IsDirty) refreshGroupAssignments.Add(tmp); - } - } - if (_GroupMemberships != null && _GroupMemberships.IsDirty) - { - foreach (GroupMembership tmp in _GroupMemberships) - { - if (tmp.IsDirty) refreshGroupMemberships.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshGroups = new List(); - _RefreshGroupAssignments = new List(); - _RefreshGroupMemberships = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshGroups, _RefreshGroupAssignments, _RefreshGroupMemberships); - } - private void ProcessRefreshList() - { - foreach (Group tmp in _RefreshGroups) - { - GroupInfo.Refresh(tmp); - } - foreach (GroupAssignment tmp in _RefreshGroupAssignments) - { - AssignmentInfo.Refresh(tmp); - } - foreach (GroupMembership tmp in _RefreshGroupMemberships) - { - MembershipInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Group group) - { - if (!_CacheList.Contains(group)) _CacheList.Add(group); // In AddToCache - } - protected static void RemoveFromCache(Group group) - { - while (_CacheList.Contains(group)) _CacheList.Remove(group); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByGroupName = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Group(s) from temporary _CacheList to _CacheByPrimaryKey - { - Group tmp = _CacheList[0]; // Get the first Group - string pKey = tmp.GID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByGroupName[tmp.GroupName.ToString()] = new List(); // Add new list for GroupName - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByGroupName[tmp.GroupName.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first Group - } - } - protected static Group GetCachedByPrimaryKey(int gid) - { - ConvertListToDictionary(); - string key = gid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Group GetCachedByGroupName(string groupName) - { - ConvertListToDictionary(); - string key = groupName.ToString(); - if (_CacheByGroupName.ContainsKey(key)) return _CacheByGroupName[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextGID = -1; - public static int NextGID - { - get { return _nextGID--; } - } - private int _GID; - [System.ComponentModel.DataObjectField(true, true)] - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - return _GID; - } - } - private string _GroupName = string.Empty; - public string GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupName", true); - return _GroupName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("GroupName", true); - if (value == null) value = string.Empty; - if (_GroupName != value) - { - _GroupName = value; - PropertyHasChanged(); - } - } - } - private int? _GroupType; - public int? GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupType", true); - return _GroupType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("GroupType", true); - if (_GroupType != value) - { - _GroupType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _GroupAssignmentCount = 0; - /// - /// Count of GroupAssignments for this Group - /// - public int GroupAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignmentCount", true); - return _GroupAssignmentCount; - } - } - private GroupAssignments _GroupAssignments = null; - /// - /// Related Field - /// - [TypeConverter(typeof(GroupAssignmentsConverter))] - public GroupAssignments GroupAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignments", true); - if (_GroupAssignmentCount < 0 || (_GroupAssignmentCount > 0 && _GroupAssignments == null)) - _GroupAssignments = GroupAssignments.GetByGID(GID); - if (_GroupAssignmentCount < 0 ) - _GroupAssignmentCount = _GroupAssignments == null ? 0 : _GroupAssignments.Count; - if (_GroupAssignments == null) - _GroupAssignments = GroupAssignments.New(); - return _GroupAssignments; - } - } - public void Reset_GroupAssignments() - { - _GroupAssignmentCount = -1; - } - private int _GroupMembershipCount = 0; - /// - /// Count of GroupMemberships for this Group - /// - public int GroupMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMembershipCount", true); - return _GroupMembershipCount; - } - } - private GroupMemberships _GroupMemberships = null; - /// - /// Related Field - /// - [TypeConverter(typeof(GroupMembershipsConverter))] - public GroupMemberships GroupMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMemberships", true); - if (_GroupMembershipCount < 0 || (_GroupMembershipCount > 0 && _GroupMemberships == null)) - _GroupMemberships = GroupMemberships.GetByGID(GID); - if (_GroupMembershipCount < 0 ) - _GroupMembershipCount = _GroupMemberships == null ? 0 : _GroupMemberships.Count; - if (_GroupMemberships == null) - _GroupMemberships = GroupMemberships.New(); - return _GroupMemberships; - } - } - public void Reset_GroupMemberships() - { - _GroupMembershipCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_GroupAssignments == null ? true : _GroupAssignments.IsValidList(list)) && (_GroupMemberships == null ? true : _GroupMemberships.IsValidList(list)); - } - // CSLATODO: Replace base Group.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Group - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Group.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Group - protected override object GetIdValue() - { - return MyGroupUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_GroupAssignments != null && (hasBrokenRules = _GroupAssignments.HasBrokenRules) != null) return hasBrokenRules; - if (_GroupMemberships != null && (hasBrokenRules = _GroupMemberships.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "GroupName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("GroupName", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _GroupExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(GroupName, ""); - //AuthorizationRules.AllowRead(GroupType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(GroupName, ""); - //AuthorizationRules.AllowWrite(GroupType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _GroupExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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; } } - 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 Group() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Group() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(GID.ToString())) - { - List listGroup = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items - while (listGroup.Contains(this)) listGroup.Remove(this); // Remove the item from the list - if (listGroup.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(GID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByGroupName.Keys) - if (_CacheByGroupName[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listGroup = _CacheByGroupName[myKey]; // Get the list of items - listGroup.Remove(this); // Remove the item from the list - if (listGroup.Count == 0) //If there are no items left in the list - _CacheByGroupName.Remove(myKey); // remove the list - } - } - public static Group New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Group"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.New", ex); - } - } - public static Group New(string groupName) - { - Group tmp = Group.New(); - tmp.GroupName = groupName; - return tmp; - } - public static Group New(string groupName, int? groupType, string config, DateTime dts, string usrID) - { - Group tmp = Group.New(); - tmp.GroupName = groupName; - tmp.GroupType = groupType; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Group MakeGroup(string groupName, int? groupType, string config, DateTime dts, string usrID) - { - Group tmp = Group.New(groupName, groupType, config, dts, usrID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Group New(string groupName, int? groupType, string config) - { - Group tmp = Group.New(); - tmp.GroupName = groupName; - tmp.GroupType = groupType; - tmp.Config = config; - return tmp; - } - public static Group MakeGroup(string groupName, int? groupType, string config) - { - Group tmp = Group.New(groupName, groupType, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(gid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Group - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.Get", ex); - } - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new GroupNameCriteria(groupName)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Group - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.GetByGroupName", ex); - } - } - public static Group Get(SafeDataReader dr) - { - if (dr.Read()) return new Group(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.Delete", ex); - } - } - 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(); - Group group = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(group);//Refresh the item in AllList - ProcessRefreshList(); - return group; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _GID; - public int GID - { get { return _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; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _GID = NextGID; - // Database Defaults - _DTS = _GroupExtension.DefaultDTS; - _UsrID = _GroupExtension.DefaultUsrID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.ReadData", GetHashCode()); - try - { - _GID = dr.GetInt32("GID"); - _GroupName = dr.GetString("GroupName"); - _GroupType = (int?)dr.GetValue("GroupType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); - _GroupMembershipCount = dr.GetInt32("MembershipCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGroup"; - cm.Parameters.AddWithValue("@GID", criteria.GID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _GroupAssignments = GroupAssignments.Get(dr); - // load child objects - dr.NextResult(); - _GroupMemberships = GroupMemberships.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(GroupNameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGroupByGroupName"; - cm.Parameters.AddWithValue("@GroupName", criteria.GroupName); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_GroupAssignments != null) _GroupAssignments.Update(this); - if (_GroupMemberships != null) _GroupMemberships.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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); - 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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Add", ex); - throw new DbCslaException("Group.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_GroupAssignments != null) _GroupAssignments.Update(this); - if (_GroupMemberships != null) _GroupMemberships.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - MarkOld(); - } - if (_GroupAssignments != null) _GroupAssignments.Update(this); - if (_GroupMemberships != null) _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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateGroup"; - // Input All Fields - Except Calculated Columns - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteGroup"; - cm.Parameters.AddWithValue("@GID", criteria.GID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteGroup"; - // Input PK Fields - cm.Parameters.AddWithValue("@GID", gid); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Remove", ex); - throw new DbCslaException("Group.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int gid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(gid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _GID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int gid) - { - _GID = gid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsGroup"; - cm.Parameters.AddWithValue("@GID", _GID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Execute", ex); - throw new DbCslaException("Group.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - GroupExtension _GroupExtension = new GroupExtension(); - [Serializable()] - partial class GroupExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GroupConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Group) - { - // Return the ToString value - return ((Group)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Group Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupConverter))] + public partial class Group : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshGroups = new List(); + private List _RefreshGroupAssignments = new List(); + private List _RefreshGroupMemberships = new List(); + private void AddToRefreshList(List refreshGroups, List refreshGroupAssignments, List refreshGroupMemberships) + { + if (IsDirty) + refreshGroups.Add(this); + if (_GroupAssignments != null && _GroupAssignments.IsDirty) + { + foreach (GroupAssignment tmp in _GroupAssignments) + { + if (tmp.IsDirty) refreshGroupAssignments.Add(tmp); + } + } + if (_GroupMemberships != null && _GroupMemberships.IsDirty) + { + foreach (GroupMembership tmp in _GroupMemberships) + { + if (tmp.IsDirty) refreshGroupMemberships.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshGroups = new List(); + _RefreshGroupAssignments = new List(); + _RefreshGroupMemberships = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshGroups, _RefreshGroupAssignments, _RefreshGroupMemberships); + } + private void ProcessRefreshList() + { + foreach (Group tmp in _RefreshGroups) + { + GroupInfo.Refresh(tmp); + } + foreach (GroupAssignment tmp in _RefreshGroupAssignments) + { + AssignmentInfo.Refresh(tmp); + } + foreach (GroupMembership tmp in _RefreshGroupMemberships) + { + MembershipInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Group group) + { + if (!_CacheList.Contains(group)) _CacheList.Add(group); // In AddToCache + } + protected static void RemoveFromCache(Group group) + { + while (_CacheList.Contains(group)) _CacheList.Remove(group); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByGroupName = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Group(s) from temporary _CacheList to _CacheByPrimaryKey + { + Group tmp = _CacheList[0]; // Get the first Group + string pKey = tmp.GID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByGroupName[tmp.GroupName.ToString()] = new List(); // Add new list for GroupName + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByGroupName[tmp.GroupName.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first Group + } + } + protected static Group GetCachedByPrimaryKey(int gid) + { + ConvertListToDictionary(); + string key = gid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Group GetCachedByGroupName(string groupName) + { + ConvertListToDictionary(); + string key = groupName.ToString(); + if (_CacheByGroupName.ContainsKey(key)) return _CacheByGroupName[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextGID = -1; + public static int NextGID + { + get { return _nextGID--; } + } + private int _GID; + [System.ComponentModel.DataObjectField(true, true)] + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GID; + } + } + private string _GroupName = string.Empty; + public string GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_GroupName != value) + { + _GroupName = value; + PropertyHasChanged(); + } + } + } + private int? _GroupType; + public int? GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_GroupType != value) + { + _GroupType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _GroupAssignmentCount = 0; + /// + /// Count of GroupAssignments for this Group + /// + public int GroupAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupAssignmentCount; + } + } + private GroupAssignments _GroupAssignments = null; + /// + /// Related Field + /// + [TypeConverter(typeof(GroupAssignmentsConverter))] + public GroupAssignments GroupAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupAssignmentCount < 0 || (_GroupAssignmentCount > 0 && _GroupAssignments == null)) + _GroupAssignments = GroupAssignments.GetByGID(GID); + if (_GroupAssignmentCount < 0) + _GroupAssignmentCount = _GroupAssignments == null ? 0 : _GroupAssignments.Count; + if (_GroupAssignments == null) + _GroupAssignments = GroupAssignments.New(); + return _GroupAssignments; + } + } + public void Reset_GroupAssignments() + { + _GroupAssignmentCount = -1; + } + private int _GroupMembershipCount = 0; + /// + /// Count of GroupMemberships for this Group + /// + public int GroupMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupMembershipCount; + } + } + private GroupMemberships _GroupMemberships = null; + /// + /// Related Field + /// + [TypeConverter(typeof(GroupMembershipsConverter))] + public GroupMemberships GroupMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupMembershipCount < 0 || (_GroupMembershipCount > 0 && _GroupMemberships == null)) + _GroupMemberships = GroupMemberships.GetByGID(GID); + if (_GroupMembershipCount < 0) + _GroupMembershipCount = _GroupMemberships == null ? 0 : _GroupMemberships.Count; + if (_GroupMemberships == null) + _GroupMemberships = GroupMemberships.New(); + return _GroupMemberships; + } + } + public void Reset_GroupMemberships() + { + _GroupMembershipCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_GroupAssignments == null ? true : _GroupAssignments.IsValidList(list)) && (_GroupMemberships == null ? true : _GroupMemberships.IsValidList(list)); + } + // CSLATODO: Replace base Group.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Group + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Group.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Group + protected override object GetIdValue() + { + return MyGroupUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_GroupAssignments != null && (hasBrokenRules = _GroupAssignments.HasBrokenRules) != null) return hasBrokenRules; + if (_GroupMemberships != null && (hasBrokenRules = _GroupMemberships.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "GroupName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("GroupName", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _GroupExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(GroupName, ""); + //AuthorizationRules.AllowRead(GroupType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(GroupName, ""); + //AuthorizationRules.AllowWrite(GroupType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _GroupExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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; } } + 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 Group() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Group() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(GID.ToString())) + { + List listGroup = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items + while (listGroup.Contains(this)) listGroup.Remove(this); // Remove the item from the list + if (listGroup.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(GID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByGroupName.Keys) + if (_CacheByGroupName[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listGroup = _CacheByGroupName[myKey]; // Get the list of items + listGroup.Remove(this); // Remove the item from the list + if (listGroup.Count == 0) //If there are no items left in the list + _CacheByGroupName.Remove(myKey); // remove the list + } + } + public static Group New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Group"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.New", ex); + } + } + public static Group New(string groupName) + { + Group tmp = Group.New(); + tmp.GroupName = groupName; + return tmp; + } + public static Group New(string groupName, int? groupType, string config, DateTime dts, string usrID) + { + Group tmp = Group.New(); + tmp.GroupName = groupName; + tmp.GroupType = groupType; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Group MakeGroup(string groupName, int? groupType, string config, DateTime dts, string usrID) + { + Group tmp = Group.New(groupName, groupType, config, dts, usrID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Group New(string groupName, int? groupType, string config) + { + Group tmp = Group.New(); + tmp.GroupName = groupName; + tmp.GroupType = groupType; + tmp.Config = config; + return tmp; + } + public static Group MakeGroup(string groupName, int? groupType, string config) + { + Group tmp = Group.New(groupName, groupType, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(gid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Group + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.Get", ex); + } + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new GroupNameCriteria(groupName)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Group + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.GetByGroupName", ex); + } + } + public static Group Get(SafeDataReader dr) + { + if (dr.Read()) return new Group(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.Delete", ex); + } + } + 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(); + Group group = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(group);//Refresh the item in AllList + ProcessRefreshList(); + return group; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _GID; + public int GID + { get { return _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; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _GID = NextGID; + // Database Defaults + _DTS = _GroupExtension.DefaultDTS; + _UsrID = _GroupExtension.DefaultUsrID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.ReadData", GetHashCode()); + try + { + _GID = dr.GetInt32("GID"); + _GroupName = dr.GetString("GroupName"); + _GroupType = (int?)dr.GetValue("GroupType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); + _GroupMembershipCount = dr.GetInt32("MembershipCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroup"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _GroupAssignments = GroupAssignments.Get(dr); + // load child objects + dr.NextResult(); + _GroupMemberships = GroupMemberships.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(GroupNameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroupByGroupName"; + cm.Parameters.AddWithValue("@GroupName", criteria.GroupName); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_GroupAssignments != null) _GroupAssignments.Update(this); + if (_GroupMemberships != null) _GroupMemberships.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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); + 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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Add", ex); + throw new DbCslaException("Group.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_GroupAssignments != null) _GroupAssignments.Update(this); + if (_GroupMemberships != null) _GroupMemberships.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + MarkOld(); + } + if (_GroupAssignments != null) _GroupAssignments.Update(this); + if (_GroupMemberships != null) _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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateGroup"; + // Input All Fields - Except Calculated Columns + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteGroup"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteGroup"; + // Input PK Fields + cm.Parameters.AddWithValue("@GID", gid); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Remove", ex); + throw new DbCslaException("Group.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int gid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(gid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _GID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int gid) + { + _GID = gid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsGroup"; + cm.Parameters.AddWithValue("@GID", _GID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Execute", ex); + throw new DbCslaException("Group.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + GroupExtension _GroupExtension = new GroupExtension(); + [Serializable()] + partial class GroupExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GroupConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Group) + { + // Return the ToString value + return ((Group)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignment.cs index 25210e1e..383daa99 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupAssignment.cs @@ -20,738 +20,708 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// GroupAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupAssignmentConverter))] - public partial class GroupAssignment : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - if (_MyAssignment != null) _AID = _MyAssignment.AID; - return _AID; - } - } - private Assignment _MyAssignment; - [System.ComponentModel.DataObjectField(true, true)] - public Assignment MyAssignment - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssignment", true); - if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); - return _MyAssignment; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private Role _MyRole; - public Role MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); - return _MyRole; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRole", true); - if (_MyRole != value) - { - _MyRole = value; - _RID = value.RID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - _FolderID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - private string _Role_Name = string.Empty; - public string Role_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Name", true); - return _Role_Name; - } - } - private string _Role_Title = string.Empty; - public string Role_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Title", true); - return _Role_Title; - } - } - private DateTime _Role_DTS = new DateTime(); - public DateTime Role_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_DTS", true); - return _Role_DTS; - } - } - private string _Role_UsrID = string.Empty; - public string Role_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_UsrID", true); - return _Role_UsrID; - } - } - // CSLATODO: Check GroupAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupAssignment - protected override object GetIdValue() - { - return MyGroupAssignmentUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base GroupAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRoleRequired, "MyRole"); - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyRoleRequired(GroupAssignment target, Csla.Validation.RuleArgs e) - { - if (target._RID == 0 && target._MyRole == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyFolderRequired(GroupAssignment target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowWrite(RID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - 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); - } - public GroupAssignment() - { - MarkAsChild(); - _AID = Assignment.NextAID; - _StartDate = _GroupAssignmentExtension.DefaultStartDate; - _DTS = _GroupAssignmentExtension.DefaultDTS; - _UsrID = _GroupAssignmentExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private GroupAssignment(Role myRole, Folder myFolder) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _AID = Assignment.NextAID; - _StartDate = _GroupAssignmentExtension.DefaultStartDate; - _DTS = _GroupAssignmentExtension.DefaultDTS; - _UsrID = _GroupAssignmentExtension.DefaultUsrID; - _MyRole = myRole; - _MyFolder = myFolder; - ValidationRules.CheckRules(); - } - internal GroupAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~GroupAssignment() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupAssignment.FetchDR", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _RID = dr.GetInt32("RID"); - _FolderID = dr.GetInt32("FolderID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - _Role_Name = dr.GetString("Role_Name"); - _Role_Title = dr.GetString("Role_Title"); - _Role_DTS = dr.GetDateTime("Role_DTS"); - _Role_UsrID = dr.GetString("Role_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupAssignment.FetchDR", ex); - throw new DbCslaException("GroupAssignment.Fetch", ex); - } - MarkOld(); - } - 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 = 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); - MarkOld(); - } - 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - GroupAssignmentExtension _GroupAssignmentExtension = new GroupAssignmentExtension(); - [Serializable()] - partial class GroupAssignmentExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GroupAssignmentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GroupAssignment) - { - // Return the ToString value - return ((GroupAssignment)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// GroupAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupAssignmentConverter))] + public partial class GroupAssignment : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment != null) _AID = _MyAssignment.AID; + return _AID; + } + } + private Assignment _MyAssignment; + [System.ComponentModel.DataObjectField(true, true)] + public Assignment MyAssignment + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); + return _MyAssignment; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private Role _MyRole; + public Role MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); + return _MyRole; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRole != value) + { + _MyRole = value; + _RID = value.RID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + _FolderID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + private string _Role_Name = string.Empty; + public string Role_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Name; + } + } + private string _Role_Title = string.Empty; + public string Role_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Title; + } + } + private DateTime _Role_DTS = new DateTime(); + public DateTime Role_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_DTS; + } + } + private string _Role_UsrID = string.Empty; + public string Role_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_UsrID; + } + } + // CSLATODO: Check GroupAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupAssignment + protected override object GetIdValue() + { + return MyGroupAssignmentUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base GroupAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRoleRequired, "MyRole"); + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyRoleRequired(GroupAssignment target, Csla.Validation.RuleArgs e) + { + if (target._RID == 0 && target._MyRole == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyFolderRequired(GroupAssignment target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowWrite(RID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + 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); + } + public GroupAssignment() + { + MarkAsChild(); + _AID = Assignment.NextAID; + _StartDate = _GroupAssignmentExtension.DefaultStartDate; + _DTS = _GroupAssignmentExtension.DefaultDTS; + _UsrID = _GroupAssignmentExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private GroupAssignment(Role myRole, Folder myFolder) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _AID = Assignment.NextAID; + _StartDate = _GroupAssignmentExtension.DefaultStartDate; + _DTS = _GroupAssignmentExtension.DefaultDTS; + _UsrID = _GroupAssignmentExtension.DefaultUsrID; + _MyRole = myRole; + _MyFolder = myFolder; + ValidationRules.CheckRules(); + } + internal GroupAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~GroupAssignment() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupAssignment.FetchDR", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _RID = dr.GetInt32("RID"); + _FolderID = dr.GetInt32("FolderID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + _Role_Name = dr.GetString("Role_Name"); + _Role_Title = dr.GetString("Role_Title"); + _Role_DTS = dr.GetDateTime("Role_DTS"); + _Role_UsrID = dr.GetString("Role_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupAssignment.FetchDR", ex); + throw new DbCslaException("GroupAssignment.Fetch", ex); + } + MarkOld(); + } + 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 = 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); + MarkOld(); + } + 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + GroupAssignmentExtension _GroupAssignmentExtension = new GroupAssignmentExtension(); + [Serializable()] + partial class GroupAssignmentExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GroupAssignmentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupAssignment) + { + // Return the ToString value + return ((GroupAssignment)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GroupInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GroupInfo.cs index 56b50976..c10b6b4c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/GroupInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupInfo.cs @@ -19,427 +19,417 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void GroupInfoEvent(object sender); - /// - /// GroupInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupInfoConverter))] - public partial class GroupInfo : ReadOnlyBase, IDisposable - { - public event GroupInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(GroupInfo groupInfo) - { - if (!_CacheList.Contains(groupInfo)) _CacheList.Add(groupInfo); // In AddToCache - } - protected static void RemoveFromCache(GroupInfo groupInfo) - { - while (_CacheList.Contains(groupInfo)) _CacheList.Remove(groupInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move GroupInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - GroupInfo tmp = _CacheList[0]; // Get the first GroupInfo - string pKey = tmp.GID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first GroupInfo - } - } - internal static void AddList(GroupInfoList lst) - { - foreach (GroupInfo item in lst) AddToCache(item); - } - protected static GroupInfo GetCachedByPrimaryKey(int gid) - { - ConvertListToDictionary(); - string key = gid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - 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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - return _GID; - } - } - private string _GroupName = string.Empty; - public string GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupName", true); - return _GroupName; - } - } - private int? _GroupType; - public int? GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupType", true); - return _GroupType; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _GroupAssignmentCount = 0; - /// - /// Count of GroupAssignments for this Group - /// - public int GroupAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignmentCount", true); - if (_GroupAssignmentCount < 0) - _GroupAssignmentCount = GroupAssignments.Count; - return _GroupAssignmentCount; - } - } - private AssignmentInfoList _GroupAssignments = null; - [TypeConverter(typeof(AssignmentInfoListConverter))] - public AssignmentInfoList GroupAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignments", true); - if (_GroupAssignmentCount < 0 || (_GroupAssignmentCount > 0 && _GroupAssignments == null)) - _GroupAssignments = AssignmentInfoList.GetByGID(_GID); - if (_GroupAssignmentCount < 0) - _GroupAssignmentCount = _GroupAssignments.Count; - return _GroupAssignments; - } - } - public void RefreshGroupAssignments() - { - _GroupAssignmentCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) - foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()]) - tmp._GroupAssignmentCount = -1; // This will cause the data to be requeried - } - private int _GroupMembershipCount = 0; - /// - /// Count of GroupMemberships for this Group - /// - public int GroupMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMembershipCount", true); - if (_GroupMembershipCount < 0) - _GroupMembershipCount = GroupMemberships.Count; - return _GroupMembershipCount; - } - } - private MembershipInfoList _GroupMemberships = null; - [TypeConverter(typeof(MembershipInfoListConverter))] - public MembershipInfoList GroupMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMemberships", true); - if (_GroupMembershipCount < 0 || (_GroupMembershipCount > 0 && _GroupMemberships == null)) - _GroupMemberships = MembershipInfoList.GetByGID(_GID); - if (_GroupMembershipCount < 0) - _GroupMembershipCount = _GroupMemberships.Count; - return _GroupMemberships; - } - } - public void RefreshGroupMemberships() - { - _GroupMembershipCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) - 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 - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check GroupInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupInfo - protected override object GetIdValue() - { - return 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; } } - protected GroupInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~GroupInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(GID.ToString())) return; - List listGroupInfo = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items - while (listGroupInfo.Contains(this)) listGroupInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Group tmp) - { - string key = tmp.GID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (GroupInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Group tmp) - { - _GroupName = tmp.GroupName; - _GroupType = tmp.GroupType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _GroupInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(gid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up GroupInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on GroupInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal GroupInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.Constructor", ex); - throw new DbCslaException("GroupInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _GID; - public int GID - { get { return _GID; } } - public PKCriteria(int gid) - { - _GID = gid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.ReadData", GetHashCode()); - try - { - _GID = dr.GetInt32("GID"); - _GroupName = dr.GetString("GroupName"); - _GroupType = (int?)dr.GetValue("GroupType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); - _GroupMembershipCount = dr.GetInt32("MembershipCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GroupInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGroup"; - cm.Parameters.AddWithValue("@GID", criteria.GID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GroupInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - GroupInfoExtension _GroupInfoExtension = new GroupInfoExtension(); - [Serializable()] - partial class GroupInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(GroupInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class GroupInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GroupInfo) - { - // Return the ToString value - return ((GroupInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void GroupInfoEvent(object sender); + /// + /// GroupInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupInfoConverter))] + public partial class GroupInfo : ReadOnlyBase, IDisposable + { + public event GroupInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(GroupInfo groupInfo) + { + if (!_CacheList.Contains(groupInfo)) _CacheList.Add(groupInfo); // In AddToCache + } + protected static void RemoveFromCache(GroupInfo groupInfo) + { + while (_CacheList.Contains(groupInfo)) _CacheList.Remove(groupInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move GroupInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + GroupInfo tmp = _CacheList[0]; // Get the first GroupInfo + string pKey = tmp.GID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first GroupInfo + } + } + internal static void AddList(GroupInfoList lst) + { + foreach (GroupInfo item in lst) AddToCache(item); + } + protected static GroupInfo GetCachedByPrimaryKey(int gid) + { + ConvertListToDictionary(); + string key = gid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + 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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GID; + } + } + private string _GroupName = string.Empty; + public string GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupName; + } + } + private int? _GroupType; + public int? GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupType; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _GroupAssignmentCount = 0; + /// + /// Count of GroupAssignments for this Group + /// + public int GroupAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupAssignmentCount < 0) + _GroupAssignmentCount = GroupAssignments.Count; + return _GroupAssignmentCount; + } + } + private AssignmentInfoList _GroupAssignments = null; + [TypeConverter(typeof(AssignmentInfoListConverter))] + public AssignmentInfoList GroupAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupAssignmentCount < 0 || (_GroupAssignmentCount > 0 && _GroupAssignments == null)) + _GroupAssignments = AssignmentInfoList.GetByGID(_GID); + if (_GroupAssignmentCount < 0) + _GroupAssignmentCount = _GroupAssignments.Count; + return _GroupAssignments; + } + } + public void RefreshGroupAssignments() + { + _GroupAssignmentCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) + foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()]) + tmp._GroupAssignmentCount = -1; // This will cause the data to be requeried + } + private int _GroupMembershipCount = 0; + /// + /// Count of GroupMemberships for this Group + /// + public int GroupMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupMembershipCount < 0) + _GroupMembershipCount = GroupMemberships.Count; + return _GroupMembershipCount; + } + } + private MembershipInfoList _GroupMemberships = null; + [TypeConverter(typeof(MembershipInfoListConverter))] + public MembershipInfoList GroupMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupMembershipCount < 0 || (_GroupMembershipCount > 0 && _GroupMemberships == null)) + _GroupMemberships = MembershipInfoList.GetByGID(_GID); + if (_GroupMembershipCount < 0) + _GroupMembershipCount = _GroupMemberships.Count; + return _GroupMemberships; + } + } + public void RefreshGroupMemberships() + { + _GroupMembershipCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) + 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 + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check GroupInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupInfo + protected override object GetIdValue() + { + return 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; } } + protected GroupInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~GroupInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(GID.ToString())) return; + List listGroupInfo = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items + while (listGroupInfo.Contains(this)) listGroupInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Group tmp) + { + string key = tmp.GID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (GroupInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Group tmp) + { + _GroupName = tmp.GroupName; + _GroupType = tmp.GroupType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _GroupInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(gid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up GroupInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GroupInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal GroupInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.Constructor", ex); + throw new DbCslaException("GroupInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _GID; + public int GID + { get { return _GID; } } + public PKCriteria(int gid) + { + _GID = gid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.ReadData", GetHashCode()); + try + { + _GID = dr.GetInt32("GID"); + _GroupName = dr.GetString("GroupName"); + _GroupType = (int?)dr.GetValue("GroupType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); + _GroupMembershipCount = dr.GetInt32("MembershipCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GroupInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroup"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GroupInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + GroupInfoExtension _GroupInfoExtension = new GroupInfoExtension(); + [Serializable()] + partial class GroupInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(GroupInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class GroupInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupInfo) + { + // Return the ToString value + return ((GroupInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/GroupMembership.cs b/PROMS/VEPROMS.CSLA.Library/Generated/GroupMembership.cs index 071ef3f5..b080ad3d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/GroupMembership.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/GroupMembership.cs @@ -20,706 +20,678 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// GroupMembership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupMembershipConverter))] - public partial class GroupMembership : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - if (_MyMembership != null) _UGID = _MyMembership.UGID; - return _UGID; - } - } - private Membership _MyMembership; - [System.ComponentModel.DataObjectField(true, true)] - public Membership MyMembership - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyMembership", true); - if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); - return _MyMembership; - } - } - private int _UID; - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - if (_MyUser != null) _UID = _MyUser.UID; - return _UID; - } - } - private User _MyUser; - public User MyUser - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyUser", true); - if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); - return _MyUser; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyUser", true); - if (_MyUser != value) - { - _MyUser = value; - _UID = value.UID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _User_UserID = string.Empty; - public string User_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UserID", true); - return _User_UserID; - } - } - private string _User_FirstName = string.Empty; - public string User_FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_FirstName", true); - return _User_FirstName; - } - } - private string _User_MiddleName = string.Empty; - public string User_MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_MiddleName", true); - return _User_MiddleName; - } - } - private string _User_LastName = string.Empty; - public string User_LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_LastName", true); - return _User_LastName; - } - } - private string _User_Suffix = string.Empty; - public string User_Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_Suffix", true); - return _User_Suffix; - } - } - private string _User_CourtesyTitle = string.Empty; - public string User_CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_CourtesyTitle", true); - return _User_CourtesyTitle; - } - } - private string _User_PhoneNumber = string.Empty; - public string User_PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_PhoneNumber", true); - return _User_PhoneNumber; - } - } - private string _User_CFGName = string.Empty; - public string User_CFGName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_CFGName", true); - return _User_CFGName; - } - } - private string _User_UserLogin = string.Empty; - public string User_UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UserLogin", true); - return _User_UserLogin; - } - } - private string _User_UserName = string.Empty; - public string User_UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UserName", true); - return _User_UserName; - } - } - private string _User_Config = string.Empty; - public string User_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_Config", true); - return _User_Config; - } - } - private DateTime _User_DTS = new DateTime(); - public DateTime User_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_DTS", true); - return _User_DTS; - } - } - private string _User_UsrID = string.Empty; - public string User_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UsrID", true); - return _User_UsrID; - } - } - // CSLATODO: Check GroupMembership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupMembership - protected override object GetIdValue() - { - return MyGroupMembershipUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base GroupMembership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupMembership - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyUser == null ? false : _MyUser.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyUser == null ? true : _MyUser.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyUserRequired, "MyUser"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(GroupMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(GroupMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyUserRequired(GroupMembership target, Csla.Validation.RuleArgs e) - { - if (target._UID == 0 && target._MyUser == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(UID, ""); - //AuthorizationRules.AllowWrite(UID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - 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); - } - public GroupMembership() - { - MarkAsChild(); - _UGID = Membership.NextUGID; - _StartDate = _GroupMembershipExtension.DefaultStartDate; - _DTS = _GroupMembershipExtension.DefaultDTS; - _UsrID = _GroupMembershipExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private GroupMembership(User myUser) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _UGID = Membership.NextUGID; - _StartDate = _GroupMembershipExtension.DefaultStartDate; - _DTS = _GroupMembershipExtension.DefaultDTS; - _UsrID = _GroupMembershipExtension.DefaultUsrID; - _MyUser = myUser; - ValidationRules.CheckRules(); - } - internal GroupMembership(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~GroupMembership() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupMembership.FetchDR", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _UID = dr.GetInt32("UID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _User_UserID = dr.GetString("User_UserID"); - _User_FirstName = dr.GetString("User_FirstName"); - _User_MiddleName = dr.GetString("User_MiddleName"); - _User_LastName = dr.GetString("User_LastName"); - _User_Suffix = dr.GetString("User_Suffix"); - _User_CourtesyTitle = dr.GetString("User_CourtesyTitle"); - _User_PhoneNumber = dr.GetString("User_PhoneNumber"); - _User_CFGName = dr.GetString("User_CFGName"); - _User_UserLogin = dr.GetString("User_UserLogin"); - _User_UserName = dr.GetString("User_UserName"); - _User_Config = dr.GetString("User_Config"); - _User_DTS = dr.GetDateTime("User_DTS"); - _User_UsrID = dr.GetString("User_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupMembership.FetchDR", ex); - throw new DbCslaException("GroupMembership.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - 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"]; - Membership.Remove(cn, _UGID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - GroupMembershipExtension _GroupMembershipExtension = new GroupMembershipExtension(); - [Serializable()] - partial class GroupMembershipExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GroupMembershipConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GroupMembership) - { - // Return the ToString value - return ((GroupMembership)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// GroupMembership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupMembershipConverter))] + public partial class GroupMembership : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership != null) _UGID = _MyMembership.UGID; + return _UGID; + } + } + private Membership _MyMembership; + [System.ComponentModel.DataObjectField(true, true)] + public Membership MyMembership + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); + return _MyMembership; + } + } + private int _UID; + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser != null) _UID = _MyUser.UID; + return _UID; + } + } + private User _MyUser; + public User MyUser + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); + return _MyUser; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyUser != value) + { + _MyUser = value; + _UID = value.UID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _User_UserID = string.Empty; + public string User_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UserID; + } + } + private string _User_FirstName = string.Empty; + public string User_FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_FirstName; + } + } + private string _User_MiddleName = string.Empty; + public string User_MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_MiddleName; + } + } + private string _User_LastName = string.Empty; + public string User_LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_LastName; + } + } + private string _User_Suffix = string.Empty; + public string User_Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_Suffix; + } + } + private string _User_CourtesyTitle = string.Empty; + public string User_CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_CourtesyTitle; + } + } + private string _User_PhoneNumber = string.Empty; + public string User_PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_PhoneNumber; + } + } + private string _User_CFGName = string.Empty; + public string User_CFGName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_CFGName; + } + } + private string _User_UserLogin = string.Empty; + public string User_UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UserLogin; + } + } + private string _User_UserName = string.Empty; + public string User_UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UserName; + } + } + private string _User_Config = string.Empty; + public string User_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_Config; + } + } + private DateTime _User_DTS = new DateTime(); + public DateTime User_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_DTS; + } + } + private string _User_UsrID = string.Empty; + public string User_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UsrID; + } + } + // CSLATODO: Check GroupMembership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupMembership + protected override object GetIdValue() + { + return MyGroupMembershipUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base GroupMembership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupMembership + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyUser == null ? false : _MyUser.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyUser == null ? true : _MyUser.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyUserRequired, "MyUser"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(GroupMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(GroupMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyUserRequired(GroupMembership target, Csla.Validation.RuleArgs e) + { + if (target._UID == 0 && target._MyUser == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(UID, ""); + //AuthorizationRules.AllowWrite(UID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + 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); + } + public GroupMembership() + { + MarkAsChild(); + _UGID = Membership.NextUGID; + _StartDate = _GroupMembershipExtension.DefaultStartDate; + _DTS = _GroupMembershipExtension.DefaultDTS; + _UsrID = _GroupMembershipExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private GroupMembership(User myUser) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _UGID = Membership.NextUGID; + _StartDate = _GroupMembershipExtension.DefaultStartDate; + _DTS = _GroupMembershipExtension.DefaultDTS; + _UsrID = _GroupMembershipExtension.DefaultUsrID; + _MyUser = myUser; + ValidationRules.CheckRules(); + } + internal GroupMembership(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~GroupMembership() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupMembership.FetchDR", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _UID = dr.GetInt32("UID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _User_UserID = dr.GetString("User_UserID"); + _User_FirstName = dr.GetString("User_FirstName"); + _User_MiddleName = dr.GetString("User_MiddleName"); + _User_LastName = dr.GetString("User_LastName"); + _User_Suffix = dr.GetString("User_Suffix"); + _User_CourtesyTitle = dr.GetString("User_CourtesyTitle"); + _User_PhoneNumber = dr.GetString("User_PhoneNumber"); + _User_CFGName = dr.GetString("User_CFGName"); + _User_UserLogin = dr.GetString("User_UserLogin"); + _User_UserName = dr.GetString("User_UserName"); + _User_Config = dr.GetString("User_Config"); + _User_DTS = dr.GetDateTime("User_DTS"); + _User_UsrID = dr.GetString("User_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupMembership.FetchDR", ex); + throw new DbCslaException("GroupMembership.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + 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"]; + Membership.Remove(cn, _UGID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + GroupMembershipExtension _GroupMembershipExtension = new GroupMembershipExtension(); + [Serializable()] + partial class GroupMembershipExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GroupMembershipConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupMembership) + { + // Return the ToString value + return ((GroupMembership)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Image.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Image.cs index d9936cba..65aca996 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Image.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Image.cs @@ -20,1049 +20,1035 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Image Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ImageConverter))] - public partial class Image : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshImages = new List(); - private void AddToRefreshList(List refreshImages) - { - if (IsDirty) - refreshImages.Add(this); - } - private void ClearRefreshList() - { - _RefreshImages = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshImages); - } - private void ProcessRefreshList() - { - foreach (Image tmp in _RefreshImages) - { - ImageInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - 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 - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Image(s) from temporary _CacheList to _CacheByPrimaryKey - { - Image tmp = _CacheList[0]; // Get the first Image - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Image - } - } - protected static Image GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private int _ImageType; - /// - /// 1 - Figure, 2 - Video, 3 - Audio - /// - public int ImageType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageType", true); - return _ImageType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ImageType", true); - if (_ImageType != value) - { - _ImageType = value; - PropertyHasChanged(); - } - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileName", true); - if (value == null) value = string.Empty; - if (_FileName != value) - { - _FileName = value; - PropertyHasChanged(); - } - } - } - private byte[] _Data; - public byte[] Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Data", true); - if (_Data != value) - { - _Data = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base Image.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Image - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Image.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Image - protected override object GetIdValue() - { - return MyImageUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ImageExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(ImageType, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowRead(Data, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ImageType, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowWrite(Data, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ImageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 Image() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Image() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listImage = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listImage.Contains(this)) listImage.Remove(this); // Remove the item from the list - if (listImage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static Image New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Image"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Image.New", ex); - } - } - public static Image New(Content myContent, string fileName, byte[] data) - { - Image tmp = Image.New(); - tmp._MyContent = myContent; - tmp.FileName = fileName; - tmp.Data = data; - return tmp; - } - public static Image New(Content myContent, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID) - { - Image tmp = Image.New(); - tmp._MyContent = myContent; - tmp.ImageType = imageType; - tmp.FileName = fileName; - tmp.Data = data; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Image MakeImage(Content myContent, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID) - { - Image tmp = Image.New(myContent, imageType, fileName, data, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Image New(Content myContent, string fileName, byte[] data, string config) - { - Image tmp = Image.New(); - tmp._MyContent = myContent; - tmp.FileName = fileName; - tmp.Data = data; - tmp.Config = config; - return tmp; - } - public static Image MakeImage(Content myContent, string fileName, byte[] data, string config) - { - Image tmp = Image.New(myContent, fileName, data, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Image New(Content myContent) - { - Image tmp = Image.New(); - tmp._MyContent = myContent; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Image - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Image.Get", ex); - } - } - public static Image Get(SafeDataReader dr) - { - if (dr.Read()) return new Image(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Image.Delete", ex); - } - } - 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(); - Image image = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(image);//Refresh the item in AllList - ProcessRefreshList(); - return image; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// Image Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ImageConverter))] + public partial class Image : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshImages = new List(); + private void AddToRefreshList(List refreshImages) + { + if (IsDirty) + refreshImages.Add(this); + } + private void ClearRefreshList() + { + _RefreshImages = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshImages); + } + private void ProcessRefreshList() + { + foreach (Image tmp in _RefreshImages) + { + ImageInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + 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 + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Image(s) from temporary _CacheList to _CacheByPrimaryKey + { + Image tmp = _CacheList[0]; // Get the first Image + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Image + } + } + protected static Image GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private int _ImageType; + /// + /// 1 - Figure, 2 - Video, 3 - Audio + /// + public int ImageType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ImageType != value) + { + _ImageType = value; + PropertyHasChanged(); + } + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileName != value) + { + _FileName = value; + PropertyHasChanged(); + } + } + } + private byte[] _Data; + public byte[] Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Data != value) + { + _Data = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base Image.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Image + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Image.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Image + protected override object GetIdValue() + { + return MyImageUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ImageExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(ImageType, ""); + //AuthorizationRules.AllowRead(FileName, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ImageType, ""); + //AuthorizationRules.AllowWrite(FileName, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ImageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 Image() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Image() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listImage = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listImage.Contains(this)) listImage.Remove(this); // Remove the item from the list + if (listImage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static Image New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Image"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Image.New", ex); + } + } + public static Image New(Content myContent, string fileName, byte[] data) + { + Image tmp = Image.New(); + tmp._MyContent = myContent; + tmp.FileName = fileName; + tmp.Data = data; + return tmp; + } + public static Image New(Content myContent, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID) + { + Image tmp = Image.New(); + tmp._MyContent = myContent; + tmp.ImageType = imageType; + tmp.FileName = fileName; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Image MakeImage(Content myContent, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID) + { + Image tmp = Image.New(myContent, imageType, fileName, data, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Image New(Content myContent, string fileName, byte[] data, string config) + { + Image tmp = Image.New(); + tmp._MyContent = myContent; + tmp.FileName = fileName; + tmp.Data = data; + tmp.Config = config; + return tmp; + } + public static Image MakeImage(Content myContent, string fileName, byte[] data, string config) + { + Image tmp = Image.New(myContent, fileName, data, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Image New(Content myContent) + { + Image tmp = Image.New(); + tmp._MyContent = myContent; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Image + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Image.Get", ex); + } + } + public static Image Get(SafeDataReader dr) + { + if (dr.Read()) return new Image(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Image.Delete", ex); + } + } + 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(); + Image image = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(image);//Refresh the item in AllList + ProcessRefreshList(); + return image; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _ImageType = _ImageExtension.DefaultImageType; - _DTS = _ImageExtension.DefaultDTS; - _UserID = _ImageExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _ImageType = dr.GetInt32("ImageType"); - _FileName = dr.GetString("FileName"); - _Data = (byte[])dr.GetValue("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Image.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getImage"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Image.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Image.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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", myContent.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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.Add", ex); - throw new DbCslaException("Image.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Content content) - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateImage"; - // 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("@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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteImage"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteImage"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.Remove", ex); - throw new DbCslaException("Image.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Image.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsImage"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Execute", ex); - throw new DbCslaException("Image.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ImageExtension _ImageExtension = new ImageExtension(); - [Serializable()] - partial class ImageExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Image) - { - // Return the ToString value - return ((Image)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _ImageType = _ImageExtension.DefaultImageType; + _DTS = _ImageExtension.DefaultDTS; + _UserID = _ImageExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _ImageType = dr.GetInt32("ImageType"); + _FileName = dr.GetString("FileName"); + _Data = (byte[])dr.GetValue("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Image.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getImage"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Image.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Image.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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", myContent.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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.Add", ex); + throw new DbCslaException("Image.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Content content) + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateImage"; + // 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("@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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteImage"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteImage"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.Remove", ex); + throw new DbCslaException("Image.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Image.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Image.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsImage"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Image.DataPortal_Execute", ex); + throw new DbCslaException("Image.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ImageExtension _ImageExtension = new ImageExtension(); + [Serializable()] + partial class ImageExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Image) + { + // Return the ToString value + return ((Image)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs index 3ac47efe..e7b500b6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAudit.cs @@ -20,983 +20,966 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ImageAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ImageAuditConverter))] - public partial class ImageAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshImageAudits = new List(); - private void AddToRefreshList(List refreshImageAudits) - { - if (IsDirty) - refreshImageAudits.Add(this); - } - private void ClearRefreshList() - { - _RefreshImageAudits = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshImageAudits); - } - private void ProcessRefreshList() - { - foreach (ImageAudit tmp in _RefreshImageAudits) - { - ImageAuditInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ImageAudit imageAudit) - { - if (!_CacheList.Contains(imageAudit)) _CacheList.Add(imageAudit); // In AddToCache - } - protected static void RemoveFromCache(ImageAudit imageAudit) - { - while (_CacheList.Contains(imageAudit)) _CacheList.Remove(imageAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ImageAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - ImageAudit tmp = _CacheList[0]; // Get the first ImageAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ImageAudit - } - } - protected static ImageAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private int _ImageType; - public int ImageType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageType", true); - return _ImageType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ImageType", true); - if (_ImageType != value) - { - _ImageType = value; - PropertyHasChanged(); - } - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileName", true); - if (value == null) value = string.Empty; - if (_FileName != value) - { - _FileName = value; - PropertyHasChanged(); - } - } - } - private byte[] _Data; - public byte[] Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Data", true); - if (_Data != value) - { - _Data = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base ImageAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ImageAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ImageAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ImageAudit - protected override object GetIdValue() - { - return MyImageAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _ImageAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(ImageType, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowRead(Data, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(ImageType, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowWrite(Data, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _ImageAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 ImageAudit() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ImageAudit() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listImageAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listImageAudit.Contains(this)) listImageAudit.Remove(this); // Remove the item from the list - if (listImageAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static ImageAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ImageAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ImageAudit.New", ex); - } - } - public static ImageAudit New(int contentID, int imageType, string fileName, byte[] data, DateTime dts, string userID, int deleteStatus) - { - ImageAudit tmp = ImageAudit.New(); - tmp.ContentID = contentID; - tmp.ImageType = imageType; - tmp.FileName = fileName; - tmp.Data = data; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ImageAudit New(int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) - { - ImageAudit tmp = ImageAudit.New(); - tmp.ContentID = contentID; - tmp.ImageType = imageType; - tmp.FileName = fileName; - tmp.Data = data; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ImageAudit MakeImageAudit(int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) - { - ImageAudit tmp = ImageAudit.New(contentID, imageType, fileName, data, config, dts, userID, deleteStatus); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ImageAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ImageAudit.Get", ex); - } - } - public static ImageAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new ImageAudit(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ImageAudit.Delete", ex); - } - } - 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(); - ImageAudit imageAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(imageAudit);//Refresh the item in AllList - ProcessRefreshList(); - return imageAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// ImageAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ImageAuditConverter))] + public partial class ImageAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshImageAudits = new List(); + private void AddToRefreshList(List refreshImageAudits) + { + if (IsDirty) + refreshImageAudits.Add(this); + } + private void ClearRefreshList() + { + _RefreshImageAudits = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshImageAudits); + } + private void ProcessRefreshList() + { + foreach (ImageAudit tmp in _RefreshImageAudits) + { + ImageAuditInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ImageAudit imageAudit) + { + if (!_CacheList.Contains(imageAudit)) _CacheList.Add(imageAudit); // In AddToCache + } + protected static void RemoveFromCache(ImageAudit imageAudit) + { + while (_CacheList.Contains(imageAudit)) _CacheList.Remove(imageAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ImageAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + ImageAudit tmp = _CacheList[0]; // Get the first ImageAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ImageAudit + } + } + protected static ImageAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private int _ImageType; + public int ImageType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ImageType != value) + { + _ImageType = value; + PropertyHasChanged(); + } + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileName != value) + { + _FileName = value; + PropertyHasChanged(); + } + } + } + private byte[] _Data; + public byte[] Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Data != value) + { + _Data = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ImageAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ImageAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ImageAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ImageAudit + protected override object GetIdValue() + { + return MyImageAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _ImageAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(ImageType, ""); + //AuthorizationRules.AllowRead(FileName, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(ImageType, ""); + //AuthorizationRules.AllowWrite(FileName, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _ImageAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 ImageAudit() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ImageAudit() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listImageAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listImageAudit.Contains(this)) listImageAudit.Remove(this); // Remove the item from the list + if (listImageAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static ImageAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ImageAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAudit.New", ex); + } + } + public static ImageAudit New(int contentID, int imageType, string fileName, byte[] data, DateTime dts, string userID, int deleteStatus) + { + ImageAudit tmp = ImageAudit.New(); + tmp.ContentID = contentID; + tmp.ImageType = imageType; + tmp.FileName = fileName; + tmp.Data = data; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ImageAudit New(int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) + { + ImageAudit tmp = ImageAudit.New(); + tmp.ContentID = contentID; + tmp.ImageType = imageType; + tmp.FileName = fileName; + tmp.Data = data; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ImageAudit MakeImageAudit(int contentID, int imageType, string fileName, byte[] data, string config, DateTime dts, string userID, int deleteStatus) + { + ImageAudit tmp = ImageAudit.New(contentID, imageType, fileName, data, config, dts, userID, deleteStatus); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ImageAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAudit.Get", ex); + } + } + public static ImageAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new ImageAudit(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAudit.Delete", ex); + } + } + 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(); + ImageAudit imageAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(imageAudit);//Refresh the item in AllList + ProcessRefreshList(); + return imageAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _ImageType = dr.GetInt32("ImageType"); - _FileName = dr.GetString("FileName"); - _Data = (byte[])dr.GetValue("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ImageAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getImageAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ImageAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ImageAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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); - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Add", ex); - throw new DbCslaException("ImageAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateImageAudit"; - // Input All Fields - Except Calculated Columns - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteImageAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteImageAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Remove", ex); - throw new DbCslaException("ImageAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - ImageAuditExtension _ImageAuditExtension = new ImageAuditExtension(); - [Serializable()] - partial class ImageAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ImageAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ImageAudit) - { - // Return the ToString value - return ((ImageAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _ImageType = dr.GetInt32("ImageType"); + _FileName = dr.GetString("FileName"); + _Data = (byte[])dr.GetValue("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getImageAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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); + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Add", ex); + throw new DbCslaException("ImageAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateImageAudit"; + // Input All Fields - Except Calculated Columns + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteImageAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteImageAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAudit.Remove", ex); + throw new DbCslaException("ImageAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + ImageAuditExtension _ImageAuditExtension = new ImageAuditExtension(); + [Serializable()] + partial class ImageAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ImageAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ImageAudit) + { + // Return the ToString value + return ((ImageAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfo.cs index 325fd0a8..99e26e9f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ImageAuditInfo.cs @@ -19,385 +19,376 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ImageAuditInfoEvent(object sender); - /// - /// ImageAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ImageAuditInfoConverter))] - public partial class ImageAuditInfo : ReadOnlyBase, IDisposable - { - public event ImageAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ImageAuditInfo imageAuditInfo) - { - if (!_CacheList.Contains(imageAuditInfo)) _CacheList.Add(imageAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(ImageAuditInfo imageAuditInfo) - { - while (_CacheList.Contains(imageAuditInfo)) _CacheList.Remove(imageAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ImageAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ImageAuditInfo tmp = _CacheList[0]; // Get the first ImageAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ImageAuditInfo - } - } - internal static void AddList(ImageAuditInfoList lst) - { - foreach (ImageAuditInfo item in lst) AddToCache(item); - } - protected static ImageAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private int _ImageType; - public int ImageType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageType", true); - return _ImageType; - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - } - private byte[] _Data; - public byte[] Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base ImageAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ImageAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ImageAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ImageAuditInfo - protected override object GetIdValue() - { - return 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; } } - protected ImageAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ImageAuditInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listImageAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listImageAuditInfo.Contains(this)) listImageAuditInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(ImageAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ImageAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ImageAudit tmp) - { - _ContentID = tmp.ContentID; - _ImageType = tmp.ImageType; - _FileName = tmp.FileName; - _Data = tmp.Data; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _ImageAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ImageAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ImageAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ImageAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.Constructor", ex); - throw new DbCslaException("ImageAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _ImageType = dr.GetInt32("ImageType"); - _FileName = dr.GetString("FileName"); - _Data = (byte[])dr.GetValue("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ImageAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getImageAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ImageAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ImageAuditInfoExtension _ImageAuditInfoExtension = new ImageAuditInfoExtension(); - [Serializable()] - partial class ImageAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ImageAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ImageAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ImageAuditInfo) - { - // Return the ToString value - return ((ImageAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ImageAuditInfoEvent(object sender); + /// + /// ImageAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ImageAuditInfoConverter))] + public partial class ImageAuditInfo : ReadOnlyBase, IDisposable + { + public event ImageAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ImageAuditInfo imageAuditInfo) + { + if (!_CacheList.Contains(imageAuditInfo)) _CacheList.Add(imageAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(ImageAuditInfo imageAuditInfo) + { + while (_CacheList.Contains(imageAuditInfo)) _CacheList.Remove(imageAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ImageAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ImageAuditInfo tmp = _CacheList[0]; // Get the first ImageAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ImageAuditInfo + } + } + internal static void AddList(ImageAuditInfoList lst) + { + foreach (ImageAuditInfo item in lst) AddToCache(item); + } + protected static ImageAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private int _ImageType; + public int ImageType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageType; + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + } + private byte[] _Data; + public byte[] Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base ImageAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ImageAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ImageAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ImageAuditInfo + protected override object GetIdValue() + { + return 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; } } + protected ImageAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ImageAuditInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listImageAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listImageAuditInfo.Contains(this)) listImageAuditInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(ImageAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ImageAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ImageAudit tmp) + { + _ContentID = tmp.ContentID; + _ImageType = tmp.ImageType; + _FileName = tmp.FileName; + _Data = tmp.Data; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ImageAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ImageAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ImageAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.Constructor", ex); + throw new DbCslaException("ImageAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _ImageType = dr.GetInt32("ImageType"); + _FileName = dr.GetString("FileName"); + _Data = (byte[])dr.GetValue("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getImageAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ImageAuditInfoExtension _ImageAuditInfoExtension = new ImageAuditInfoExtension(); + [Serializable()] + partial class ImageAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ImageAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ImageAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ImageAuditInfo) + { + // Return the ToString value + return ((ImageAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ImageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ImageInfo.cs index 11972749..36a2a7d4 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ImageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ImageInfo.cs @@ -19,381 +19,373 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ImageInfoEvent(object sender); - /// - /// ImageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ImageInfoConverter))] - public partial class ImageInfo : ReadOnlyBase, IDisposable - { - public event ImageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ImageInfo imageInfo) - { - if (!_CacheList.Contains(imageInfo)) _CacheList.Add(imageInfo); // In AddToCache - } - protected static void RemoveFromCache(ImageInfo imageInfo) - { - while (_CacheList.Contains(imageInfo)) _CacheList.Remove(imageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ImageInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ImageInfo tmp = _CacheList[0]; // Get the first ImageInfo - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ImageInfo - } - } - protected static ImageInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private int _ImageType; - /// - /// 1 - Figure, 2 - Video, 3 - Audio - /// - public int ImageType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageType", true); - return _ImageType; - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - } - private byte[] _Data; - public byte[] Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base ImageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ImageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ImageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ImageInfo - protected override object GetIdValue() - { - return 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; } } - protected ImageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ImageInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listImageInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listImageInfo.Contains(this)) listImageInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Image tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Image tmp) - { - _ImageType = tmp.ImageType; - _FileName = tmp.FileName; - _Data = tmp.Data; - _Config = tmp.Config; - _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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ImageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ImageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ImageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageInfo.Constructor", ex); - throw new DbCslaException("ImageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _ImageType = dr.GetInt32("ImageType"); - _FileName = dr.GetString("FileName"); - _Data = (byte[])dr.GetValue("Data"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ImageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getImage"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ImageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ImageInfoExtension _ImageInfoExtension = new ImageInfoExtension(); - [Serializable()] - partial class ImageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ImageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ImageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ImageInfo) - { - // Return the ToString value - return ((ImageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ImageInfoEvent(object sender); + /// + /// ImageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ImageInfoConverter))] + public partial class ImageInfo : ReadOnlyBase, IDisposable + { + public event ImageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ImageInfo imageInfo) + { + if (!_CacheList.Contains(imageInfo)) _CacheList.Add(imageInfo); // In AddToCache + } + protected static void RemoveFromCache(ImageInfo imageInfo) + { + while (_CacheList.Contains(imageInfo)) _CacheList.Remove(imageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ImageInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ImageInfo tmp = _CacheList[0]; // Get the first ImageInfo + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ImageInfo + } + } + protected static ImageInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private int _ImageType; + /// + /// 1 - Figure, 2 - Video, 3 - Audio + /// + public int ImageType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageType; + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + } + private byte[] _Data; + public byte[] Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base ImageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ImageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ImageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ImageInfo + protected override object GetIdValue() + { + return 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; } } + protected ImageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ImageInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listImageInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listImageInfo.Contains(this)) listImageInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Image tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Image tmp) + { + _ImageType = tmp.ImageType; + _FileName = tmp.FileName; + _Data = tmp.Data; + _Config = tmp.Config; + _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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ImageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ImageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ImageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageInfo.Constructor", ex); + throw new DbCslaException("ImageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _ImageType = dr.GetInt32("ImageType"); + _FileName = dr.GetString("FileName"); + _Data = (byte[])dr.GetValue("Data"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ImageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getImage"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ImageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ImageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ImageInfoExtension _ImageInfoExtension = new ImageInfoExtension(); + [Serializable()] + partial class ImageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ImageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ImageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ImageInfo) + { + // Return the ToString value + return ((ImageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Item.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Item.cs index 91c6263d..2ea29707 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Item.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Item.cs @@ -20,1497 +20,1474 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Item Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemConverter))] - public partial class Item : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshItems = new List(); - private List _RefreshItemAnnotations = new List(); - private List _RefreshItemDocVersions = new List(); - private List _RefreshItemParts = new List(); - private List _RefreshItemTransitions_RangeID = new List(); - private List _RefreshItemTransitions_ToID = new List(); - private void AddToRefreshList(List refreshItems, List refreshItemAnnotations, List refreshItemDocVersions, List refreshItemParts, List refreshItemTransitions_RangeID, List refreshItemTransitions_ToID) - { - if (IsDirty) - refreshItems.Add(this); - if (_ItemAnnotations != null && _ItemAnnotations.IsDirty) - { - foreach (ItemAnnotation tmp in _ItemAnnotations) - { - if (tmp.IsDirty) refreshItemAnnotations.Add(tmp); - } - } - if (_ItemDocVersions != null && _ItemDocVersions.IsDirty) - { - foreach (ItemDocVersion tmp in _ItemDocVersions) - { - if (tmp.IsDirty) refreshItemDocVersions.Add(tmp); - } - } - if (_NextItems != null && _NextItems.IsDirty) - { - foreach (Item tmp in _NextItems) - { - tmp.AddToRefreshList(refreshItems, refreshItemAnnotations, refreshItemDocVersions, refreshItemParts, refreshItemTransitions_RangeID, refreshItemTransitions_ToID); - } - } - if (_ItemParts != null && _ItemParts.IsDirty) - { - foreach (ItemPart tmp in _ItemParts) - { - if (tmp.IsDirty) refreshItemParts.Add(tmp); - } - } - if (_ItemTransitions_RangeID != null && _ItemTransitions_RangeID.IsDirty) - { - foreach (ItemTransition_RangeID tmp in _ItemTransitions_RangeID) - { - if (tmp.IsDirty) refreshItemTransitions_RangeID.Add(tmp); - } - } - if (_ItemTransitions_ToID != null && _ItemTransitions_ToID.IsDirty) - { - foreach (ItemTransition_ToID tmp in _ItemTransitions_ToID) - { - if (tmp.IsDirty) refreshItemTransitions_ToID.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshItems = new List(); - _RefreshItemAnnotations = new List(); - _RefreshItemDocVersions = new List(); - _RefreshItemParts = new List(); - _RefreshItemTransitions_RangeID = new List(); - _RefreshItemTransitions_ToID = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshItems, _RefreshItemAnnotations, _RefreshItemDocVersions, _RefreshItemParts, _RefreshItemTransitions_RangeID, _RefreshItemTransitions_ToID); - } - private void ProcessRefreshList() - { - foreach (Item tmp in _RefreshItems) - { - if (tmp._MyContent != null) - { - ContentInfo.Refresh(tmp._MyContent); - if (tmp._MyContent?.MyImage != null) ImageInfo.Refresh(tmp._MyContent.MyImage); - } - ItemInfo.Refresh(tmp); - } - foreach (ItemAnnotation tmp in _RefreshItemAnnotations) - { - AnnotationInfo.Refresh(tmp); - } - foreach (ItemDocVersion tmp in _RefreshItemDocVersions) - { - DocVersionInfo.Refresh(tmp); - } - foreach (ItemPart tmp in _RefreshItemParts) - { - PartInfo.Refresh(tmp); - } - foreach (ItemTransition_RangeID tmp in _RefreshItemTransitions_RangeID) - { - TransitionInfo.Refresh(tmp); - } - foreach (ItemTransition_ToID tmp in _RefreshItemTransitions_ToID) - { - TransitionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Item item) - { - if (!_CacheList.Contains(item)) _CacheList.Add(item); // In AddToCache - } - protected static void RemoveFromCache(Item item) - { - while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Item(s) from temporary _CacheList to _CacheByPrimaryKey - { - Item tmp = _CacheList[0]; // Get the first Item - string pKey = tmp.ItemID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Item - } - } - protected static Item GetCachedByPrimaryKey(int itemID) - { - ConvertListToDictionary(); - string key = itemID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextItemID = -1; - public static int NextItemID - { - get { return _nextItemID--; } - } - private int _ItemID; - [System.ComponentModel.DataObjectField(true, true)] - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; - return _PreviousID; - } - } - private Item _MyPrevious; - public Item MyPrevious - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPrevious", true); - if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); - return _MyPrevious; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyPrevious", true); - if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyPrevious = value; - _PreviousID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - _ContentID = value.ContentID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ItemAnnotationCount = 0; - /// - /// Count of ItemAnnotations for this Item - /// - public int ItemAnnotationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotationCount", true); - return _ItemAnnotationCount; - } - } - private ItemAnnotations _ItemAnnotations = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemAnnotationsConverter))] - public ItemAnnotations ItemAnnotations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotations", true); - if (_ItemAnnotationCount < 0 || (_ItemAnnotationCount > 0 && _ItemAnnotations == null)) - _ItemAnnotations = ItemAnnotations.GetByItemID(ItemID); - if (_ItemAnnotationCount < 0 ) - _ItemAnnotationCount = _ItemAnnotations == null ? 0 : _ItemAnnotations.Count; - if (_ItemAnnotations == null) - _ItemAnnotations = ItemAnnotations.New(); - return _ItemAnnotations; - } - } - public void Reset_ItemAnnotations() - { - _ItemAnnotationCount = -1; - } - private int _ItemDocVersionCount = 0; - /// - /// Count of ItemDocVersions for this Item - /// - public int ItemDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersionCount", true); - return _ItemDocVersionCount; - } - } - private ItemDocVersions _ItemDocVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemDocVersionsConverter))] - public ItemDocVersions ItemDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersions", true); - if (_ItemDocVersionCount < 0 || (_ItemDocVersionCount > 0 && _ItemDocVersions == null)) - _ItemDocVersions = ItemDocVersions.GetByItemID(ItemID); - if (_ItemDocVersionCount < 0 ) - _ItemDocVersionCount = _ItemDocVersions == null ? 0 : _ItemDocVersions.Count; - if (_ItemDocVersions == null) - _ItemDocVersions = ItemDocVersions.New(); - return _ItemDocVersions; - } - } - public void Reset_ItemDocVersions() - { - _ItemDocVersionCount = -1; - } - private int _NextItemCount = 0; - /// - /// Count of NextItems for this Item - /// - public int NextItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItemCount", true); - return _NextItemCount; - } - } - private NextItems _NextItems = null; - /// - /// Related Field - /// - [TypeConverter(typeof(NextItemsConverter))] - public NextItems NextItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItems", true); - if (_NextItemCount < 0 || (_NextItemCount > 0 && _NextItems == null)) - _NextItems = NextItems.GetByPreviousID(ItemID); - if (_NextItemCount < 0 ) - _NextItemCount = _NextItems == null ? 0 : _NextItems.Count; - if (_NextItems == null) - _NextItems = NextItems.New(); - return _NextItems; - } - } - public void Reset_NextItems() - { - _NextItemCount = -1; - } - private int _ItemPartCount = 0; - /// - /// Count of ItemParts for this Item - /// - public int ItemPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemPartCount", true); - return _ItemPartCount; - } - } - private ItemParts _ItemParts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemPartsConverter))] - public ItemParts ItemParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemParts", true); - if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) - _ItemParts = ItemParts.GetByItemID(ItemID); - if (_ItemPartCount < 0 ) - _ItemPartCount = _ItemParts == null ? 0 : _ItemParts.Count; - if (_ItemParts == null) - _ItemParts = ItemParts.New(); - return _ItemParts; - } - } - public void Reset_ItemParts() - { - _ItemPartCount = -1; - } - private int _ItemTransition_RangeIDCount = 0; - /// - /// Count of ItemTransitions for this Item - /// - public int ItemTransition_RangeIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_RangeIDCount", true); - return _ItemTransition_RangeIDCount; - } - } - private ItemTransitions_RangeID _ItemTransitions_RangeID = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemTransitions_RangeIDConverter))] - public ItemTransitions_RangeID ItemTransitions_RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_RangeID", true); - if (_ItemTransition_RangeIDCount < 0 || (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null)) - _ItemTransitions_RangeID = ItemTransitions_RangeID.GetByRangeID(ItemID); - if (_ItemTransition_RangeIDCount < 0 ) - _ItemTransition_RangeIDCount = _ItemTransitions_RangeID == null ? 0 : _ItemTransitions_RangeID.Count; - if (_ItemTransitions_RangeID == null) - _ItemTransitions_RangeID = ItemTransitions_RangeID.New(); - return _ItemTransitions_RangeID; - } - } - public void Reset_ItemTransitions_RangeID() - { - _ItemTransition_RangeIDCount = -1; - } - private int _ItemTransition_ToIDCount = 0; - /// - /// Count of ItemTransitions for this Item - /// - public int ItemTransition_ToIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_ToIDCount", true); - return _ItemTransition_ToIDCount; - } - } - private ItemTransitions_ToID _ItemTransitions_ToID = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemTransitions_ToIDConverter))] - public ItemTransitions_ToID ItemTransitions_ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_ToID", true); - if (_ItemTransition_ToIDCount < 0 || (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null)) - _ItemTransitions_ToID = ItemTransitions_ToID.GetByToID(ItemID); - if (_ItemTransition_ToIDCount < 0 ) - _ItemTransition_ToIDCount = _ItemTransitions_ToID == null ? 0 : _ItemTransitions_ToID.Count; - if (_ItemTransitions_ToID == null) - _ItemTransitions_ToID = ItemTransitions_ToID.New(); - return _ItemTransitions_ToID; - } - } - public void Reset_ItemTransitions_ToID() - { - _ItemTransition_ToIDCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : 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)); - } - // CSLATODO: Replace base Item.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Item - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Item.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Item - protected override object GetIdValue() - { - return MyItemUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ItemAnnotations != null && (hasBrokenRules = _ItemAnnotations.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemDocVersions != null && (hasBrokenRules = _ItemDocVersions.HasBrokenRules) != null) return hasBrokenRules; - if (_NextItems != null && (hasBrokenRules = _NextItems.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemParts != null && (hasBrokenRules = _ItemParts.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemTransitions_RangeID != null && (hasBrokenRules = _ItemTransitions_RangeID.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemTransitions_ToID != null && (hasBrokenRules = _ItemTransitions_ToID.HasBrokenRules) != null) return hasBrokenRules; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ItemExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ItemExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyContentRequired(Item target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(PreviousID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(PreviousID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ItemExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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; } } - 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 Item() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Item() - { - _CountFinalized++; - } - private bool _DisposeOfContent = true; // part B2017-060 when Item is in a Using statement, the content was being freed after it's use, we needed the content to stick around + /// + /// Item Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemConverter))] + public partial class Item : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshItems = new List(); + private List _RefreshItemAnnotations = new List(); + private List _RefreshItemDocVersions = new List(); + private List _RefreshItemParts = new List(); + private List _RefreshItemTransitions_RangeID = new List(); + private List _RefreshItemTransitions_ToID = new List(); + private void AddToRefreshList(List refreshItems, List refreshItemAnnotations, List refreshItemDocVersions, List refreshItemParts, List refreshItemTransitions_RangeID, List refreshItemTransitions_ToID) + { + if (IsDirty) + refreshItems.Add(this); + if (_ItemAnnotations != null && _ItemAnnotations.IsDirty) + { + foreach (ItemAnnotation tmp in _ItemAnnotations) + { + if (tmp.IsDirty) refreshItemAnnotations.Add(tmp); + } + } + if (_ItemDocVersions != null && _ItemDocVersions.IsDirty) + { + foreach (ItemDocVersion tmp in _ItemDocVersions) + { + if (tmp.IsDirty) refreshItemDocVersions.Add(tmp); + } + } + if (_NextItems != null && _NextItems.IsDirty) + { + foreach (Item tmp in _NextItems) + { + tmp.AddToRefreshList(refreshItems, refreshItemAnnotations, refreshItemDocVersions, refreshItemParts, refreshItemTransitions_RangeID, refreshItemTransitions_ToID); + } + } + if (_ItemParts != null && _ItemParts.IsDirty) + { + foreach (ItemPart tmp in _ItemParts) + { + if (tmp.IsDirty) refreshItemParts.Add(tmp); + } + } + if (_ItemTransitions_RangeID != null && _ItemTransitions_RangeID.IsDirty) + { + foreach (ItemTransition_RangeID tmp in _ItemTransitions_RangeID) + { + if (tmp.IsDirty) refreshItemTransitions_RangeID.Add(tmp); + } + } + if (_ItemTransitions_ToID != null && _ItemTransitions_ToID.IsDirty) + { + foreach (ItemTransition_ToID tmp in _ItemTransitions_ToID) + { + if (tmp.IsDirty) refreshItemTransitions_ToID.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshItems = new List(); + _RefreshItemAnnotations = new List(); + _RefreshItemDocVersions = new List(); + _RefreshItemParts = new List(); + _RefreshItemTransitions_RangeID = new List(); + _RefreshItemTransitions_ToID = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshItems, _RefreshItemAnnotations, _RefreshItemDocVersions, _RefreshItemParts, _RefreshItemTransitions_RangeID, _RefreshItemTransitions_ToID); + } + private void ProcessRefreshList() + { + foreach (Item tmp in _RefreshItems) + { + if (tmp._MyContent != null) + { + ContentInfo.Refresh(tmp._MyContent); + if (tmp._MyContent?.MyImage != null) ImageInfo.Refresh(tmp._MyContent.MyImage); + } + ItemInfo.Refresh(tmp); + } + foreach (ItemAnnotation tmp in _RefreshItemAnnotations) + { + AnnotationInfo.Refresh(tmp); + } + foreach (ItemDocVersion tmp in _RefreshItemDocVersions) + { + DocVersionInfo.Refresh(tmp); + } + foreach (ItemPart tmp in _RefreshItemParts) + { + PartInfo.Refresh(tmp); + } + foreach (ItemTransition_RangeID tmp in _RefreshItemTransitions_RangeID) + { + TransitionInfo.Refresh(tmp); + } + foreach (ItemTransition_ToID tmp in _RefreshItemTransitions_ToID) + { + TransitionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Item item) + { + if (!_CacheList.Contains(item)) _CacheList.Add(item); // In AddToCache + } + protected static void RemoveFromCache(Item item) + { + while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Item(s) from temporary _CacheList to _CacheByPrimaryKey + { + Item tmp = _CacheList[0]; // Get the first Item + string pKey = tmp.ItemID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Item + } + } + protected static Item GetCachedByPrimaryKey(int itemID) + { + ConvertListToDictionary(); + string key = itemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextItemID = -1; + public static int NextItemID + { + get { return _nextItemID--; } + } + private int _ItemID; + [System.ComponentModel.DataObjectField(true, true)] + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; + return _PreviousID; + } + } + private Item _MyPrevious; + public Item MyPrevious + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); + return _MyPrevious; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyPrevious = value; + _PreviousID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + _ContentID = value.ContentID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ItemAnnotationCount = 0; + /// + /// Count of ItemAnnotations for this Item + /// + public int ItemAnnotationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemAnnotationCount; + } + } + private ItemAnnotations _ItemAnnotations = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemAnnotationsConverter))] + public ItemAnnotations ItemAnnotations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemAnnotationCount < 0 || (_ItemAnnotationCount > 0 && _ItemAnnotations == null)) + _ItemAnnotations = ItemAnnotations.GetByItemID(ItemID); + if (_ItemAnnotationCount < 0) + _ItemAnnotationCount = _ItemAnnotations == null ? 0 : _ItemAnnotations.Count; + if (_ItemAnnotations == null) + _ItemAnnotations = ItemAnnotations.New(); + return _ItemAnnotations; + } + } + public void Reset_ItemAnnotations() + { + _ItemAnnotationCount = -1; + } + private int _ItemDocVersionCount = 0; + /// + /// Count of ItemDocVersions for this Item + /// + public int ItemDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemDocVersionCount; + } + } + private ItemDocVersions _ItemDocVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemDocVersionsConverter))] + public ItemDocVersions ItemDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemDocVersionCount < 0 || (_ItemDocVersionCount > 0 && _ItemDocVersions == null)) + _ItemDocVersions = ItemDocVersions.GetByItemID(ItemID); + if (_ItemDocVersionCount < 0) + _ItemDocVersionCount = _ItemDocVersions == null ? 0 : _ItemDocVersions.Count; + if (_ItemDocVersions == null) + _ItemDocVersions = ItemDocVersions.New(); + return _ItemDocVersions; + } + } + public void Reset_ItemDocVersions() + { + _ItemDocVersionCount = -1; + } + private int _NextItemCount = 0; + /// + /// Count of NextItems for this Item + /// + public int NextItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _NextItemCount; + } + } + private NextItems _NextItems = null; + /// + /// Related Field + /// + [TypeConverter(typeof(NextItemsConverter))] + public NextItems NextItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_NextItemCount < 0 || (_NextItemCount > 0 && _NextItems == null)) + _NextItems = NextItems.GetByPreviousID(ItemID); + if (_NextItemCount < 0) + _NextItemCount = _NextItems == null ? 0 : _NextItems.Count; + if (_NextItems == null) + _NextItems = NextItems.New(); + return _NextItems; + } + } + public void Reset_NextItems() + { + _NextItemCount = -1; + } + private int _ItemPartCount = 0; + /// + /// Count of ItemParts for this Item + /// + public int ItemPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemPartCount; + } + } + private ItemParts _ItemParts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemPartsConverter))] + public ItemParts ItemParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) + _ItemParts = ItemParts.GetByItemID(ItemID); + if (_ItemPartCount < 0) + _ItemPartCount = _ItemParts == null ? 0 : _ItemParts.Count; + if (_ItemParts == null) + _ItemParts = ItemParts.New(); + return _ItemParts; + } + } + public void Reset_ItemParts() + { + _ItemPartCount = -1; + } + private int _ItemTransition_RangeIDCount = 0; + /// + /// Count of ItemTransitions for this Item + /// + public int ItemTransition_RangeIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemTransition_RangeIDCount; + } + } + private ItemTransitions_RangeID _ItemTransitions_RangeID = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemTransitions_RangeIDConverter))] + public ItemTransitions_RangeID ItemTransitions_RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_RangeIDCount < 0 || (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null)) + _ItemTransitions_RangeID = ItemTransitions_RangeID.GetByRangeID(ItemID); + if (_ItemTransition_RangeIDCount < 0) + _ItemTransition_RangeIDCount = _ItemTransitions_RangeID == null ? 0 : _ItemTransitions_RangeID.Count; + if (_ItemTransitions_RangeID == null) + _ItemTransitions_RangeID = ItemTransitions_RangeID.New(); + return _ItemTransitions_RangeID; + } + } + public void Reset_ItemTransitions_RangeID() + { + _ItemTransition_RangeIDCount = -1; + } + private int _ItemTransition_ToIDCount = 0; + /// + /// Count of ItemTransitions for this Item + /// + public int ItemTransition_ToIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemTransition_ToIDCount; + } + } + private ItemTransitions_ToID _ItemTransitions_ToID = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemTransitions_ToIDConverter))] + public ItemTransitions_ToID ItemTransitions_ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_ToIDCount < 0 || (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null)) + _ItemTransitions_ToID = ItemTransitions_ToID.GetByToID(ItemID); + if (_ItemTransition_ToIDCount < 0) + _ItemTransition_ToIDCount = _ItemTransitions_ToID == null ? 0 : _ItemTransitions_ToID.Count; + if (_ItemTransitions_ToID == null) + _ItemTransitions_ToID = ItemTransitions_ToID.New(); + return _ItemTransitions_ToID; + } + } + public void Reset_ItemTransitions_ToID() + { + _ItemTransition_ToIDCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : 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)); + } + // CSLATODO: Replace base Item.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Item + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Item.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Item + protected override object GetIdValue() + { + return MyItemUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ItemAnnotations != null && (hasBrokenRules = _ItemAnnotations.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemDocVersions != null && (hasBrokenRules = _ItemDocVersions.HasBrokenRules) != null) return hasBrokenRules; + if (_NextItems != null && (hasBrokenRules = _NextItems.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemParts != null && (hasBrokenRules = _ItemParts.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemTransitions_RangeID != null && (hasBrokenRules = _ItemTransitions_RangeID.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemTransitions_ToID != null && (hasBrokenRules = _ItemTransitions_ToID.HasBrokenRules) != null) return hasBrokenRules; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ItemExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ItemExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyContentRequired(Item target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(PreviousID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(PreviousID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ItemExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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; } } + 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 Item() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Item() + { + _CountFinalized++; + } + private bool _DisposeOfContent = true; // part B2017-060 when Item is in a Using statement, the content was being freed after it's use, we needed the content to stick around - public bool DisposeOfContent - { - get { return _DisposeOfContent; } - set { _DisposeOfContent = value; } - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - if (_MyContent != null && DisposeOfContent) - { - _MyContent.Dispose(); - _MyContent = null; - } - if (_ItemTransitions_RangeID != null) - _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() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) - { - List listItem = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items - while (listItem.Contains(this)) listItem.Remove(this); // Remove the item from the list - if (listItem.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list - } - } - public static Item New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Item"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.New", ex); - } - } - public static Item New(Content myContent) - { - Item tmp = Item.New(); - tmp.MyContent = myContent; - return tmp; - } - public static Item New(Item myPrevious, Content myContent, DateTime dts, string userID) - { - Item tmp = Item.New(); - tmp.MyPrevious = myPrevious; - tmp.MyContent = myContent; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Item MakeItem(Item myPrevious, Content myContent, DateTime dts, string userID) - { - Item tmp = Item.New(myPrevious, myContent, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Item New(Item myPrevious, Content myContent) - { - Item tmp = Item.New(); - tmp.MyPrevious = myPrevious; - tmp.MyContent = myContent; - return tmp; - } - public static Item MakeItem(Item myPrevious, Content myContent) - { - Item tmp = Item.New(myPrevious, myContent); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(itemID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Item - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.Get", ex); - } - } - public static Item Get(SafeDataReader dr, Item previous) - { - if (dr.Read()) return new Item(dr, previous); - return null; - } - internal Item(SafeDataReader dr) - { - ReadData(dr); - } - private Item(SafeDataReader dr, Item previous) - { - ReadData(dr); - MarkAsChild(); - } - internal Item(SafeDataReader dr, int parentID) - { - ReadData(dr); - MarkAsChild(); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.Delete", ex); - } - } - 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(); - Item item = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(item);//Refresh the item in AllList - ProcessRefreshList(); - return item; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ItemID; - public int ItemID - { get { return _ItemID; } } - public PKCriteria(int itemID) - { - _ItemID = itemID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ItemID = NextItemID; - // Database Defaults - _DTS = _ItemExtension.DefaultDTS; - _UserID = _ItemExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.ReadData", GetHashCode()); - try - { - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); - _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); - _NextItemCount = dr.GetInt32("NextCount"); - _ItemPartCount = dr.GetInt32("PartCount"); - _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); - _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Item.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItem"; - cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ItemAnnotations = ItemAnnotations.Get(dr); - // load child objects - dr.NextResult(); - _ItemDocVersions = ItemDocVersions.Get(dr); - // load child objects - dr.NextResult(); - _ItemParts = ItemParts.Get(dr); - // load child objects - dr.NextResult(); - _ItemTransitions_RangeID = ItemTransitions_RangeID.Get(dr); - // load child objects - dr.NextResult(); - _ItemTransitions_ToID = ItemTransitions_ToID.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Item.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Item.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - 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); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addItem"; - // Input All Fields - Except Calculated Columns - if (myPrevious != null) cm.Parameters.AddWithValue("@PreviousID", myPrevious.ItemID); - cm.Parameters.AddWithValue("@ContentID", myContent.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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Add", ex); - throw new DbCslaException("Item.Add", ex); - } - } - public static void DeactivateStateDisplayTabTmp(string UserID) - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - try - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "DeactivateStateDisplayTabTmp"; - cm.CommandTimeout = Database.DefaultTimeout; - cm.Parameters.AddWithValue("@UserID", UserID); - cm.ExecuteNonQuery(); - } - catch (Exception ex) - { - Database.LogException("ItemExt.DeactivateStateDisplayTabTmp", ex); - } + public bool DisposeOfContent + { + get { return _DisposeOfContent; } + set { _DisposeOfContent = value; } + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + if (_MyContent != null && DisposeOfContent) + { + _MyContent.Dispose(); + _MyContent = null; + } + if (_ItemTransitions_RangeID != null) + _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() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) + { + List listItem = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items + while (listItem.Contains(this)) listItem.Remove(this); // Remove the item from the list + if (listItem.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list + } + } + public static Item New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Item"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.New", ex); + } + } + public static Item New(Content myContent) + { + Item tmp = Item.New(); + tmp.MyContent = myContent; + return tmp; + } + public static Item New(Item myPrevious, Content myContent, DateTime dts, string userID) + { + Item tmp = Item.New(); + tmp.MyPrevious = myPrevious; + tmp.MyContent = myContent; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Item MakeItem(Item myPrevious, Content myContent, DateTime dts, string userID) + { + Item tmp = Item.New(myPrevious, myContent, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Item New(Item myPrevious, Content myContent) + { + Item tmp = Item.New(); + tmp.MyPrevious = myPrevious; + tmp.MyContent = myContent; + return tmp; + } + public static Item MakeItem(Item myPrevious, Content myContent) + { + Item tmp = Item.New(myPrevious, myContent); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Item + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Get", ex); + } + } + public static Item Get(SafeDataReader dr, Item previous) + { + if (dr.Read()) return new Item(dr, previous); + return null; + } + internal Item(SafeDataReader dr) + { + ReadData(dr); + } + private Item(SafeDataReader dr, Item previous) + { + ReadData(dr); + MarkAsChild(); + } + internal Item(SafeDataReader dr, int parentID) + { + ReadData(dr); + MarkAsChild(); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Delete", ex); + } + } + 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(); + Item item = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(item);//Refresh the item in AllList + ProcessRefreshList(); + return item; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + public PKCriteria(int itemID) + { + _ItemID = itemID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ItemID = NextItemID; + // Database Defaults + _DTS = _ItemExtension.DefaultDTS; + _UserID = _ItemExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.ReadData", GetHashCode()); + try + { + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); + _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); + _NextItemCount = dr.GetInt32("NextCount"); + _ItemPartCount = dr.GetInt32("PartCount"); + _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); + _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Item.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItem"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ItemAnnotations = ItemAnnotations.Get(dr); + // load child objects + dr.NextResult(); + _ItemDocVersions = ItemDocVersions.Get(dr); + // load child objects + dr.NextResult(); + _ItemParts = ItemParts.Get(dr); + // load child objects + dr.NextResult(); + _ItemTransitions_RangeID = ItemTransitions_RangeID.Get(dr); + // load child objects + dr.NextResult(); + _ItemTransitions_ToID = ItemTransitions_ToID.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Item.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Item.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + 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); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addItem"; + // Input All Fields - Except Calculated Columns + if (myPrevious != null) cm.Parameters.AddWithValue("@PreviousID", myPrevious.ItemID); + cm.Parameters.AddWithValue("@ContentID", myContent.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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Add", ex); + throw new DbCslaException("Item.Add", ex); + } + } + public static void DeactivateStateDisplayTabTmp(string UserID) + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + try + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "DeactivateStateDisplayTabTmp"; + cm.CommandTimeout = Database.DefaultTimeout; + cm.Parameters.AddWithValue("@UserID", UserID); + cm.ExecuteNonQuery(); + } + catch (Exception ex) + { + Database.LogException("ItemExt.DeactivateStateDisplayTabTmp", ex); + } - } - } - } - public static void AddDisplayTabsState(int itemID, string displayTabID, string displayTabName, string UserID, int order) - //private void DataPortal_Fetch(int itemID, string displayTabID, string displayTabName) - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - try - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "AddDisplayTabState"; - cm.CommandTimeout = Database.DefaultTimeout; - cm.Parameters.AddWithValue("@ItemID", itemID); - cm.Parameters.AddWithValue("@displayTabID", displayTabID); - cm.Parameters.AddWithValue("@displayTabName", displayTabName); - cm.Parameters.AddWithValue("@UserID", UserID); - cm.Parameters.AddWithValue("@order", order); - cm.ExecuteNonQuery(); - } - catch (Exception ex) - { - Database.LogException("ItemExt.AddDisplayTabsState", ex); - } - } - } - } - public static DataTable GetDisplayTabs(string UserID) //, string displayTabID, string displayTabName) - //public static void DeactivateStateDisplayTabTmp(string UserID) - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - try - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "GetDisplayTabdata"; - cm.CommandTimeout = Database.DefaultTimeout; - cm.Parameters.AddWithValue("@UserID", UserID); - SqlDataAdapter da = new SqlDataAdapter(cm); + } + } + } + public static void AddDisplayTabsState(int itemID, string displayTabID, string displayTabName, string UserID, int order) + //private void DataPortal_Fetch(int itemID, string displayTabID, string displayTabName) + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + try + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "AddDisplayTabState"; + cm.CommandTimeout = Database.DefaultTimeout; + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@displayTabID", displayTabID); + cm.Parameters.AddWithValue("@displayTabName", displayTabName); + cm.Parameters.AddWithValue("@UserID", UserID); + cm.Parameters.AddWithValue("@order", order); + cm.ExecuteNonQuery(); + } + catch (Exception ex) + { + Database.LogException("ItemExt.AddDisplayTabsState", ex); + } + } + } + } + public static DataTable GetDisplayTabs(string UserID) //, string displayTabID, string displayTabName) + //public static void DeactivateStateDisplayTabTmp(string UserID) + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + try + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "GetDisplayTabdata"; + cm.CommandTimeout = Database.DefaultTimeout; + cm.Parameters.AddWithValue("@UserID", UserID); + SqlDataAdapter da = new SqlDataAdapter(cm); - SqlDataReader reader = cm.ExecuteReader(); - DataTable dt = new DataTable(); - dt.Load(reader); - return dt; + SqlDataReader reader = cm.ExecuteReader(); + DataTable dt = new DataTable(); + dt.Load(reader); + return dt; - } - catch (Exception ex) - { - //B2025-004 - //if it fails loading previously open tabs, simply treat it as if no tabs were open - //instead of crashing - return new DataTable(); - } + } + catch (Exception ex) + { + //B2025-004 + //if it fails loading previously open tabs, simply treat it as if no tabs were open + //instead of crashing + return new DataTable(); + } - } - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - 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); - 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; - } - } - 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - } - internal void DeleteSelf(Item item) - { - // 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"]; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateItem"; - // 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("@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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteItem"; - cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteItem"; - // Input PK Fields - cm.Parameters.AddWithValue("@ItemID", itemID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Remove", ex); - throw new DbCslaException("Item.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int itemID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(itemID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ItemID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int itemID) - { - _ItemID = itemID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsItem"; - cm.Parameters.AddWithValue("@ItemID", _ItemID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Execute", ex); - throw new DbCslaException("Item.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ItemExtension _ItemExtension = new ItemExtension(); - [Serializable()] - partial class ItemExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Item) - { - // Return the ToString value - return ((Item)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + } + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + 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); + 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; + } + } + 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + } + internal void DeleteSelf(Item item) + { + // 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"]; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateItem"; + // 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("@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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteItem"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteItem"; + // Input PK Fields + cm.Parameters.AddWithValue("@ItemID", itemID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Remove", ex); + throw new DbCslaException("Item.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int itemID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(itemID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ItemID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int itemID) + { + _ItemID = itemID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsItem"; + cm.Parameters.AddWithValue("@ItemID", _ItemID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Execute", ex); + throw new DbCslaException("Item.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ItemExtension _ItemExtension = new ItemExtension(); + [Serializable()] + partial class ItemExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Item) + { + // Return the ToString value + return ((Item)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotation.cs index e5ea6f6c..1f4f60ff 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAnnotation.cs @@ -20,559 +20,540 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemAnnotation Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemAnnotationConverter))] - public partial class ItemAnnotation : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _AnnotationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AnnotationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationID", true); - if (_MyAnnotation != null) _AnnotationID = _MyAnnotation.AnnotationID; - return _AnnotationID; - } - } - private Annotation _MyAnnotation; - [System.ComponentModel.DataObjectField(true, true)] - public Annotation MyAnnotation - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAnnotation", true); - if (_MyAnnotation == null && _AnnotationID != 0) _MyAnnotation = Annotation.Get(_AnnotationID); - return _MyAnnotation; - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; - return _TypeID; - } - } - private AnnotationType _MyAnnotationType; - public AnnotationType MyAnnotationType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAnnotationType", true); - if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID); - return _MyAnnotationType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyAnnotationType", true); - if (_MyAnnotationType != value) - { - _MyAnnotationType = value; - _TypeID = value.TypeID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _RtfText = string.Empty; - public string RtfText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RtfText", true); - return _RtfText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("RtfText", true); - if (value == null) value = string.Empty; - if (_RtfText != value) - { - _RtfText = value; - PropertyHasChanged(); - } - } - } - private string _SearchText = string.Empty; - public string SearchText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SearchText", true); - return _SearchText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SearchText", true); - if (value == null) value = string.Empty; - if (_SearchText != value) - { - _SearchText = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _AnnotationType_Name = string.Empty; - public string AnnotationType_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_Name", true); - return _AnnotationType_Name; - } - } - private string _AnnotationType_Config = string.Empty; - public string AnnotationType_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_Config", true); - return _AnnotationType_Config; - } - } - private DateTime _AnnotationType_DTS = new DateTime(); - public DateTime AnnotationType_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_DTS", true); - return _AnnotationType_DTS; - } - } - private string _AnnotationType_UserID = string.Empty; - public string AnnotationType_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_UserID", true); - return _AnnotationType_UserID; - } - } - // CSLATODO: Check ItemAnnotation.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemAnnotation - protected override object GetIdValue() - { - return MyItemAnnotationUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ItemAnnotation.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemAnnotation - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyAnnotationTypeRequired, "MyAnnotationType"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyAnnotationTypeRequired(ItemAnnotation target, Csla.Validation.RuleArgs e) - { - if (target._TypeID == 0 && target._MyAnnotationType == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(TypeID, ""); - //AuthorizationRules.AllowWrite(TypeID, ""); - //AuthorizationRules.AllowRead(RtfText, ""); - //AuthorizationRules.AllowWrite(RtfText, ""); - //AuthorizationRules.AllowRead(SearchText, ""); - //AuthorizationRules.AllowWrite(SearchText, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public ItemAnnotation() - { - MarkAsChild(); - _AnnotationID = Annotation.NextAnnotationID; - _DTS = _ItemAnnotationExtension.DefaultDTS; - _UserID = _ItemAnnotationExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemAnnotation(AnnotationType myAnnotationType) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _AnnotationID = Annotation.NextAnnotationID; - _DTS = _ItemAnnotationExtension.DefaultDTS; - _UserID = _ItemAnnotationExtension.DefaultUserID; - _MyAnnotationType = myAnnotationType; - ValidationRules.CheckRules(); - } - internal ItemAnnotation(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ItemAnnotation() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAnnotation.FetchDR", GetHashCode()); - try - { - _AnnotationID = dr.GetInt32("AnnotationID"); - _TypeID = dr.GetInt32("TypeID"); - _RtfText = dr.GetString("RtfText"); - _SearchText = dr.GetString("SearchText"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _AnnotationType_Name = dr.GetString("AnnotationType_Name"); - _AnnotationType_Config = dr.GetString("AnnotationType_Config"); - _AnnotationType_DTS = dr.GetDateTime("AnnotationType_DTS"); - _AnnotationType_UserID = dr.GetString("AnnotationType_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAnnotation.FetchDR", ex); - throw new DbCslaException("ItemAnnotation.Fetch", ex); - } - MarkOld(); - } - 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); - 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); - MarkOld(); - } - 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"]; - Annotation.Remove(cn, _AnnotationID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension(); - [Serializable()] - partial class ItemAnnotationExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemAnnotationConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemAnnotation) - { - // Return the ToString value - return ((ItemAnnotation)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemAnnotation Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAnnotationConverter))] + public partial class ItemAnnotation : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _AnnotationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotation != null) _AnnotationID = _MyAnnotation.AnnotationID; + return _AnnotationID; + } + } + private Annotation _MyAnnotation; + [System.ComponentModel.DataObjectField(true, true)] + public Annotation MyAnnotation + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotation == null && _AnnotationID != 0) _MyAnnotation = Annotation.Get(_AnnotationID); + return _MyAnnotation; + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; + return _TypeID; + } + } + private AnnotationType _MyAnnotationType; + public AnnotationType MyAnnotationType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID); + return _MyAnnotationType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyAnnotationType != value) + { + _MyAnnotationType = value; + _TypeID = value.TypeID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RtfText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_RtfText != value) + { + _RtfText = value; + PropertyHasChanged(); + } + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SearchText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_SearchText != value) + { + _SearchText = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _AnnotationType_Name = string.Empty; + public string AnnotationType_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_Name; + } + } + private string _AnnotationType_Config = string.Empty; + public string AnnotationType_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_Config; + } + } + private DateTime _AnnotationType_DTS = new DateTime(); + public DateTime AnnotationType_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_DTS; + } + } + private string _AnnotationType_UserID = string.Empty; + public string AnnotationType_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_UserID; + } + } + // CSLATODO: Check ItemAnnotation.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemAnnotation + protected override object GetIdValue() + { + return MyItemAnnotationUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ItemAnnotation.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemAnnotation + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyAnnotationTypeRequired, "MyAnnotationType"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyAnnotationTypeRequired(ItemAnnotation target, Csla.Validation.RuleArgs e) + { + if (target._TypeID == 0 && target._MyAnnotationType == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowWrite(TypeID, ""); + //AuthorizationRules.AllowRead(RtfText, ""); + //AuthorizationRules.AllowWrite(RtfText, ""); + //AuthorizationRules.AllowRead(SearchText, ""); + //AuthorizationRules.AllowWrite(SearchText, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public ItemAnnotation() + { + MarkAsChild(); + _AnnotationID = Annotation.NextAnnotationID; + _DTS = _ItemAnnotationExtension.DefaultDTS; + _UserID = _ItemAnnotationExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemAnnotation(AnnotationType myAnnotationType) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _AnnotationID = Annotation.NextAnnotationID; + _DTS = _ItemAnnotationExtension.DefaultDTS; + _UserID = _ItemAnnotationExtension.DefaultUserID; + _MyAnnotationType = myAnnotationType; + ValidationRules.CheckRules(); + } + internal ItemAnnotation(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ItemAnnotation() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAnnotation.FetchDR", GetHashCode()); + try + { + _AnnotationID = dr.GetInt32("AnnotationID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _AnnotationType_Name = dr.GetString("AnnotationType_Name"); + _AnnotationType_Config = dr.GetString("AnnotationType_Config"); + _AnnotationType_DTS = dr.GetDateTime("AnnotationType_DTS"); + _AnnotationType_UserID = dr.GetString("AnnotationType_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAnnotation.FetchDR", ex); + throw new DbCslaException("ItemAnnotation.Fetch", ex); + } + MarkOld(); + } + 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); + 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); + MarkOld(); + } + 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"]; + Annotation.Remove(cn, _AnnotationID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension(); + [Serializable()] + partial class ItemAnnotationExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemAnnotationConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAnnotation) + { + // Return the ToString value + return ((ItemAnnotation)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs index 75e2392c..f3ee51e3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAudit.cs @@ -20,915 +20,902 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemAuditConverter))] - public partial class ItemAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshItemAudits = new List(); - private void AddToRefreshList(List refreshItemAudits) - { - if (IsDirty) - refreshItemAudits.Add(this); - } - private void ClearRefreshList() - { - _RefreshItemAudits = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshItemAudits); - } - private void ProcessRefreshList() - { - foreach (ItemAudit tmp in _RefreshItemAudits) - { - ItemAuditInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ItemAudit itemAudit) - { - if (!_CacheList.Contains(itemAudit)) _CacheList.Add(itemAudit); // In AddToCache - } - protected static void RemoveFromCache(ItemAudit itemAudit) - { - while (_CacheList.Contains(itemAudit)) _CacheList.Remove(itemAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ItemAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - ItemAudit tmp = _CacheList[0]; // Get the first ItemAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ItemAudit - } - } - protected static ItemAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemID", true); - if (_ItemID != value) - { - _ItemID = value; - PropertyHasChanged(); - } - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - return _PreviousID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PreviousID", true); - if (_PreviousID != value) - { - _PreviousID = value; - PropertyHasChanged(); - } - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base ItemAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ItemAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemAudit - protected override object GetIdValue() - { - return MyItemAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _ItemAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _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, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(PreviousID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(PreviousID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _ItemAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //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; } } - 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 ItemAudit() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ItemAudit() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listItemAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listItemAudit.Contains(this)) listItemAudit.Remove(this); // Remove the item from the list - if (listItemAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static ItemAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ItemAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemAudit.New", ex); - } - } - public static ItemAudit New(int itemID, int contentID, DateTime dts, string userID, int deleteStatus) - { - ItemAudit tmp = ItemAudit.New(); - tmp.ItemID = itemID; - tmp.ContentID = contentID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ItemAudit New(int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) - { - ItemAudit tmp = ItemAudit.New(); - tmp.ItemID = itemID; - tmp.PreviousID = previousID; - tmp.ContentID = contentID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static ItemAudit MakeItemAudit(int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) - { - ItemAudit tmp = ItemAudit.New(itemID, previousID, contentID, dts, userID, deleteStatus); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ItemAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemAudit.Get", ex); - } - } - public static ItemAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new ItemAudit(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemAudit.Delete", ex); - } - } - 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(); - ItemAudit itemAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(itemAudit);//Refresh the item in AllList - ProcessRefreshList(); - return itemAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// ItemAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAuditConverter))] + public partial class ItemAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshItemAudits = new List(); + private void AddToRefreshList(List refreshItemAudits) + { + if (IsDirty) + refreshItemAudits.Add(this); + } + private void ClearRefreshList() + { + _RefreshItemAudits = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshItemAudits); + } + private void ProcessRefreshList() + { + foreach (ItemAudit tmp in _RefreshItemAudits) + { + ItemAuditInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ItemAudit itemAudit) + { + if (!_CacheList.Contains(itemAudit)) _CacheList.Add(itemAudit); // In AddToCache + } + protected static void RemoveFromCache(ItemAudit itemAudit) + { + while (_CacheList.Contains(itemAudit)) _CacheList.Remove(itemAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ItemAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + ItemAudit tmp = _CacheList[0]; // Get the first ItemAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ItemAudit + } + } + protected static ItemAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemID != value) + { + _ItemID = value; + PropertyHasChanged(); + } + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PreviousID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PreviousID != value) + { + _PreviousID = value; + PropertyHasChanged(); + } + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ItemAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ItemAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemAudit + protected override object GetIdValue() + { + return MyItemAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _ItemAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _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, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(PreviousID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(PreviousID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _ItemAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //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; } } + 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 ItemAudit() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ItemAudit() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listItemAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listItemAudit.Contains(this)) listItemAudit.Remove(this); // Remove the item from the list + if (listItemAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static ItemAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ItemAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAudit.New", ex); + } + } + public static ItemAudit New(int itemID, int contentID, DateTime dts, string userID, int deleteStatus) + { + ItemAudit tmp = ItemAudit.New(); + tmp.ItemID = itemID; + tmp.ContentID = contentID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ItemAudit New(int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) + { + ItemAudit tmp = ItemAudit.New(); + tmp.ItemID = itemID; + tmp.PreviousID = previousID; + tmp.ContentID = contentID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static ItemAudit MakeItemAudit(int itemID, int? previousID, int contentID, DateTime dts, string userID, int deleteStatus) + { + ItemAudit tmp = ItemAudit.New(itemID, previousID, contentID, dts, userID, deleteStatus); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAudit.Get", ex); + } + } + public static ItemAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new ItemAudit(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAudit.Delete", ex); + } + } + 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(); + ItemAudit itemAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(itemAudit);//Refresh the item in AllList + ProcessRefreshList(); + return itemAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItemAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - 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); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - 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); - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Add", ex); - throw new DbCslaException("ItemAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateItemAudit"; - // Input All Fields - Except Calculated Columns - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteItemAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteItemAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Remove", ex); - throw new DbCslaException("ItemAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - ItemAuditExtension _ItemAuditExtension = new ItemAuditExtension(); - [Serializable()] - partial class ItemAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemAudit) - { - // Return the ToString value - return ((ItemAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItemAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + 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); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + 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); + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Add", ex); + throw new DbCslaException("ItemAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateItemAudit"; + // Input All Fields - Except Calculated Columns + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteItemAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteItemAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAudit.Remove", ex); + throw new DbCslaException("ItemAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + ItemAuditExtension _ItemAuditExtension = new ItemAuditExtension(); + [Serializable()] + partial class ItemAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAudit) + { + // Return the ToString value + return ((ItemAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfo.cs index 52fe68c7..06e15c5d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemAuditInfo.cs @@ -19,361 +19,354 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ItemAuditInfoEvent(object sender); - /// - /// ItemAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemAuditInfoConverter))] - public partial class ItemAuditInfo : ReadOnlyBase, IDisposable - { - public event ItemAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ItemAuditInfo itemAuditInfo) - { - if (!_CacheList.Contains(itemAuditInfo)) _CacheList.Add(itemAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(ItemAuditInfo itemAuditInfo) - { - while (_CacheList.Contains(itemAuditInfo)) _CacheList.Remove(itemAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ItemAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ItemAuditInfo tmp = _CacheList[0]; // Get the first ItemAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ItemAuditInfo - } - } - internal static void AddList(ItemAuditInfoList lst) - { - foreach (ItemAuditInfo item in lst) AddToCache(item); - } - protected static ItemAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - return _PreviousID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base ItemAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ItemAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemAuditInfo - protected override object GetIdValue() - { - return 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; } } - protected ItemAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ItemAuditInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listItemAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listItemAuditInfo.Contains(this)) listItemAuditInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(ItemAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ItemAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemAudit tmp) - { - _ItemID = tmp.ItemID; - _PreviousID = tmp.PreviousID; - _ContentID = tmp.ContentID; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _ItemAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ItemAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ItemAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.Constructor", ex); - throw new DbCslaException("ItemAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItemAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ItemAuditInfoExtension _ItemAuditInfoExtension = new ItemAuditInfoExtension(); - [Serializable()] - partial class ItemAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ItemAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ItemAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemAuditInfo) - { - // Return the ToString value - return ((ItemAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ItemAuditInfoEvent(object sender); + /// + /// ItemAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAuditInfoConverter))] + public partial class ItemAuditInfo : ReadOnlyBase, IDisposable + { + public event ItemAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ItemAuditInfo itemAuditInfo) + { + if (!_CacheList.Contains(itemAuditInfo)) _CacheList.Add(itemAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(ItemAuditInfo itemAuditInfo) + { + while (_CacheList.Contains(itemAuditInfo)) _CacheList.Remove(itemAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ItemAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ItemAuditInfo tmp = _CacheList[0]; // Get the first ItemAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ItemAuditInfo + } + } + internal static void AddList(ItemAuditInfoList lst) + { + foreach (ItemAuditInfo item in lst) AddToCache(item); + } + protected static ItemAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PreviousID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base ItemAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ItemAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemAuditInfo + protected override object GetIdValue() + { + return 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; } } + protected ItemAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ItemAuditInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listItemAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listItemAuditInfo.Contains(this)) listItemAuditInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(ItemAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ItemAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemAudit tmp) + { + _ItemID = tmp.ItemID; + _PreviousID = tmp.PreviousID; + _ContentID = tmp.ContentID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _ItemAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ItemAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.Constructor", ex); + throw new DbCslaException("ItemAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItemAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ItemAuditInfoExtension _ItemAuditInfoExtension = new ItemAuditInfoExtension(); + [Serializable()] + partial class ItemAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ItemAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ItemAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAuditInfo) + { + // Return the ToString value + return ((ItemAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersion.cs index ac53a772..50d8abd8 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemDocVersion.cs @@ -20,697 +20,667 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemDocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemDocVersionConverter))] - public partial class ItemDocVersion : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - _FolderID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - // CSLATODO: Check ItemDocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemDocVersion - protected override object GetIdValue() - { - return MyItemDocVersionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ItemDocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemDocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyFolderRequired(ItemDocVersion target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - 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); - } - public ItemDocVersion() - { - MarkAsChild(); - _VersionID = DocVersion.NextVersionID; - _VersionType = _ItemDocVersionExtension.DefaultVersionType; - _DTS = _ItemDocVersionExtension.DefaultDTS; - _UserID = _ItemDocVersionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemDocVersion(Folder myFolder, string name) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _VersionID = DocVersion.NextVersionID; - _VersionType = _ItemDocVersionExtension.DefaultVersionType; - _DTS = _ItemDocVersionExtension.DefaultDTS; - _UserID = _ItemDocVersionExtension.DefaultUserID; - _MyFolder = myFolder; - _Name = name; - ValidationRules.CheckRules(); - } - internal ItemDocVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ItemDocVersion() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemDocVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemDocVersion.FetchDR", ex); - throw new DbCslaException("ItemDocVersion.Fetch", ex); - } - MarkOld(); - } - 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 = 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); - MarkOld(); - } - 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension(); - [Serializable()] - partial class ItemDocVersionExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemDocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemDocVersion) - { - // Return the ToString value - return ((ItemDocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemDocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemDocVersionConverter))] + public partial class ItemDocVersion : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + _FolderID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + // CSLATODO: Check ItemDocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemDocVersion + protected override object GetIdValue() + { + return MyItemDocVersionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ItemDocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemDocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyFolderRequired(ItemDocVersion target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + 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); + } + public ItemDocVersion() + { + MarkAsChild(); + _VersionID = DocVersion.NextVersionID; + _VersionType = _ItemDocVersionExtension.DefaultVersionType; + _DTS = _ItemDocVersionExtension.DefaultDTS; + _UserID = _ItemDocVersionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemDocVersion(Folder myFolder, string name) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _VersionID = DocVersion.NextVersionID; + _VersionType = _ItemDocVersionExtension.DefaultVersionType; + _DTS = _ItemDocVersionExtension.DefaultDTS; + _UserID = _ItemDocVersionExtension.DefaultUserID; + _MyFolder = myFolder; + _Name = name; + ValidationRules.CheckRules(); + } + internal ItemDocVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ItemDocVersion() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemDocVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemDocVersion.FetchDR", ex); + throw new DbCslaException("ItemDocVersion.Fetch", ex); + } + MarkOld(); + } + 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 = 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); + MarkOld(); + } + 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension(); + [Serializable()] + partial class ItemDocVersionExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemDocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemDocVersion) + { + // Return the ToString value + return ((ItemDocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs index 79b7fc92..9dd0926b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfo.cs @@ -20,765 +20,747 @@ using System.Collections.Generic; using Volian.Base.Library; namespace VEPROMS.CSLA.Library { - public delegate void ItemInfoEvent(object sender); - /// - /// ItemInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemInfoConverter))] - public partial class ItemInfo : ReadOnlyBase, IDisposable - { - public event ItemInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ItemInfo itemInfo) - { - if (!_CacheList.Contains(itemInfo)) - _CacheList.Add(itemInfo); // In AddToCache - //try - //{ - // _CacheList.Add(itemInfo); // In AddToCache - //} - //catch (Exception ex) - //{ - // _MyLog.ErrorFormat("ItemInfo {0}.{1} already exists in the cache", itemInfo.ItemID, itemInfo.MyItemInfoUnique); - //} - } - protected static void RemoveFromCache(ItemInfo itemInfo) - { - while (_CacheList.Contains(itemInfo)) _CacheList.Remove(itemInfo); // In RemoveFromCache - } - protected static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - protected static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ItemInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ItemInfo tmp = _CacheList[0]; // Get the first ItemInfo - string pKey = tmp.ItemID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ItemInfo - } - } - internal static void AddList(ItemInfoList lst) - { - foreach (ItemInfo item in lst) AddToCache(item); - } - protected static ItemInfo GetCachedByPrimaryKey(int itemID) - { - ConvertListToDictionary(); - string key = itemID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Item _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ItemID; - [System.ComponentModel.DataObjectField(true, true)] - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; - return _PreviousID; - } - } - private ItemInfo _MyPrevious; - public ItemInfo MyPrevious - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPrevious", true); - if (_MyPrevious == null && _PreviousID != null) - { - if (this is ProcedureInfo) - _MyPrevious = ProcedureInfo.Get((int)_PreviousID); - else if (this is SectionInfo) - _MyPrevious = SectionInfo.Get((int)_PreviousID); - else if (this is StepInfo) - _MyPrevious = StepInfo.Get((int)_PreviousID); - else - _MyPrevious = ItemInfo.Get((int)_PreviousID); - } - return _MyPrevious; - } - set - { - _MyPrevious = value; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ItemAnnotationCount = 0; - /// - /// Count of ItemAnnotations for this Item - /// - public int ItemAnnotationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotationCount", true); - if (_ItemAnnotationCount < 0) - _ItemAnnotationCount = ItemAnnotations.Count; - return _ItemAnnotationCount; - } - } - private AnnotationInfoList _ItemAnnotations = null; - [TypeConverter(typeof(AnnotationInfoListConverter))] - public AnnotationInfoList ItemAnnotations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotations", true); - if (_ItemAnnotationCount < 0 || (_ItemAnnotationCount > 0 && _ItemAnnotations == null)) - _ItemAnnotations = AnnotationInfoList.GetByItemID(_ItemID); - if (_ItemAnnotationCount < 0) - _ItemAnnotationCount = _ItemAnnotations.Count; - return _ItemAnnotations; - } - } - public void RefreshItemAnnotations() - { - _ItemAnnotationCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemAnnotationCount = -1; // This will cause the data to be requeried - } - private int _ItemDocVersionCount = 0; - /// - /// Count of ItemDocVersions for this Item - /// - public int ItemDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersionCount", true); - if (_ItemDocVersionCount < 0) - _ItemDocVersionCount = ItemDocVersions.Count; - return _ItemDocVersionCount; - } - } - private DocVersionInfoList _ItemDocVersions = null; - [TypeConverter(typeof(DocVersionInfoListConverter))] - public DocVersionInfoList ItemDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersions", true); - if (_ItemDocVersionCount < 0 || (_ItemDocVersionCount > 0 && _ItemDocVersions == null)) - _ItemDocVersions = DocVersionInfoList.GetByItemID(_ItemID); - if (_ItemDocVersionCount < 0) - _ItemDocVersionCount = _ItemDocVersions.Count; - return _ItemDocVersions; - } - } - public void RefreshItemDocVersions() - { - _ItemDocVersionCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemDocVersionCount = -1; // This will cause the data to be requeried - } - // B2016-130: GetNext was added so that NextItems was not used for finding the next item in a list of iteminfos using 'nextitems'. - // When using 'nextitems' internal list data structures for items were not maintained consistently with the database items during - // some occurrences of copy/paste/delete. - [Serializable()] - private class PreviousIDCriteria - { - public PreviousIDCriteria(int? previousID) - { - _PreviousID = previousID; - } - private int? _PreviousID; - public int? PreviousID - { - get { return _PreviousID; } - set { _PreviousID = value; } - } - } - public ItemInfo GetNext() - { - try - { - ItemInfo tmp = DataPortal.Fetch(new PreviousIDCriteria(ItemID)); - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ItemInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemInfo.GetNext", ex); - } - } - private void DataPortal_Fetch(PreviousIDCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_FetchPreviousID", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getNextItems"; - cm.Parameters.AddWithValue("@PreviousID", criteria.PreviousID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_FetchPreviousID", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); - } - } - private int _NextItemCount = 0; - /// - /// Count of NextItems for this Item - /// - public int NextItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItemCount", true); - if (_NextItemCount < 0) - _NextItemCount = NextItems.Count; - return _NextItemCount; - } - } - private ItemInfoList _NextItems = null; - [TypeConverter(typeof(ItemInfoListConverter))] - public ItemInfoList NextItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItems", true); - if (_NextItemCount < 0 || (_NextItemCount > 0 && _NextItems == null)) - _NextItems = ItemInfoList.GetNext(_ItemID); - if (_NextItemCount < 0) - _NextItemCount = _NextItems.Count; - return _NextItems; - } - } - public void RefreshNextItems() - { - _NextItemCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._NextItemCount = -1; // This will cause the data to be requeried - } - private int _ItemPartCount = 0; - /// - /// Count of ItemParts for this Item - /// - public int ItemPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemPartCount", true); - if (_ItemPartCount < 0) - _ItemPartCount = ItemParts.Count; - return _ItemPartCount; - } - } - private PartInfoList _ItemParts = null; - [TypeConverter(typeof(PartInfoListConverter))] - public PartInfoList ItemParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - //int profileDepth = ProfileTimer.Push(">>>> ItemParts"); - CanReadProperty("ItemParts", true); - if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) - _ItemParts = PartInfoList.GetByItemID(_ItemID); - if (_ItemPartCount < 0) - _ItemPartCount = _ItemParts.Count; - //ProfileTimer.Pop(profileDepth); - return _ItemParts; - } - } - public void RefreshItemParts() - { - _ItemPartCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemPartCount = -1; // This will cause the data to be requeried - } - private int _ItemTransition_RangeIDCount = 0; - /// - /// Count of ItemTransitions_RangeID for this Item - /// - public int ItemTransition_RangeIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_RangeIDCount", true); - if (_ItemTransition_RangeIDCount < 0) - _ItemTransition_RangeIDCount = ItemTransitions_RangeID.Count; - return _ItemTransition_RangeIDCount; - } - } - private TransitionInfoList _ItemTransitions_RangeID = null; - [TypeConverter(typeof(TransitionInfoListConverter))] - public TransitionInfoList ItemTransitions_RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_RangeID", true); - if (_ItemTransition_RangeIDCount < 0 || (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null)) - _ItemTransitions_RangeID = TransitionInfoList.GetByRangeID(_ItemID); - if (_ItemTransition_RangeIDCount < 0) - _ItemTransition_RangeIDCount = _ItemTransitions_RangeID.Count; - return _ItemTransitions_RangeID; - } - } - public void RefreshItemTransitions_RangeID() - { - _ItemTransition_RangeIDCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried - } - private int _ItemTransition_ToIDCount = 0; - /// - /// Count of ItemTransitions_ToID for this Item - /// - public int ItemTransition_ToIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_ToIDCount", true); - if (_ItemTransition_ToIDCount < 0) - _ItemTransition_ToIDCount = ItemTransitions_ToID.Count; - return _ItemTransition_ToIDCount; - } - } - private TransitionInfoList _ItemTransitions_ToID = null; - [TypeConverter(typeof(TransitionInfoListConverter))] - public TransitionInfoList ItemTransitions_ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_ToID", true); - if (_ItemTransition_ToIDCount < 0 || (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null)) - _ItemTransitions_ToID = TransitionInfoList.GetByToID(_ItemID); - if (_ItemTransition_ToIDCount < 0) - _ItemTransition_ToIDCount = _ItemTransitions_ToID.Count; - return _ItemTransitions_ToID; - } - } - public void RefreshItemTransitions_ToID() - { - _ItemTransition_ToIDCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base ItemInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ItemInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemInfo - protected override object GetIdValue() - { - return MyItemInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ItemInfoUnique = 0; - private static int ItemInfoUnique - { - get - { - int ui = ++_ItemInfoUnique; - //Useful for debug to identify where item is being created: - //if (ui == 73) Console.WriteLine("here"); - return ui; - } - } - private int _MyItemInfoUnique = ItemInfoUnique; - public int MyItemInfoUnique // Absolutely Unique ID - Info - { get { return _MyItemInfoUnique; } } - protected ItemInfo() - {/* require use of factory methods */ - //AddToCache(this); - } - 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; } } - ~ItemInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) return; - List listItemInfo = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items - while (listItemInfo.Contains(this)) listItemInfo.Remove(this); // Remove the item from the list - if (listItemInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list - if (_MyContent != null) - _MyContent = null; - if (_MyPrevious != null) - _MyPrevious = null; - //if (_ActiveFormat != null) - // _ActiveFormat = null; - //if (_ActiveParent != null) - // _ActiveParent = null; - //if (_ActiveSection != null) - // _ActiveSection = null; - //if (_MyDocVersion != null) - // _MyDocVersion = null; - //if (_ParentNoteOrCaution != null) - // _ParentNoteOrCaution = null; - } - public virtual Item Get() - { - return _Editable = Item.Get(_ItemID); - } - public static void Refresh(Item tmp) - { - string key = tmp.ItemID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Item tmp) - { - if (_PreviousID != tmp.PreviousID) - { - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value - _PreviousID = tmp.PreviousID; // Update the value - } - _MyPrevious = null; // Reset list so that the next line gets a new list - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value - //if (_ContentID != tmp.ContentID) - //{ - if (MyContent != null) MyContent.RefreshContentItems(); // 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.RefreshContentItems(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ItemInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ContentItem tmp) - { - string key = tmp.ItemID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentItem tmp) - { - if (_PreviousID != tmp.PreviousID) - { - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value - _PreviousID = tmp.PreviousID; // Update the value - } - _MyPrevious = null; // Reset list so that the next line gets a new list - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ItemInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ItemInfo Get(int itemID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Item"); - try - { - ItemInfo tmp = GetCachedByPrimaryKey(itemID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(itemID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ItemInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemInfo.Get", ex); - } - } - // B2016-130: Just get an item from the database, but don't add it to the cache because it gets - // freed (only use this in a 'using' statement). - public static ItemInfo GetNonCached(int itemID) - { - try - { - ItemInfo tmp = DataPortal.Fetch(new PKCriteria(itemID)); - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ItemInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemInfo.GetNonCached", ex); - } - } - #endregion - #region Data Access Portal - internal ItemInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.Constructor", ex); - throw new DbCslaException("ItemInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ItemID; - public int ItemID - { get { return _ItemID; } } - public PKCriteria(int itemID) - { - _ItemID = itemID; - } - } - protected void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode()); - try - { - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); - _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); - _NextItemCount = dr.GetInt32("NextCount"); - _ItemPartCount = dr.GetInt32("PartCount"); - _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); - _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItem"; - cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ItemInfoExtension _ItemInfoExtension = new ItemInfoExtension(); - [Serializable()] - partial class ItemInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ItemInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ItemInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemInfo) - { - // Return the ToString value - return ((ItemInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ItemInfoEvent(object sender); + /// + /// ItemInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemInfoConverter))] + public partial class ItemInfo : ReadOnlyBase, IDisposable + { + public event ItemInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ItemInfo itemInfo) + { + if (!_CacheList.Contains(itemInfo)) + _CacheList.Add(itemInfo); // In AddToCache + //try + //{ + // _CacheList.Add(itemInfo); // In AddToCache + //} + //catch (Exception ex) + //{ + // _MyLog.ErrorFormat("ItemInfo {0}.{1} already exists in the cache", itemInfo.ItemID, itemInfo.MyItemInfoUnique); + //} + } + protected static void RemoveFromCache(ItemInfo itemInfo) + { + while (_CacheList.Contains(itemInfo)) _CacheList.Remove(itemInfo); // In RemoveFromCache + } + protected static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + protected static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ItemInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ItemInfo tmp = _CacheList[0]; // Get the first ItemInfo + string pKey = tmp.ItemID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ItemInfo + } + } + internal static void AddList(ItemInfoList lst) + { + foreach (ItemInfo item in lst) AddToCache(item); + } + protected static ItemInfo GetCachedByPrimaryKey(int itemID) + { + ConvertListToDictionary(); + string key = itemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Item _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ItemID; + [System.ComponentModel.DataObjectField(true, true)] + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; + return _PreviousID; + } + } + private ItemInfo _MyPrevious; + public ItemInfo MyPrevious + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious == null && _PreviousID != null) + { + if (this is ProcedureInfo) + _MyPrevious = ProcedureInfo.Get((int)_PreviousID); + else if (this is SectionInfo) + _MyPrevious = SectionInfo.Get((int)_PreviousID); + else if (this is StepInfo) + _MyPrevious = StepInfo.Get((int)_PreviousID); + else + _MyPrevious = ItemInfo.Get((int)_PreviousID); + } + return _MyPrevious; + } + set + { + _MyPrevious = value; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ItemAnnotationCount = 0; + /// + /// Count of ItemAnnotations for this Item + /// + public int ItemAnnotationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemAnnotationCount < 0) + _ItemAnnotationCount = ItemAnnotations.Count; + return _ItemAnnotationCount; + } + } + private AnnotationInfoList _ItemAnnotations = null; + [TypeConverter(typeof(AnnotationInfoListConverter))] + public AnnotationInfoList ItemAnnotations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemAnnotationCount < 0 || (_ItemAnnotationCount > 0 && _ItemAnnotations == null)) + _ItemAnnotations = AnnotationInfoList.GetByItemID(_ItemID); + if (_ItemAnnotationCount < 0) + _ItemAnnotationCount = _ItemAnnotations.Count; + return _ItemAnnotations; + } + } + public void RefreshItemAnnotations() + { + _ItemAnnotationCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemAnnotationCount = -1; // This will cause the data to be requeried + } + private int _ItemDocVersionCount = 0; + /// + /// Count of ItemDocVersions for this Item + /// + public int ItemDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemDocVersionCount < 0) + _ItemDocVersionCount = ItemDocVersions.Count; + return _ItemDocVersionCount; + } + } + private DocVersionInfoList _ItemDocVersions = null; + [TypeConverter(typeof(DocVersionInfoListConverter))] + public DocVersionInfoList ItemDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemDocVersionCount < 0 || (_ItemDocVersionCount > 0 && _ItemDocVersions == null)) + _ItemDocVersions = DocVersionInfoList.GetByItemID(_ItemID); + if (_ItemDocVersionCount < 0) + _ItemDocVersionCount = _ItemDocVersions.Count; + return _ItemDocVersions; + } + } + public void RefreshItemDocVersions() + { + _ItemDocVersionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemDocVersionCount = -1; // This will cause the data to be requeried + } + // B2016-130: GetNext was added so that NextItems was not used for finding the next item in a list of iteminfos using 'nextitems'. + // When using 'nextitems' internal list data structures for items were not maintained consistently with the database items during + // some occurrences of copy/paste/delete. + [Serializable()] + private class PreviousIDCriteria + { + public PreviousIDCriteria(int? previousID) + { + _PreviousID = previousID; + } + private int? _PreviousID; + public int? PreviousID + { + get { return _PreviousID; } + set { _PreviousID = value; } + } + } + public ItemInfo GetNext() + { + try + { + ItemInfo tmp = DataPortal.Fetch(new PreviousIDCriteria(ItemID)); + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfo.GetNext", ex); + } + } + private void DataPortal_Fetch(PreviousIDCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_FetchPreviousID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getNextItems"; + cm.Parameters.AddWithValue("@PreviousID", criteria.PreviousID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_FetchPreviousID", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); + } + } + private int _NextItemCount = 0; + /// + /// Count of NextItems for this Item + /// + public int NextItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_NextItemCount < 0) + _NextItemCount = NextItems.Count; + return _NextItemCount; + } + } + private ItemInfoList _NextItems = null; + [TypeConverter(typeof(ItemInfoListConverter))] + public ItemInfoList NextItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_NextItemCount < 0 || (_NextItemCount > 0 && _NextItems == null)) + _NextItems = ItemInfoList.GetNext(_ItemID); + if (_NextItemCount < 0) + _NextItemCount = _NextItems.Count; + return _NextItems; + } + } + public void RefreshNextItems() + { + _NextItemCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._NextItemCount = -1; // This will cause the data to be requeried + } + private int _ItemPartCount = 0; + /// + /// Count of ItemParts for this Item + /// + public int ItemPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemPartCount < 0) + _ItemPartCount = ItemParts.Count; + return _ItemPartCount; + } + } + private PartInfoList _ItemParts = null; + [TypeConverter(typeof(PartInfoListConverter))] + public PartInfoList ItemParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + //int profileDepth = ProfileTimer.Push(">>>> ItemParts"); + if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) + _ItemParts = PartInfoList.GetByItemID(_ItemID); + if (_ItemPartCount < 0) + _ItemPartCount = _ItemParts.Count; + //ProfileTimer.Pop(profileDepth); + return _ItemParts; + } + } + public void RefreshItemParts() + { + _ItemPartCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemPartCount = -1; // This will cause the data to be requeried + } + private int _ItemTransition_RangeIDCount = 0; + /// + /// Count of ItemTransitions_RangeID for this Item + /// + public int ItemTransition_RangeIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_RangeIDCount < 0) + _ItemTransition_RangeIDCount = ItemTransitions_RangeID.Count; + return _ItemTransition_RangeIDCount; + } + } + private TransitionInfoList _ItemTransitions_RangeID = null; + [TypeConverter(typeof(TransitionInfoListConverter))] + public TransitionInfoList ItemTransitions_RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_RangeIDCount < 0 || (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null)) + _ItemTransitions_RangeID = TransitionInfoList.GetByRangeID(_ItemID); + if (_ItemTransition_RangeIDCount < 0) + _ItemTransition_RangeIDCount = _ItemTransitions_RangeID.Count; + return _ItemTransitions_RangeID; + } + } + public void RefreshItemTransitions_RangeID() + { + _ItemTransition_RangeIDCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried + } + private int _ItemTransition_ToIDCount = 0; + /// + /// Count of ItemTransitions_ToID for this Item + /// + public int ItemTransition_ToIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_ToIDCount < 0) + _ItemTransition_ToIDCount = ItemTransitions_ToID.Count; + return _ItemTransition_ToIDCount; + } + } + private TransitionInfoList _ItemTransitions_ToID = null; + [TypeConverter(typeof(TransitionInfoListConverter))] + public TransitionInfoList ItemTransitions_ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_ToIDCount < 0 || (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null)) + _ItemTransitions_ToID = TransitionInfoList.GetByToID(_ItemID); + if (_ItemTransition_ToIDCount < 0) + _ItemTransition_ToIDCount = _ItemTransitions_ToID.Count; + return _ItemTransitions_ToID; + } + } + public void RefreshItemTransitions_ToID() + { + _ItemTransition_ToIDCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base ItemInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ItemInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemInfo + protected override object GetIdValue() + { + return MyItemInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ItemInfoUnique = 0; + private static int ItemInfoUnique + { + get + { + int ui = ++_ItemInfoUnique; + //Useful for debug to identify where item is being created: + //if (ui == 73) Console.WriteLine("here"); + return ui; + } + } + private int _MyItemInfoUnique = ItemInfoUnique; + public int MyItemInfoUnique // Absolutely Unique ID - Info + { get { return _MyItemInfoUnique; } } + protected ItemInfo() + {/* require use of factory methods */ + //AddToCache(this); + } + 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; } } + ~ItemInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + _ItemParts?.Dispose(); + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) return; + List listItemInfo = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items + while (listItemInfo.Contains(this)) listItemInfo.Remove(this); // Remove the item from the list + if (listItemInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list + if (_MyContent != null) + _MyContent = null; + if (_MyPrevious != null) + _MyPrevious = null; + //if (_ActiveFormat != null) + // _ActiveFormat = null; + //if (_ActiveParent != null) + // _ActiveParent = null; + //if (_ActiveSection != null) + // _ActiveSection = null; + //if (_MyDocVersion != null) + // _MyDocVersion = null; + //if (_ParentNoteOrCaution != null) + // _ParentNoteOrCaution = null; + } + public virtual Item Get() + { + return _Editable = Item.Get(_ItemID); + } + public static void Refresh(Item tmp) + { + string key = tmp.ItemID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Item tmp) + { + if (_PreviousID != tmp.PreviousID) + { + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value + _PreviousID = tmp.PreviousID; // Update the value + } + _MyPrevious = null; // Reset list so that the next line gets a new list + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value + //if (_ContentID != tmp.ContentID) + //{ + if (MyContent != null) MyContent.RefreshContentItems(); // 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.RefreshContentItems(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ItemInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ContentItem tmp) + { + string key = tmp.ItemID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentItem tmp) + { + if (_PreviousID != tmp.PreviousID) + { + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value + _PreviousID = tmp.PreviousID; // Update the value + } + _MyPrevious = null; // Reset list so that the next line gets a new list + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ItemInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ItemInfo Get(int itemID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Item"); + try + { + ItemInfo tmp = GetCachedByPrimaryKey(itemID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfo.Get", ex); + } + } + // B2016-130: Just get an item from the database, but don't add it to the cache because it gets + // freed (only use this in a 'using' statement). + public static ItemInfo GetNonCached(int itemID) + { + try + { + ItemInfo tmp = DataPortal.Fetch(new PKCriteria(itemID)); + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfo.GetNonCached", ex); + } + } + #endregion + #region Data Access Portal + internal ItemInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.Constructor", ex); + throw new DbCslaException("ItemInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + public PKCriteria(int itemID) + { + _ItemID = itemID; + } + } + protected void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode()); + try + { + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); + _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); + _NextItemCount = dr.GetInt32("NextCount"); + _ItemPartCount = dr.GetInt32("PartCount"); + _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); + _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItem"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ItemInfoExtension _ItemInfoExtension = new ItemInfoExtension(); + [Serializable()] + partial class ItemInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ItemInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ItemInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemInfo) + { + // Return the ToString value + return ((ItemInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfoList.cs index d3c37c32..410bdce1 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemInfoList.cs @@ -19,373 +19,373 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - /// - /// ItemInfoList Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemInfoListConverter))] - public partial class ItemInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Business Methods - internal new IList Items - { get { return base.Items; } } - public void AddEvents() - { - foreach (ItemInfo tmp in this) - { - tmp.Changed += new ItemInfoEvent(tmp_Changed); - tmp.Deleted += new ItemInfoEvent(tmp_Deleted); - } - } - private bool _RefreshingList = false; - public bool RefreshingList - { - get { return _RefreshingList; } - set { _RefreshingList = value; } - } - void tmp_Deleted(object sender) - { - ItemInfo ii = sender as ItemInfo; - if (ii != null) - { - RefreshingList = true; - IsReadOnly = false; - Remove(ii); - IsReadOnly = true; - this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, 0)); - RefreshingList = false; - } - } - // sender can be either the current item changed, or the current item with one added before it (when an item is inserted) - void tmp_Changed(object sender) - { - for (int i = 0; i < Count; i++) - { - if (base[i] == sender) - { - // Added insert to fix when item is replaced and a 'delete' is done, the item needs inserted. Note - // that when text is modified, i.e. 'Changed', this code is not executed. Fixed B2016-130. - RefreshingList = true; - IsReadOnly = false; - // the following checks to see if the previous is this one, and if so, it is not an insert it is a change - // On an insert, inserting from 'sender', MyPrevious is set as the new item. - if (SourceOfList != "Search" && (sender as ItemInfo).MyPrevious != null && i > 0 && base[i - 1].ItemID != (sender as ItemInfo).MyPrevious.ItemID) - Items.Insert(i, (sender as ItemInfo).MyPrevious); - IsReadOnly = true; - this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); - RefreshingList = false; - break; - } - } - } - private string _SourceOfList; - public string SourceOfList - { - get { return _SourceOfList; } - set { _SourceOfList = value; } - } - //private void ShowList(string txt) - //{ - // Console.WriteLine("\r\n{0} - {1} - {2}: i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText", txt, Count, SourceOfList); - // for (int i = 0; i < Count; i++) - // { - // Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText, base[i].MyItemInfoUnique, base[i].Disposed); - // } - //} - 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; } } - ~ItemInfoList() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _Disposed = true; - _CountDisposed++; - foreach (ItemInfo tmp in this) - { - tmp.Changed -= new ItemInfoEvent(tmp_Changed); - tmp.Deleted -= new ItemInfoEvent(tmp_Deleted); - } - } - #endregion - #region Factory Methods - public static ItemInfoList _ItemInfoList = null; - /// - /// Return a list of all ItemInfo. - /// - public static ItemInfoList Get() - { - try - { - if (_ItemInfoList != null) - return _ItemInfoList; - ItemInfoList tmp = DataPortal.Fetch(); - ItemInfo.AddList(tmp); - tmp.AddEvents(); - _ItemInfoList = tmp; - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemInfoList.Get", ex); - } - } - /// - /// Reset the list of all ItemInfo. - /// - public static void Reset() - { - _ItemInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static ItemInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on ItemInfoList.Get", ex); - // } - //} - public static ItemInfoList GetNext(int? previousID) - { - try - { - ItemInfoList tmp = DataPortal.Fetch(new PreviousIDCriteria(previousID)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemInfoList.GetNext", ex); - } - } - public static ItemInfoList GetByContentID(int contentID) - { - try - { - ItemInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); - ItemInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemInfoList.GetByContentID", ex); - } - } - private ItemInfoList() - { /* require use of factory methods */ } - #endregion - #region Data Access Portal - private void DataPortal_Fetch() - { - this.RaiseListChangedEvents = false; - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItems"; - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - IsReadOnly = false; - while (dr.Read()) this.Add(new ItemInfo(dr)); - IsReadOnly = true; - } - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_Fetch", ex); - throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); - } - this.RaiseListChangedEvents = true; - } - [Serializable()] - private class PreviousIDCriteria - { - public PreviousIDCriteria(int? previousID) - { - _PreviousID = previousID; - } - private int? _PreviousID; - public int? PreviousID - { - get { return _PreviousID; } - set { _PreviousID = value; } - } - } - private void DataPortal_Fetch(PreviousIDCriteria criteria) - { - this.RaiseListChangedEvents = false; - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchPreviousID", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getNextItems"; - cm.Parameters.AddWithValue("@PreviousID", criteria.PreviousID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - IsReadOnly = false; - while (dr.Read()) this.Add(new ItemInfo(dr)); - IsReadOnly = true; - } - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchPreviousID", ex); - throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); - } - this.RaiseListChangedEvents = true; - } - [Serializable()] - private class ContentIDCriteria - { - public ContentIDCriteria(int contentID) - { - _ContentID = contentID; - } - private int _ContentID; - public int ContentID - { - get { return _ContentID; } - set { _ContentID = value; } - } - } - private void DataPortal_Fetch(ContentIDCriteria criteria) - { - this.RaiseListChangedEvents = false; - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchContentID", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItemsByContentID"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - IsReadOnly = false; - while (dr.Read()) this.Add(new ItemInfo(dr)); - IsReadOnly = true; - } - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchContentID", ex); - throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); - } - 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; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - 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++) - { - // Create a property descriptor for the item and add to the property descriptor collection - ItemInfoListPropertyDescriptor pd = new ItemInfoListPropertyDescriptor(this, i); - pds.Add(pd); - } - // return the property descriptor collection - return pds; - } - #endregion - } // Class - #region Property Descriptor - /// - /// Summary description for CollectionPropertyDescriptor. - /// - public partial class ItemInfoListPropertyDescriptor : vlnListPropertyDescriptor - { - private ItemInfo Item { get { return (ItemInfo)_Item; } } - public ItemInfoListPropertyDescriptor(ItemInfoList collection, int index) : base(collection, index) { ;} - } - #endregion - #region Converter - internal class ItemInfoListConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemInfoList) - { - // Return department and department role separated by comma. - return ((ItemInfoList)value).Items.Count.ToString() + " Items"; - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemInfoListConverter))] + public partial class ItemInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + internal new IList Items + { get { return base.Items; } } + public void AddEvents() + { + foreach (ItemInfo tmp in this) + { + tmp.Changed += new ItemInfoEvent(tmp_Changed); + tmp.Deleted += new ItemInfoEvent(tmp_Deleted); + } + } + private bool _RefreshingList = false; + public bool RefreshingList + { + get { return _RefreshingList; } + set { _RefreshingList = value; } + } + void tmp_Deleted(object sender) + { + ItemInfo ii = sender as ItemInfo; + if (ii != null) + { + RefreshingList = true; + IsReadOnly = false; + Remove(ii); + IsReadOnly = true; + this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, 0)); + RefreshingList = false; + } + } + // sender can be either the current item changed, or the current item with one added before it (when an item is inserted) + void tmp_Changed(object sender) + { + for (int i = 0; i < Count; i++) + { + if (base[i] == sender) + { + // Added insert to fix when item is replaced and a 'delete' is done, the item needs inserted. Note + // that when text is modified, i.e. 'Changed', this code is not executed. Fixed B2016-130. + RefreshingList = true; + IsReadOnly = false; + // the following checks to see if the previous is this one, and if so, it is not an insert it is a change + // On an insert, inserting from 'sender', MyPrevious is set as the new item. + if (SourceOfList != "Search" && (sender as ItemInfo).MyPrevious != null && i > 0 && base[i - 1].ItemID != (sender as ItemInfo).MyPrevious.ItemID) + Items.Insert(i, (sender as ItemInfo).MyPrevious); + IsReadOnly = true; + this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, i)); + RefreshingList = false; + break; + } + } + } + private string _SourceOfList; + public string SourceOfList + { + get { return _SourceOfList; } + set { _SourceOfList = value; } + } + //private void ShowList(string txt) + //{ + // Console.WriteLine("\r\n{0} - {1} - {2}: i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText", txt, Count, SourceOfList); + // for (int i = 0; i < Count; i++) + // { + // Console.WriteLine("{0}, {1}, {2}, {3}, {4}, {5}", i, base[i].Ordinal, base[i].ItemID, base[i].DisplayText, base[i].MyItemInfoUnique, base[i].Disposed); + // } + //} + 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; } } + ~ItemInfoList() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _Disposed = true; + _CountDisposed++; + foreach (ItemInfo tmp in this) + { + tmp.Changed -= tmp_Changed; + tmp.Deleted -= tmp_Deleted; + } + } + #endregion + #region Factory Methods + public static ItemInfoList _ItemInfoList = null; + /// + /// Return a list of all ItemInfo. + /// + public static ItemInfoList Get() + { + try + { + if (_ItemInfoList != null) + return _ItemInfoList; + ItemInfoList tmp = DataPortal.Fetch(); + ItemInfo.AddList(tmp); + tmp.AddEvents(); + _ItemInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.Get", ex); + } + } + /// + /// Reset the list of all ItemInfo. + /// + public static void Reset() + { + _ItemInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static ItemInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on ItemInfoList.Get", ex); + // } + //} + public static ItemInfoList GetNext(int? previousID) + { + try + { + ItemInfoList tmp = DataPortal.Fetch(new PreviousIDCriteria(previousID)); + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.GetNext", ex); + } + } + public static ItemInfoList GetByContentID(int contentID) + { + try + { + ItemInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + ItemInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.GetByContentID", ex); + } + } + private ItemInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItems"; + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ItemInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class PreviousIDCriteria + { + public PreviousIDCriteria(int? previousID) + { + _PreviousID = previousID; + } + private int? _PreviousID; + public int? PreviousID + { + get { return _PreviousID; } + set { _PreviousID = value; } + } + } + private void DataPortal_Fetch(PreviousIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchPreviousID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getNextItems"; + cm.Parameters.AddWithValue("@PreviousID", criteria.PreviousID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ItemInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchPreviousID", ex); + throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ContentIDCriteria + { + public ContentIDCriteria(int contentID) + { + _ContentID = contentID; + } + private int _ContentID; + public int ContentID + { + get { return _ContentID; } + set { _ContentID = value; } + } + } + private void DataPortal_Fetch(ContentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfoList.DataPortal_FetchContentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItemsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new ItemInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfoList.DataPortal_FetchContentID", ex); + throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + 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; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + 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++) + { + // Create a property descriptor for the item and add to the property descriptor collection + ItemInfoListPropertyDescriptor pd = new ItemInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class ItemInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private ItemInfo Item { get { return (ItemInfo)_Item; } } + public ItemInfoListPropertyDescriptor(ItemInfoList collection, int index) : base(collection, index) {; } + } + #endregion + #region Converter + internal class ItemInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemInfoList) + { + // Return department and department role separated by comma. + return ((ItemInfoList)value).Items.Count.ToString() + " Items"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemPart.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemPart.cs index d7b636a7..b8c4549e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemPart.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemPart.cs @@ -20,472 +20,458 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemPart Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemPartConverter))] - public partial class ItemPart : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // CSLATODO: Check ItemPart.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemPart - protected override object GetIdValue() - { - return MyItemPartUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ItemPart.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemPart - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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, ""); - //AuthorizationRules.AllowRead(FromType, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ItemPartUnique = 0; - private static int ItemPartUnique - { get { return ++_ItemPartUnique; } } - private int _MyItemPartUnique = ItemPartUnique; - public int MyItemPartUnique // Absolutely Unique ID - Editable FK - { get { return _MyItemPartUnique; } } - internal static ItemPart New(Content myContent, int fromType) - { - return new ItemPart(myContent, fromType); - } - internal static ItemPart Get(SafeDataReader dr) - { - return new ItemPart(dr); - } - public ItemPart() - { - MarkAsChild(); + /// + /// ItemPart Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemPartConverter))] + public partial class ItemPart : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // CSLATODO: Check ItemPart.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemPart + protected override object GetIdValue() + { + return MyItemPartUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ItemPart.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemPart + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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, ""); + //AuthorizationRules.AllowRead(FromType, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ItemPartUnique = 0; + private static int ItemPartUnique + { get { return ++_ItemPartUnique; } } + private int _MyItemPartUnique = ItemPartUnique; + public int MyItemPartUnique // Absolutely Unique ID - Editable FK + { get { return _MyItemPartUnique; } } + internal static ItemPart New(Content myContent, int fromType) + { + return new ItemPart(myContent, fromType); + } + internal static ItemPart Get(SafeDataReader dr) + { + return new ItemPart(dr); + } + public ItemPart() + { + MarkAsChild(); - _DTS = _ItemPartExtension.DefaultDTS; - _UserID = _ItemPartExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemPart(Content myContent, int fromType) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _DTS = _ItemPartExtension.DefaultDTS; - _UserID = _ItemPartExtension.DefaultUserID; - _MyContent = myContent; - _FromType = fromType; - ValidationRules.CheckRules(); - } - internal ItemPart(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ItemPart() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemPart.FetchDR", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemPart.FetchDR", ex); - throw new DbCslaException("ItemPart.Fetch", ex); - } - MarkOld(); - } - 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 = Part.Add(cn, _MyContent, _FromType, myItem, _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 = Part.Update(cn, _ContentID, _FromType, myItem.ItemID, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - 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"]; - Part.Remove(cn, _ContentID, _FromType); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemPartExtension _ItemPartExtension = new ItemPartExtension(); - [Serializable()] - partial class ItemPartExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemPartConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemPart) - { - // Return the ToString value - return ((ItemPart)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _ItemPartExtension.DefaultDTS; + _UserID = _ItemPartExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemPart(Content myContent, int fromType) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _DTS = _ItemPartExtension.DefaultDTS; + _UserID = _ItemPartExtension.DefaultUserID; + _MyContent = myContent; + _FromType = fromType; + ValidationRules.CheckRules(); + } + internal ItemPart(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ItemPart() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemPart.FetchDR", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemPart.FetchDR", ex); + throw new DbCslaException("ItemPart.Fetch", ex); + } + MarkOld(); + } + 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 = Part.Add(cn, _MyContent, _FromType, myItem, _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 = Part.Update(cn, _ContentID, _FromType, myItem.ItemID, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + 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"]; + Part.Remove(cn, _ContentID, _FromType); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemPartExtension _ItemPartExtension = new ItemPartExtension(); + [Serializable()] + partial class ItemPartExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemPartConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemPart) + { + // Return the ToString value + return ((ItemPart)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_RangeID.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_RangeID.cs index 046fc97d..f40f2721 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_RangeID.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_RangeID.cs @@ -20,645 +20,620 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemTransition_RangeID Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemTransition_RangeIDConverter))] - public partial class ItemTransition_RangeID : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - _FromID = value.ContentID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private Item _MyItemToID; - public Item MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); - return _MyItemToID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemToID", true); - if (_MyItemToID != value) - { - _MyItemToID = value; - _ToID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _IsRange; - /// - /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling - /// - public int IsRange - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("IsRange", true); - return _IsRange; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("IsRange", true); - if (_IsRange != value) - { - _IsRange = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // CSLATODO: Check ItemTransition_RangeID.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemTransition_RangeID - protected override object GetIdValue() - { - return MyItemTransition_RangeIDUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ItemTransition_RangeID.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemTransition_RangeID - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyContentRequired(ItemTransition_RangeID target, Csla.Validation.RuleArgs e) - { - if (target._FromID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(TransitionID, ""); - //AuthorizationRules.AllowRead(FromID, ""); - //AuthorizationRules.AllowWrite(FromID, ""); - //AuthorizationRules.AllowRead(ToID, ""); - //AuthorizationRules.AllowWrite(ToID, ""); - //AuthorizationRules.AllowRead(IsRange, ""); - //AuthorizationRules.AllowWrite(IsRange, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ItemTransition_RangeIDUnique = 0; - private static int ItemTransition_RangeIDUnique - { get { return ++_ItemTransition_RangeIDUnique; } } - private int _MyItemTransition_RangeIDUnique = ItemTransition_RangeIDUnique; - public int MyItemTransition_RangeIDUnique // Absolutely Unique ID - Editable FK - { get { return _MyItemTransition_RangeIDUnique; } } - internal static ItemTransition_RangeID New(Content myContent, Item myItemToID) - { - return new ItemTransition_RangeID(myContent, myItemToID); - } - internal static ItemTransition_RangeID Get(SafeDataReader dr) - { - return new ItemTransition_RangeID(dr); - } - public ItemTransition_RangeID() - { - MarkAsChild(); - _TransitionID = Transition.NextTransitionID; - _IsRange = _ItemTransition_RangeIDExtension.DefaultIsRange; - _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; - _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; - _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemTransition_RangeID(Content myContent, Item myItemToID) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _TransitionID = Transition.NextTransitionID; - _IsRange = _ItemTransition_RangeIDExtension.DefaultIsRange; - _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; - _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; - _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; - _MyContent = myContent; - _MyItemToID = myItemToID; - ValidationRules.CheckRules(); - } - internal ItemTransition_RangeID(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ItemTransition_RangeID() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_RangeID.FetchDR", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _ToID = dr.GetInt32("ToID"); - _IsRange = dr.GetInt32("IsRange"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_RangeID.FetchDR", ex); - throw new DbCslaException("ItemTransition_RangeID.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Item myItemRangeID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Item myItemRangeID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, _ToID, myItemRangeID.ItemID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Item myItemRangeID) - { - // 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"]; - Transition.Remove(cn, _TransitionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemTransition_RangeIDExtension _ItemTransition_RangeIDExtension = new ItemTransition_RangeIDExtension(); - [Serializable()] - partial class ItemTransition_RangeIDExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultIsRange - { - get { return 0; } - } - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemTransition_RangeIDConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemTransition_RangeID) - { - // Return the ToString value - return ((ItemTransition_RangeID)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemTransition_RangeID Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemTransition_RangeIDConverter))] + public partial class ItemTransition_RangeID : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + _FromID = value.ContentID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private Item _MyItemToID; + public Item MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); + return _MyItemToID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemToID != value) + { + _MyItemToID = value; + _ToID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _IsRange; + /// + /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling + /// + public int IsRange + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _IsRange; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_IsRange != value) + { + _IsRange = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // CSLATODO: Check ItemTransition_RangeID.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemTransition_RangeID + protected override object GetIdValue() + { + return MyItemTransition_RangeIDUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ItemTransition_RangeID.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemTransition_RangeID + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyContentRequired(ItemTransition_RangeID target, Csla.Validation.RuleArgs e) + { + if (target._FromID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(TransitionID, ""); + //AuthorizationRules.AllowRead(FromID, ""); + //AuthorizationRules.AllowWrite(FromID, ""); + //AuthorizationRules.AllowRead(ToID, ""); + //AuthorizationRules.AllowWrite(ToID, ""); + //AuthorizationRules.AllowRead(IsRange, ""); + //AuthorizationRules.AllowWrite(IsRange, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ItemTransition_RangeIDUnique = 0; + private static int ItemTransition_RangeIDUnique + { get { return ++_ItemTransition_RangeIDUnique; } } + private int _MyItemTransition_RangeIDUnique = ItemTransition_RangeIDUnique; + public int MyItemTransition_RangeIDUnique // Absolutely Unique ID - Editable FK + { get { return _MyItemTransition_RangeIDUnique; } } + internal static ItemTransition_RangeID New(Content myContent, Item myItemToID) + { + return new ItemTransition_RangeID(myContent, myItemToID); + } + internal static ItemTransition_RangeID Get(SafeDataReader dr) + { + return new ItemTransition_RangeID(dr); + } + public ItemTransition_RangeID() + { + MarkAsChild(); + _TransitionID = Transition.NextTransitionID; + _IsRange = _ItemTransition_RangeIDExtension.DefaultIsRange; + _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; + _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; + _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemTransition_RangeID(Content myContent, Item myItemToID) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _TransitionID = Transition.NextTransitionID; + _IsRange = _ItemTransition_RangeIDExtension.DefaultIsRange; + _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; + _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; + _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; + _MyContent = myContent; + _MyItemToID = myItemToID; + ValidationRules.CheckRules(); + } + internal ItemTransition_RangeID(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ItemTransition_RangeID() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_RangeID.FetchDR", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _ToID = dr.GetInt32("ToID"); + _IsRange = dr.GetInt32("IsRange"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_RangeID.FetchDR", ex); + throw new DbCslaException("ItemTransition_RangeID.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Item myItemRangeID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Item myItemRangeID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, _ToID, myItemRangeID.ItemID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Item myItemRangeID) + { + // 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"]; + Transition.Remove(cn, _TransitionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemTransition_RangeIDExtension _ItemTransition_RangeIDExtension = new ItemTransition_RangeIDExtension(); + [Serializable()] + partial class ItemTransition_RangeIDExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultIsRange + { + get { return 0; } + } + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemTransition_RangeIDConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemTransition_RangeID) + { + // Return the ToString value + return ((ItemTransition_RangeID)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_ToID.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_ToID.cs index cf2edc6d..7e3b9a27 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_ToID.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ItemTransition_ToID.cs @@ -20,642 +20,617 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemTransition_ToID Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemTransition_ToIDConverter))] - public partial class ItemTransition_ToID : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - _FromID = value.ContentID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private Item _MyItemRangeID; - public Item MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); - return _MyItemRangeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemRangeID", true); - if (_MyItemRangeID != value) - { - _MyItemRangeID = value; - _RangeID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _IsRange; - /// - /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling - /// - public int IsRange - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("IsRange", true); - return _IsRange; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("IsRange", true); - if (_IsRange != value) - { - _IsRange = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // CSLATODO: Check ItemTransition_ToID.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemTransition_ToID - protected override object GetIdValue() - { - return MyItemTransition_ToIDUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ItemTransition_ToID.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemTransition_ToID - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyContentRequired(ItemTransition_ToID target, Csla.Validation.RuleArgs e) - { - if (target._FromID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(TransitionID, ""); - //AuthorizationRules.AllowRead(FromID, ""); - //AuthorizationRules.AllowWrite(FromID, ""); - //AuthorizationRules.AllowRead(RangeID, ""); - //AuthorizationRules.AllowWrite(RangeID, ""); - //AuthorizationRules.AllowRead(IsRange, ""); - //AuthorizationRules.AllowWrite(IsRange, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ItemTransition_ToIDUnique = 0; - private static int ItemTransition_ToIDUnique - { get { return ++_ItemTransition_ToIDUnique; } } - private int _MyItemTransition_ToIDUnique = ItemTransition_ToIDUnique; - public int MyItemTransition_ToIDUnique // Absolutely Unique ID - Editable FK - { get { return _MyItemTransition_ToIDUnique; } } - internal static ItemTransition_ToID New(Content myContent, Item myItemRangeID) - { - return new ItemTransition_ToID(myContent, myItemRangeID); - } - internal static ItemTransition_ToID Get(SafeDataReader dr) - { - return new ItemTransition_ToID(dr); - } - public ItemTransition_ToID() - { - MarkAsChild(); - _TransitionID = Transition.NextTransitionID; - _IsRange = _ItemTransition_ToIDExtension.DefaultIsRange; - _TranType = _ItemTransition_ToIDExtension.DefaultTranType; - _DTS = _ItemTransition_ToIDExtension.DefaultDTS; - _UserID = _ItemTransition_ToIDExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemTransition_ToID(Content myContent, Item myItemRangeID) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _TransitionID = Transition.NextTransitionID; - _IsRange = _ItemTransition_ToIDExtension.DefaultIsRange; - _TranType = _ItemTransition_ToIDExtension.DefaultTranType; - _DTS = _ItemTransition_ToIDExtension.DefaultDTS; - _UserID = _ItemTransition_ToIDExtension.DefaultUserID; - _MyContent = myContent; - _MyItemRangeID = myItemRangeID; - ValidationRules.CheckRules(); - } - internal ItemTransition_ToID(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ItemTransition_ToID() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_ToID.FetchDR", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _RangeID = dr.GetInt32("RangeID"); - _IsRange = dr.GetInt32("IsRange"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_ToID.FetchDR", ex); - throw new DbCslaException("ItemTransition_ToID.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Item myItemToID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Item myItemToID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, myItemToID.ItemID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Item myItemToID) - { - // 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"]; - Transition.Remove(cn, _TransitionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemTransition_ToIDExtension _ItemTransition_ToIDExtension = new ItemTransition_ToIDExtension(); - [Serializable()] - partial class ItemTransition_ToIDExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultIsRange - { - get { return 0; } - } - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemTransition_ToIDConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemTransition_ToID) - { - // Return the ToString value - return ((ItemTransition_ToID)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemTransition_ToID Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemTransition_ToIDConverter))] + public partial class ItemTransition_ToID : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + _FromID = value.ContentID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private Item _MyItemRangeID; + public Item MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); + return _MyItemRangeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemRangeID != value) + { + _MyItemRangeID = value; + _RangeID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _IsRange; + /// + /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling + /// + public int IsRange + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _IsRange; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_IsRange != value) + { + _IsRange = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // CSLATODO: Check ItemTransition_ToID.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemTransition_ToID + protected override object GetIdValue() + { + return MyItemTransition_ToIDUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ItemTransition_ToID.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemTransition_ToID + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyContentRequired(ItemTransition_ToID target, Csla.Validation.RuleArgs e) + { + if (target._FromID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(TransitionID, ""); + //AuthorizationRules.AllowRead(FromID, ""); + //AuthorizationRules.AllowWrite(FromID, ""); + //AuthorizationRules.AllowRead(RangeID, ""); + //AuthorizationRules.AllowWrite(RangeID, ""); + //AuthorizationRules.AllowRead(IsRange, ""); + //AuthorizationRules.AllowWrite(IsRange, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ItemTransition_ToIDUnique = 0; + private static int ItemTransition_ToIDUnique + { get { return ++_ItemTransition_ToIDUnique; } } + private int _MyItemTransition_ToIDUnique = ItemTransition_ToIDUnique; + public int MyItemTransition_ToIDUnique // Absolutely Unique ID - Editable FK + { get { return _MyItemTransition_ToIDUnique; } } + internal static ItemTransition_ToID New(Content myContent, Item myItemRangeID) + { + return new ItemTransition_ToID(myContent, myItemRangeID); + } + internal static ItemTransition_ToID Get(SafeDataReader dr) + { + return new ItemTransition_ToID(dr); + } + public ItemTransition_ToID() + { + MarkAsChild(); + _TransitionID = Transition.NextTransitionID; + _IsRange = _ItemTransition_ToIDExtension.DefaultIsRange; + _TranType = _ItemTransition_ToIDExtension.DefaultTranType; + _DTS = _ItemTransition_ToIDExtension.DefaultDTS; + _UserID = _ItemTransition_ToIDExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemTransition_ToID(Content myContent, Item myItemRangeID) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _TransitionID = Transition.NextTransitionID; + _IsRange = _ItemTransition_ToIDExtension.DefaultIsRange; + _TranType = _ItemTransition_ToIDExtension.DefaultTranType; + _DTS = _ItemTransition_ToIDExtension.DefaultDTS; + _UserID = _ItemTransition_ToIDExtension.DefaultUserID; + _MyContent = myContent; + _MyItemRangeID = myItemRangeID; + ValidationRules.CheckRules(); + } + internal ItemTransition_ToID(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ItemTransition_ToID() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_ToID.FetchDR", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _RangeID = dr.GetInt32("RangeID"); + _IsRange = dr.GetInt32("IsRange"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_ToID.FetchDR", ex); + throw new DbCslaException("ItemTransition_ToID.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Item myItemToID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Item myItemToID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, myItemToID.ItemID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Item myItemToID) + { + // 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"]; + Transition.Remove(cn, _TransitionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemTransition_ToIDExtension _ItemTransition_ToIDExtension = new ItemTransition_ToIDExtension(); + [Serializable()] + partial class ItemTransition_ToIDExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultIsRange + { + get { return 0; } + } + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemTransition_ToIDConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemTransition_ToID) + { + // Return the ToString value + return ((ItemTransition_ToID)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs index 314b04f3..c24a7fca 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Membership.cs @@ -20,1170 +20,1153 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Membership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(MembershipConverter))] - public partial class Membership : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshMemberships = new List(); - private void AddToRefreshList(List refreshMemberships) - { - if (IsDirty) - refreshMemberships.Add(this); - } - private void ClearRefreshList() - { - _RefreshMemberships = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshMemberships); - } - private void ProcessRefreshList() - { - foreach (Membership tmp in _RefreshMemberships) - { - MembershipInfo.Refresh(tmp); - if (tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup); - if (tmp._MyUser != null) UserInfo.Refresh(tmp._MyUser); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Membership membership) - { - if (!_CacheList.Contains(membership)) _CacheList.Add(membership); // In AddToCache - } - protected static void RemoveFromCache(Membership membership) - { - while (_CacheList.Contains(membership)) _CacheList.Remove(membership); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Membership(s) from temporary _CacheList to _CacheByPrimaryKey - { - Membership tmp = _CacheList[0]; // Get the first Membership - string pKey = tmp.UGID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Membership - } - } - protected static Membership GetCachedByPrimaryKey(int ugid) - { - ConvertListToDictionary(); - string key = ugid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextUGID = -1; - public static int NextUGID - { - get { return _nextUGID--; } - } - private int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - return _UGID; - } - } - private int _UID; - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - if (_MyUser != null) _UID = _MyUser.UID; - return _UID; - } - } - private User _MyUser; - public User MyUser - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyUser", true); - if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); - return _MyUser; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyUser", true); - if (_MyUser != value) - { - _MyUser = value; - _UID = value.UID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - _GID = value.GID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyUser == null ? false : _MyUser.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyUser == null ? true : _MyUser.IsValidList(list)); - } - // CSLATODO: Replace base Membership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Membership - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Membership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Membership - protected override object GetIdValue() - { - return MyMembershipUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyUserRequired, "MyUser"); - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _MembershipExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _MembershipExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(Membership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(Membership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyUserRequired(Membership target, Csla.Validation.RuleArgs e) - { - if (target._UID == 0 && target._MyUser == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyGroupRequired(Membership target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(UID, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _MembershipExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _MembershipExtension.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; } } - private static int _MembershipUnique = 0; - protected static int MembershipUnique - { get { return ++_MembershipUnique; } } - private int _MyMembershipUnique = MembershipUnique; - public int MyMembershipUnique // Absolutely Unique ID - Editable - { get { return _MyMembershipUnique; } } - protected Membership() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Membership() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(UGID.ToString())) - { - List listMembership = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items - while (listMembership.Contains(this)) listMembership.Remove(this); // Remove the item from the list - if (listMembership.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list - } - } - public static Membership New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Membership"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.New", ex); - } - } - public static Membership New(User myUser, Group myGroup) - { - Membership tmp = Membership.New(); - tmp.MyUser = myUser; - tmp.MyGroup = myGroup; - return tmp; - } - public static Membership New(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Membership tmp = Membership.New(); - tmp.MyUser = myUser; - tmp.MyGroup = myGroup; - tmp.StartDate = startDate; - tmp.EndDate = endDate; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Membership MakeMembership(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Membership New(User myUser, Group myGroup, string endDate, string config) - { - Membership tmp = Membership.New(); - tmp.MyUser = myUser; - tmp.MyGroup = myGroup; - tmp.EndDate = endDate; - tmp.Config = config; - return tmp; - } - public static Membership MakeMembership(User myUser, Group myGroup, string endDate, string config) - { - Membership tmp = Membership.New(myUser, myGroup, endDate, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Membership Get(int ugid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Membership"); - try - { - Membership tmp = GetCachedByPrimaryKey(ugid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ugid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Membership - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.Get", ex); - } - } - public static Membership Get(SafeDataReader dr) - { - if (dr.Read()) return new Membership(dr); - return null; - } - internal Membership(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int ugid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Membership"); - try - { - DataPortal.Delete(new PKCriteria(ugid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.Delete", ex); - } - } - public override Membership Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Membership"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Membership"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Membership"); - try - { - BuildRefreshList(); - Membership membership = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(membership);//Refresh the item in AllList - ProcessRefreshList(); - return membership; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _UGID; - public int UGID - { get { return _UGID; } } - public PKCriteria(int ugid) - { - _UGID = ugid; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _UGID = NextUGID; - // Database Defaults - _StartDate = _MembershipExtension.DefaultStartDate; - _DTS = _MembershipExtension.DefaultDTS; - _UsrID = _MembershipExtension.DefaultUsrID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.ReadData", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _UID = dr.GetInt32("UID"); - _GID = dr.GetInt32("GID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getMembership"; - cm.Parameters.AddWithValue("@UGID", criteria.UGID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyGroup != null) _MyGroup.Update(); - if (_MyUser != null) _MyUser.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addMembership"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UID", UID); - cm.Parameters.AddWithValue("@GID", GID); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); - param_UGID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UGID); - 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 - _UGID = (int)cm.Parameters["@newUGID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addMembership"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UID", myUser.UID); - cm.Parameters.AddWithValue("@GID", myGroup.GID); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); - param_UGID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UGID); - 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 - ugid = (int)cm.Parameters["@newUGID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Add", ex); - throw new DbCslaException("Membership.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Membership.SQLUpdate", GetHashCode()); - try - { - if (_MyGroup != null) _MyGroup.Update(); - if (_MyUser != null) _MyUser.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateMembership"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@UGID", _UGID); - cm.Parameters.AddWithValue("@UID", UID); - cm.Parameters.AddWithValue("@GID", GID); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Membership.Add(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); - else - _LastChanged = Membership.Update(cn, ref _UGID, _UID, _GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int ugid, int uid, int gid, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateMembership"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UGID", ugid); - cm.Parameters.AddWithValue("@UID", uid); - cm.Parameters.AddWithValue("@GID", gid); - cm.Parameters.AddWithValue("@StartDate", startDate); - cm.Parameters.AddWithValue("@EndDate", endDate); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Update", ex); - throw new DbCslaException("Membership.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_UGID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteMembership"; - cm.Parameters.AddWithValue("@UGID", criteria.UGID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int ugid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteMembership"; - // Input PK Fields - cm.Parameters.AddWithValue("@UGID", ugid); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Remove", ex); - throw new DbCslaException("Membership.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int ugid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(ugid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _UGID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int ugid) - { - _UGID = ugid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsMembership"; - cm.Parameters.AddWithValue("@UGID", _UGID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Execute", ex); - throw new DbCslaException("Membership.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - MembershipExtension _MembershipExtension = new MembershipExtension(); - [Serializable()] - partial class MembershipExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class MembershipConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Membership) - { - // Return the ToString value - return ((Membership)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Membership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(MembershipConverter))] + public partial class Membership : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshMemberships = new List(); + private void AddToRefreshList(List refreshMemberships) + { + if (IsDirty) + refreshMemberships.Add(this); + } + private void ClearRefreshList() + { + _RefreshMemberships = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshMemberships); + } + private void ProcessRefreshList() + { + foreach (Membership tmp in _RefreshMemberships) + { + MembershipInfo.Refresh(tmp); + if (tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup); + if (tmp._MyUser != null) UserInfo.Refresh(tmp._MyUser); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Membership membership) + { + if (!_CacheList.Contains(membership)) _CacheList.Add(membership); // In AddToCache + } + protected static void RemoveFromCache(Membership membership) + { + while (_CacheList.Contains(membership)) _CacheList.Remove(membership); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Membership(s) from temporary _CacheList to _CacheByPrimaryKey + { + Membership tmp = _CacheList[0]; // Get the first Membership + string pKey = tmp.UGID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Membership + } + } + protected static Membership GetCachedByPrimaryKey(int ugid) + { + ConvertListToDictionary(); + string key = ugid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextUGID = -1; + public static int NextUGID + { + get { return _nextUGID--; } + } + private int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UGID; + } + } + private int _UID; + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser != null) _UID = _MyUser.UID; + return _UID; + } + } + private User _MyUser; + public User MyUser + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); + return _MyUser; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyUser != value) + { + _MyUser = value; + _UID = value.UID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + _GID = value.GID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyUser == null ? false : _MyUser.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyUser == null ? true : _MyUser.IsValidList(list)); + } + // CSLATODO: Replace base Membership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Membership + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Membership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Membership + protected override object GetIdValue() + { + return MyMembershipUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyUserRequired, "MyUser"); + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _MembershipExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _MembershipExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(Membership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(Membership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyUserRequired(Membership target, Csla.Validation.RuleArgs e) + { + if (target._UID == 0 && target._MyUser == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyGroupRequired(Membership target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(UID, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _MembershipExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _MembershipExtension.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; } } + private static int _MembershipUnique = 0; + protected static int MembershipUnique + { get { return ++_MembershipUnique; } } + private int _MyMembershipUnique = MembershipUnique; + public int MyMembershipUnique // Absolutely Unique ID - Editable + { get { return _MyMembershipUnique; } } + protected Membership() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Membership() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(UGID.ToString())) + { + List listMembership = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items + while (listMembership.Contains(this)) listMembership.Remove(this); // Remove the item from the list + if (listMembership.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list + } + } + public static Membership New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Membership"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.New", ex); + } + } + public static Membership New(User myUser, Group myGroup) + { + Membership tmp = Membership.New(); + tmp.MyUser = myUser; + tmp.MyGroup = myGroup; + return tmp; + } + public static Membership New(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Membership tmp = Membership.New(); + tmp.MyUser = myUser; + tmp.MyGroup = myGroup; + tmp.StartDate = startDate; + tmp.EndDate = endDate; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Membership MakeMembership(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Membership New(User myUser, Group myGroup, string endDate, string config) + { + Membership tmp = Membership.New(); + tmp.MyUser = myUser; + tmp.MyGroup = myGroup; + tmp.EndDate = endDate; + tmp.Config = config; + return tmp; + } + public static Membership MakeMembership(User myUser, Group myGroup, string endDate, string config) + { + Membership tmp = Membership.New(myUser, myGroup, endDate, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Membership Get(int ugid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Membership"); + try + { + Membership tmp = GetCachedByPrimaryKey(ugid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ugid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Membership + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.Get", ex); + } + } + public static Membership Get(SafeDataReader dr) + { + if (dr.Read()) return new Membership(dr); + return null; + } + internal Membership(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int ugid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Membership"); + try + { + DataPortal.Delete(new PKCriteria(ugid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.Delete", ex); + } + } + public override Membership Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Membership"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Membership"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Membership"); + try + { + BuildRefreshList(); + Membership membership = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(membership);//Refresh the item in AllList + ProcessRefreshList(); + return membership; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _UGID; + public int UGID + { get { return _UGID; } } + public PKCriteria(int ugid) + { + _UGID = ugid; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _UGID = NextUGID; + // Database Defaults + _StartDate = _MembershipExtension.DefaultStartDate; + _DTS = _MembershipExtension.DefaultDTS; + _UsrID = _MembershipExtension.DefaultUsrID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.ReadData", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _UID = dr.GetInt32("UID"); + _GID = dr.GetInt32("GID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembership"; + cm.Parameters.AddWithValue("@UGID", criteria.UGID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyGroup != null) _MyGroup.Update(); + if (_MyUser != null) _MyUser.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addMembership"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UID", UID); + cm.Parameters.AddWithValue("@GID", GID); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); + param_UGID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UGID); + 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 + _UGID = (int)cm.Parameters["@newUGID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addMembership"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UID", myUser.UID); + cm.Parameters.AddWithValue("@GID", myGroup.GID); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); + param_UGID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UGID); + 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 + ugid = (int)cm.Parameters["@newUGID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Add", ex); + throw new DbCslaException("Membership.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Membership.SQLUpdate", GetHashCode()); + try + { + if (_MyGroup != null) _MyGroup.Update(); + if (_MyUser != null) _MyUser.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateMembership"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@UGID", _UGID); + cm.Parameters.AddWithValue("@UID", UID); + cm.Parameters.AddWithValue("@GID", GID); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Membership.Add(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); + else + _LastChanged = Membership.Update(cn, ref _UGID, _UID, _GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int ugid, int uid, int gid, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateMembership"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UGID", ugid); + cm.Parameters.AddWithValue("@UID", uid); + cm.Parameters.AddWithValue("@GID", gid); + cm.Parameters.AddWithValue("@StartDate", startDate); + cm.Parameters.AddWithValue("@EndDate", endDate); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Update", ex); + throw new DbCslaException("Membership.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_UGID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteMembership"; + cm.Parameters.AddWithValue("@UGID", criteria.UGID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int ugid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteMembership"; + // Input PK Fields + cm.Parameters.AddWithValue("@UGID", ugid); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Remove", ex); + throw new DbCslaException("Membership.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int ugid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(ugid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _UGID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int ugid) + { + _UGID = ugid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsMembership"; + cm.Parameters.AddWithValue("@UGID", _UGID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Execute", ex); + throw new DbCslaException("Membership.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + MembershipExtension _MembershipExtension = new MembershipExtension(); + [Serializable()] + partial class MembershipExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class MembershipConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Membership) + { + // Return the ToString value + return ((Membership)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs index 8411ed91..afbc060c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/MembershipInfo.cs @@ -19,459 +19,449 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void MembershipInfoEvent(object sender); - /// - /// MembershipInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(MembershipInfoConverter))] - public partial class MembershipInfo : ReadOnlyBase, IDisposable - { - public event MembershipInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(MembershipInfo membershipInfo) - { - if (!_CacheList.Contains(membershipInfo)) _CacheList.Add(membershipInfo); // In AddToCache - } - protected static void RemoveFromCache(MembershipInfo membershipInfo) - { - while (_CacheList.Contains(membershipInfo)) _CacheList.Remove(membershipInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move MembershipInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - MembershipInfo tmp = _CacheList[0]; // Get the first MembershipInfo - string pKey = tmp.UGID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first MembershipInfo - } - } - internal static void AddList(MembershipInfoList lst) - { - foreach (MembershipInfo item in lst) AddToCache(item); - } - protected static MembershipInfo GetCachedByPrimaryKey(int ugid) - { - ConvertListToDictionary(); - string key = ugid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Membership _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - return _UGID; - } - } - private int _UID; - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - if (_MyUser != null) _UID = _MyUser.UID; - return _UID; - } - } - private UserInfo _MyUser; - public UserInfo MyUser - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyUser", true); - if (_MyUser == null && _UID != 0) _MyUser = UserInfo.Get(_UID); - return _MyUser; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private GroupInfo _MyGroup; - public GroupInfo MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); - return _MyGroup; - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - // CSLATODO: Replace base MembershipInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current MembershipInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check MembershipInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current MembershipInfo - protected override object GetIdValue() - { - return MyMembershipInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _MembershipInfoUnique = 0; - private static int MembershipInfoUnique - { get { return ++_MembershipInfoUnique; } } - private int _MyMembershipInfoUnique = MembershipInfoUnique; - public int MyMembershipInfoUnique // Absolutely Unique ID - Info - { get { return _MyMembershipInfoUnique; } } - protected MembershipInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~MembershipInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(UGID.ToString())) return; - List listMembershipInfo = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items - while (listMembershipInfo.Contains(this)) listMembershipInfo.Remove(this); // Remove the item from the list - if (listMembershipInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list - } - public virtual Membership Get() - { - return _Editable = Membership.Get(_UGID); - } - public static void Refresh(Membership tmp) - { - string key = tmp.UGID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Membership tmp) - { - if (_UID != tmp.UID) - { - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value - _UID = tmp.UID; // Update the value - } - _MyUser = null; // Reset list so that the next line gets a new list - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _MembershipInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(GroupMembership tmp) - { - string key = tmp.UGID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(GroupMembership tmp) - { - if (_UID != tmp.UID) - { - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value - _UID = tmp.UID; // Update the value - } - _MyUser = null; // Reset list so that the next line gets a new list - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _MembershipInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(UserMembership tmp) - { - string key = tmp.UGID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(UserMembership tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _MembershipInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static MembershipInfo Get(int ugid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Membership"); - try - { - MembershipInfo tmp = GetCachedByPrimaryKey(ugid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ugid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up MembershipInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on MembershipInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal MembershipInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.Constructor", ex); - throw new DbCslaException("MembershipInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _UGID; - public int UGID - { get { return _UGID; } } - public PKCriteria(int ugid) - { - _UGID = ugid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.ReadData", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _UID = dr.GetInt32("UID"); - _GID = dr.GetInt32("GID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("MembershipInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getMembership"; - cm.Parameters.AddWithValue("@UGID", criteria.UGID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("MembershipInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - MembershipInfoExtension _MembershipInfoExtension = new MembershipInfoExtension(); - [Serializable()] - partial class MembershipInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(MembershipInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class MembershipInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is MembershipInfo) - { - // Return the ToString value - return ((MembershipInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void MembershipInfoEvent(object sender); + /// + /// MembershipInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(MembershipInfoConverter))] + public partial class MembershipInfo : ReadOnlyBase, IDisposable + { + public event MembershipInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(MembershipInfo membershipInfo) + { + if (!_CacheList.Contains(membershipInfo)) _CacheList.Add(membershipInfo); // In AddToCache + } + protected static void RemoveFromCache(MembershipInfo membershipInfo) + { + while (_CacheList.Contains(membershipInfo)) _CacheList.Remove(membershipInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move MembershipInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + MembershipInfo tmp = _CacheList[0]; // Get the first MembershipInfo + string pKey = tmp.UGID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first MembershipInfo + } + } + internal static void AddList(MembershipInfoList lst) + { + foreach (MembershipInfo item in lst) AddToCache(item); + } + protected static MembershipInfo GetCachedByPrimaryKey(int ugid) + { + ConvertListToDictionary(); + string key = ugid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Membership _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UGID; + } + } + private int _UID; + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser != null) _UID = _MyUser.UID; + return _UID; + } + } + private UserInfo _MyUser; + public UserInfo MyUser + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser == null && _UID != 0) _MyUser = UserInfo.Get(_UID); + return _MyUser; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private GroupInfo _MyGroup; + public GroupInfo MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); + return _MyGroup; + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + // CSLATODO: Replace base MembershipInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current MembershipInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check MembershipInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current MembershipInfo + protected override object GetIdValue() + { + return MyMembershipInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _MembershipInfoUnique = 0; + private static int MembershipInfoUnique + { get { return ++_MembershipInfoUnique; } } + private int _MyMembershipInfoUnique = MembershipInfoUnique; + public int MyMembershipInfoUnique // Absolutely Unique ID - Info + { get { return _MyMembershipInfoUnique; } } + protected MembershipInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~MembershipInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(UGID.ToString())) return; + List listMembershipInfo = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items + while (listMembershipInfo.Contains(this)) listMembershipInfo.Remove(this); // Remove the item from the list + if (listMembershipInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list + } + public virtual Membership Get() + { + return _Editable = Membership.Get(_UGID); + } + public static void Refresh(Membership tmp) + { + string key = tmp.UGID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Membership tmp) + { + if (_UID != tmp.UID) + { + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value + _UID = tmp.UID; // Update the value + } + _MyUser = null; // Reset list so that the next line gets a new list + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(GroupMembership tmp) + { + string key = tmp.UGID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(GroupMembership tmp) + { + if (_UID != tmp.UID) + { + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value + _UID = tmp.UID; // Update the value + } + _MyUser = null; // Reset list so that the next line gets a new list + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(UserMembership tmp) + { + string key = tmp.UGID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(UserMembership tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static MembershipInfo Get(int ugid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Membership"); + try + { + MembershipInfo tmp = GetCachedByPrimaryKey(ugid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ugid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up MembershipInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on MembershipInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal MembershipInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.Constructor", ex); + throw new DbCslaException("MembershipInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _UGID; + public int UGID + { get { return _UGID; } } + public PKCriteria(int ugid) + { + _UGID = ugid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.ReadData", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _UID = dr.GetInt32("UID"); + _GID = dr.GetInt32("GID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("MembershipInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembership"; + cm.Parameters.AddWithValue("@UGID", criteria.UGID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("MembershipInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + MembershipInfoExtension _MembershipInfoExtension = new MembershipInfoExtension(); + [Serializable()] + partial class MembershipInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(MembershipInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class MembershipInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is MembershipInfo) + { + // Return the ToString value + return ((MembershipInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Owner.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Owner.cs index b9dd7cd6..180f3cb3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Owner.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Owner.cs @@ -20,934 +20,925 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Owner Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(OwnerConverter))] - public partial class Owner : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshOwners = new List(); - private void AddToRefreshList(List refreshOwners) - { - if (IsDirty) - refreshOwners.Add(this); - } - private void ClearRefreshList() - { - _RefreshOwners = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshOwners); - } - private void ProcessRefreshList() - { - foreach (Owner tmp in _RefreshOwners) - { - OwnerInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Owner owner) - { - if (!_CacheList.Contains(owner)) _CacheList.Add(owner); // In AddToCache - } - protected static void RemoveFromCache(Owner owner) - { - while (_CacheList.Contains(owner)) _CacheList.Remove(owner); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Owner(s) from temporary _CacheList to _CacheByPrimaryKey - { - Owner tmp = _CacheList[0]; // Get the first Owner - string pKey = tmp.OwnerID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Owner - } - } - protected static Owner GetCachedByPrimaryKey(int ownerID) - { - ConvertListToDictionary(); - string key = ownerID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextOwnerID = -1; - public static int NextOwnerID - { - get { return _nextOwnerID--; } - } - private int _OwnerID; - [System.ComponentModel.DataObjectField(true, true)] - public int OwnerID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerID", true); - return _OwnerID; - } - } - private int _SessionID; - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SessionID", true); - if (_SessionID != value) - { - _SessionID = value; - PropertyHasChanged(); - } - } - } - private byte _OwnerType; - public byte OwnerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerType", true); - return _OwnerType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("OwnerType", true); - if (_OwnerType != value) - { - _OwnerType = value; - PropertyHasChanged(); - } - } - } - private int _OwnerItemID; - public int OwnerItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerItemID", true); - return _OwnerItemID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("OwnerItemID", true); - if (_OwnerItemID != value) - { - _OwnerItemID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTSStart = new DateTime(); - public DateTime DTSStart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSStart", true); - return _DTSStart; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSStart", true); - if (_DTSStart != value) - { - _DTSStart = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base Owner.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Owner - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Owner.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Owner - protected override object GetIdValue() - { - return MyOwnerUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - //ValidationRules.AddDependantProperty("x", "y"); - _OwnerExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _OwnerExtension.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(OwnerID, ""); - //AuthorizationRules.AllowRead(SessionID, ""); - //AuthorizationRules.AllowRead(OwnerType, ""); - //AuthorizationRules.AllowRead(OwnerItemID, ""); - //AuthorizationRules.AllowRead(DTSStart, ""); - //AuthorizationRules.AllowWrite(SessionID, ""); - //AuthorizationRules.AllowWrite(OwnerType, ""); - //AuthorizationRules.AllowWrite(OwnerItemID, ""); - //AuthorizationRules.AllowWrite(DTSStart, ""); - _OwnerExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _OwnerExtension.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; } } - private static int _OwnerUnique = 0; - protected static int OwnerUnique - { get { return ++_OwnerUnique; } } - private int _MyOwnerUnique = OwnerUnique; - public int MyOwnerUnique // Absolutely Unique ID - Editable - { get { return _MyOwnerUnique; } } - protected Owner() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Owner() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) - { - List listOwner = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items - while (listOwner.Contains(this)) listOwner.Remove(this); // Remove the item from the list - if (listOwner.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list - } - } - public static Owner New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Owner"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.New", ex); - } - } - public static Owner New(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) - { - Owner tmp = Owner.New(); - tmp.SessionID = sessionID; - tmp.OwnerType = ownerType; - tmp.OwnerItemID = ownerItemID; - tmp.DTSStart = dTSStart; - return tmp; - } - public static Owner MakeOwner(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) - { - Owner tmp = Owner.New(sessionID, ownerType, ownerItemID, dTSStart); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Owner Get(int ownerID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Owner"); - try - { - Owner tmp = GetCachedByPrimaryKey(ownerID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ownerID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Owner - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.Get", ex); - } - } - public static Owner Get(SafeDataReader dr) - { - if (dr.Read()) return new Owner(dr); - return null; - } - internal Owner(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int ownerID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Owner"); - try - { - DataPortal.Delete(new PKCriteria(ownerID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.Delete", ex); - } - } - public override Owner Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Owner"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Owner"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Owner"); - try - { - BuildRefreshList(); - Owner owner = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(owner);//Refresh the item in AllList - ProcessRefreshList(); - return owner; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _OwnerID; - public int OwnerID - { get { return _OwnerID; } } - public PKCriteria(int ownerID) - { - _OwnerID = ownerID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _OwnerID = NextOwnerID; - // Database Defaults - _SessionID = _OwnerExtension.DefaultSessionID; - _OwnerType = _OwnerExtension.DefaultOwnerType; - _OwnerItemID = _OwnerExtension.DefaultOwnerItemID; - _DTSStart = _OwnerExtension.DefaultDTSStart; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.ReadData", GetHashCode()); - try - { - _OwnerID = dr.GetInt32("OwnerID"); - _SessionID = dr.GetInt32("SessionID"); - _OwnerType = dr.GetByte("OwnerType"); - _OwnerItemID = dr.GetInt32("OwnerItemID"); - _DTSStart = dr.GetDateTime("DTSStart"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "getOwner"; - cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addOwner"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@SessionID", _SessionID); - cm.Parameters.AddWithValue("@OwnerType", _OwnerType); - cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); - if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); - // Output Calculated Columns - SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); - param_OwnerID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_OwnerID); - 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 - _OwnerID = (int)cm.Parameters["@newOwnerID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addOwner"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@SessionID", sessionID); - cm.Parameters.AddWithValue("@OwnerType", ownerType); - cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); - if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); - // Output Calculated Columns - SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); - param_OwnerID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_OwnerID); - 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 - ownerID = (int)cm.Parameters["@newOwnerID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Add", ex); - throw new DbCslaException("Owner.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Owner.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateOwner"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@OwnerID", _OwnerID); - cm.Parameters.AddWithValue("@SessionID", _SessionID); - cm.Parameters.AddWithValue("@OwnerType", _OwnerType); - cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); - if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Owner.Add(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart); - else - _LastChanged = Owner.Update(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateOwner"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@OwnerID", ownerID); - cm.Parameters.AddWithValue("@SessionID", sessionID); - cm.Parameters.AddWithValue("@OwnerType", ownerType); - cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); - if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Update", ex); - throw new DbCslaException("Owner.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_OwnerID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteOwner"; - cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int ownerID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteOwner"; - // Input PK Fields - cm.Parameters.AddWithValue("@OwnerID", ownerID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Remove", ex); - throw new DbCslaException("Owner.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int ownerID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(ownerID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _OwnerID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int ownerID) - { - _OwnerID = ownerID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsOwner"; - cm.Parameters.AddWithValue("@OwnerID", _OwnerID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Execute", ex); - throw new DbCslaException("Owner.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - OwnerExtension _OwnerExtension = new OwnerExtension(); - [Serializable()] - partial class OwnerExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultSessionID - { - get { return 0; } - } - public virtual byte DefaultOwnerType - { - get { return 0; } - } - public virtual int DefaultOwnerItemID - { - get { return 0; } - } - public virtual DateTime DefaultDTSStart - { - get { return DateTime.Now; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class OwnerConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Owner) - { - // Return the ToString value - return ((Owner)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Owner Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(OwnerConverter))] + public partial class Owner : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshOwners = new List(); + private void AddToRefreshList(List refreshOwners) + { + if (IsDirty) + refreshOwners.Add(this); + } + private void ClearRefreshList() + { + _RefreshOwners = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshOwners); + } + private void ProcessRefreshList() + { + foreach (Owner tmp in _RefreshOwners) + { + OwnerInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Owner owner) + { + if (!_CacheList.Contains(owner)) _CacheList.Add(owner); // In AddToCache + } + protected static void RemoveFromCache(Owner owner) + { + while (_CacheList.Contains(owner)) _CacheList.Remove(owner); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Owner(s) from temporary _CacheList to _CacheByPrimaryKey + { + Owner tmp = _CacheList[0]; // Get the first Owner + string pKey = tmp.OwnerID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Owner + } + } + protected static Owner GetCachedByPrimaryKey(int ownerID) + { + ConvertListToDictionary(); + string key = ownerID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextOwnerID = -1; + public static int NextOwnerID + { + get { return _nextOwnerID--; } + } + private int _OwnerID; + [System.ComponentModel.DataObjectField(true, true)] + public int OwnerID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerID; + } + } + private int _SessionID; + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_SessionID != value) + { + _SessionID = value; + PropertyHasChanged(); + } + } + } + private byte _OwnerType; + public byte OwnerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_OwnerType != value) + { + _OwnerType = value; + PropertyHasChanged(); + } + } + } + private int _OwnerItemID; + public int OwnerItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerItemID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_OwnerItemID != value) + { + _OwnerItemID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTSStart = new DateTime(); + public DateTime DTSStart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSStart; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSStart != value) + { + _DTSStart = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base Owner.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Owner + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Owner.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Owner + protected override object GetIdValue() + { + return MyOwnerUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + //ValidationRules.AddDependantProperty("x", "y"); + _OwnerExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _OwnerExtension.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(OwnerID, ""); + //AuthorizationRules.AllowRead(SessionID, ""); + //AuthorizationRules.AllowRead(OwnerType, ""); + //AuthorizationRules.AllowRead(OwnerItemID, ""); + //AuthorizationRules.AllowRead(DTSStart, ""); + //AuthorizationRules.AllowWrite(SessionID, ""); + //AuthorizationRules.AllowWrite(OwnerType, ""); + //AuthorizationRules.AllowWrite(OwnerItemID, ""); + //AuthorizationRules.AllowWrite(DTSStart, ""); + _OwnerExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _OwnerExtension.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; } } + private static int _OwnerUnique = 0; + protected static int OwnerUnique + { get { return ++_OwnerUnique; } } + private int _MyOwnerUnique = OwnerUnique; + public int MyOwnerUnique // Absolutely Unique ID - Editable + { get { return _MyOwnerUnique; } } + protected Owner() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Owner() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) + { + List listOwner = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items + while (listOwner.Contains(this)) listOwner.Remove(this); // Remove the item from the list + if (listOwner.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list + } + } + public static Owner New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Owner"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.New", ex); + } + } + public static Owner New(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) + { + Owner tmp = Owner.New(); + tmp.SessionID = sessionID; + tmp.OwnerType = ownerType; + tmp.OwnerItemID = ownerItemID; + tmp.DTSStart = dTSStart; + return tmp; + } + public static Owner MakeOwner(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) + { + Owner tmp = Owner.New(sessionID, ownerType, ownerItemID, dTSStart); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Owner Get(int ownerID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Owner"); + try + { + Owner tmp = GetCachedByPrimaryKey(ownerID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ownerID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Owner + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.Get", ex); + } + } + public static Owner Get(SafeDataReader dr) + { + if (dr.Read()) return new Owner(dr); + return null; + } + internal Owner(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int ownerID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Owner"); + try + { + DataPortal.Delete(new PKCriteria(ownerID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.Delete", ex); + } + } + public override Owner Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Owner"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Owner"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Owner"); + try + { + BuildRefreshList(); + Owner owner = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(owner);//Refresh the item in AllList + ProcessRefreshList(); + return owner; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _OwnerID; + public int OwnerID + { get { return _OwnerID; } } + public PKCriteria(int ownerID) + { + _OwnerID = ownerID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _OwnerID = NextOwnerID; + // Database Defaults + _SessionID = _OwnerExtension.DefaultSessionID; + _OwnerType = _OwnerExtension.DefaultOwnerType; + _OwnerItemID = _OwnerExtension.DefaultOwnerItemID; + _DTSStart = _OwnerExtension.DefaultDTSStart; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.ReadData", GetHashCode()); + try + { + _OwnerID = dr.GetInt32("OwnerID"); + _SessionID = dr.GetInt32("SessionID"); + _OwnerType = dr.GetByte("OwnerType"); + _OwnerItemID = dr.GetInt32("OwnerItemID"); + _DTSStart = dr.GetDateTime("DTSStart"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "getOwner"; + cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addOwner"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@SessionID", _SessionID); + cm.Parameters.AddWithValue("@OwnerType", _OwnerType); + cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); + if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); + // Output Calculated Columns + SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); + param_OwnerID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_OwnerID); + 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 + _OwnerID = (int)cm.Parameters["@newOwnerID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addOwner"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@SessionID", sessionID); + cm.Parameters.AddWithValue("@OwnerType", ownerType); + cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); + if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); + // Output Calculated Columns + SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); + param_OwnerID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_OwnerID); + 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 + ownerID = (int)cm.Parameters["@newOwnerID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Add", ex); + throw new DbCslaException("Owner.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Owner.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateOwner"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@OwnerID", _OwnerID); + cm.Parameters.AddWithValue("@SessionID", _SessionID); + cm.Parameters.AddWithValue("@OwnerType", _OwnerType); + cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); + if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Owner.Add(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart); + else + _LastChanged = Owner.Update(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateOwner"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@OwnerID", ownerID); + cm.Parameters.AddWithValue("@SessionID", sessionID); + cm.Parameters.AddWithValue("@OwnerType", ownerType); + cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); + if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Update", ex); + throw new DbCslaException("Owner.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_OwnerID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteOwner"; + cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int ownerID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteOwner"; + // Input PK Fields + cm.Parameters.AddWithValue("@OwnerID", ownerID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Remove", ex); + throw new DbCslaException("Owner.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int ownerID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(ownerID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _OwnerID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int ownerID) + { + _OwnerID = ownerID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsOwner"; + cm.Parameters.AddWithValue("@OwnerID", _OwnerID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Execute", ex); + throw new DbCslaException("Owner.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + OwnerExtension _OwnerExtension = new OwnerExtension(); + [Serializable()] + partial class OwnerExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultSessionID + { + get { return 0; } + } + public virtual byte DefaultOwnerType + { + get { return 0; } + } + public virtual int DefaultOwnerItemID + { + get { return 0; } + } + public virtual DateTime DefaultDTSStart + { + get { return DateTime.Now; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class OwnerConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Owner) + { + // Return the ToString value + return ((Owner)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/OwnerInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/OwnerInfo.cs index e0686532..c4955fc3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/OwnerInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/OwnerInfo.cs @@ -19,337 +19,332 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void OwnerInfoEvent(object sender); - /// - /// OwnerInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(OwnerInfoConverter))] - public partial class OwnerInfo : ReadOnlyBase, IDisposable - { - public event OwnerInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(OwnerInfo ownerInfo) - { - if (!_CacheList.Contains(ownerInfo)) _CacheList.Add(ownerInfo); // In AddToCache - } - protected static void RemoveFromCache(OwnerInfo ownerInfo) - { - while (_CacheList.Contains(ownerInfo)) _CacheList.Remove(ownerInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move OwnerInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - OwnerInfo tmp = _CacheList[0]; // Get the first OwnerInfo - string pKey = tmp.OwnerID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first OwnerInfo - } - } - internal static void AddList(OwnerInfoList lst) - { - foreach (OwnerInfo item in lst) AddToCache(item); - } - protected static OwnerInfo GetCachedByPrimaryKey(int ownerID) - { - ConvertListToDictionary(); - string key = ownerID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Owner _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _OwnerID; - [System.ComponentModel.DataObjectField(true, true)] - public int OwnerID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerID", true); - return _OwnerID; - } - } - private int _SessionID; - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - } - private byte _OwnerType; - public byte OwnerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerType", true); - return _OwnerType; - } - } - private int _OwnerItemID; - public int OwnerItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerItemID", true); - return _OwnerItemID; - } - } - private DateTime _DTSStart = new DateTime(); - public DateTime DTSStart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSStart", true); - return _DTSStart; - } - } - // CSLATODO: Replace base OwnerInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current OwnerInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check OwnerInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current OwnerInfo - protected override object GetIdValue() - { - return MyOwnerInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _OwnerInfoUnique = 0; - private static int OwnerInfoUnique - { get { return ++_OwnerInfoUnique; } } - private int _MyOwnerInfoUnique = OwnerInfoUnique; - public int MyOwnerInfoUnique // Absolutely Unique ID - Info - { get { return _MyOwnerInfoUnique; } } - protected OwnerInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~OwnerInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) return; - List listOwnerInfo = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items - while (listOwnerInfo.Contains(this)) listOwnerInfo.Remove(this); // Remove the item from the list - if (listOwnerInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list - } - public virtual Owner Get() - { - return _Editable = Owner.Get(_OwnerID); - } - public static void Refresh(Owner tmp) - { - string key = tmp.OwnerID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (OwnerInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Owner tmp) - { - _SessionID = tmp.SessionID; - _OwnerType = tmp.OwnerType; - _OwnerItemID = tmp.OwnerItemID; - _DTSStart = tmp.DTSStart; - _OwnerInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static OwnerInfo Get(int ownerID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Owner"); - try - { - OwnerInfo tmp = GetCachedByPrimaryKey(ownerID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ownerID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up OwnerInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on OwnerInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal OwnerInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.Constructor", ex); - throw new DbCslaException("OwnerInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _OwnerID; - public int OwnerID - { get { return _OwnerID; } } - public PKCriteria(int ownerID) - { - _OwnerID = ownerID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.ReadData", GetHashCode()); - try - { - _OwnerID = dr.GetInt32("OwnerID"); - _SessionID = dr.GetInt32("SessionID"); - _OwnerType = dr.GetByte("OwnerType"); - _OwnerItemID = dr.GetInt32("OwnerItemID"); - _DTSStart = dr.GetDateTime("DTSStart"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("OwnerInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "getOwner"; - cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("OwnerInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - OwnerInfoExtension _OwnerInfoExtension = new OwnerInfoExtension(); - [Serializable()] - partial class OwnerInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(OwnerInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class OwnerInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is OwnerInfo) - { - // Return the ToString value - return ((OwnerInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void OwnerInfoEvent(object sender); + /// + /// OwnerInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(OwnerInfoConverter))] + public partial class OwnerInfo : ReadOnlyBase, IDisposable + { + public event OwnerInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(OwnerInfo ownerInfo) + { + if (!_CacheList.Contains(ownerInfo)) _CacheList.Add(ownerInfo); // In AddToCache + } + protected static void RemoveFromCache(OwnerInfo ownerInfo) + { + while (_CacheList.Contains(ownerInfo)) _CacheList.Remove(ownerInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move OwnerInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + OwnerInfo tmp = _CacheList[0]; // Get the first OwnerInfo + string pKey = tmp.OwnerID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first OwnerInfo + } + } + internal static void AddList(OwnerInfoList lst) + { + foreach (OwnerInfo item in lst) AddToCache(item); + } + protected static OwnerInfo GetCachedByPrimaryKey(int ownerID) + { + ConvertListToDictionary(); + string key = ownerID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Owner _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _OwnerID; + [System.ComponentModel.DataObjectField(true, true)] + public int OwnerID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerID; + } + } + private int _SessionID; + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + } + private byte _OwnerType; + public byte OwnerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerType; + } + } + private int _OwnerItemID; + public int OwnerItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerItemID; + } + } + private DateTime _DTSStart = new DateTime(); + public DateTime DTSStart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSStart; + } + } + // CSLATODO: Replace base OwnerInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current OwnerInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check OwnerInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current OwnerInfo + protected override object GetIdValue() + { + return MyOwnerInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _OwnerInfoUnique = 0; + private static int OwnerInfoUnique + { get { return ++_OwnerInfoUnique; } } + private int _MyOwnerInfoUnique = OwnerInfoUnique; + public int MyOwnerInfoUnique // Absolutely Unique ID - Info + { get { return _MyOwnerInfoUnique; } } + protected OwnerInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~OwnerInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) return; + List listOwnerInfo = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items + while (listOwnerInfo.Contains(this)) listOwnerInfo.Remove(this); // Remove the item from the list + if (listOwnerInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list + } + public virtual Owner Get() + { + return _Editable = Owner.Get(_OwnerID); + } + public static void Refresh(Owner tmp) + { + string key = tmp.OwnerID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (OwnerInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Owner tmp) + { + _SessionID = tmp.SessionID; + _OwnerType = tmp.OwnerType; + _OwnerItemID = tmp.OwnerItemID; + _DTSStart = tmp.DTSStart; + _OwnerInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static OwnerInfo Get(int ownerID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Owner"); + try + { + OwnerInfo tmp = GetCachedByPrimaryKey(ownerID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ownerID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up OwnerInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on OwnerInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal OwnerInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.Constructor", ex); + throw new DbCslaException("OwnerInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _OwnerID; + public int OwnerID + { get { return _OwnerID; } } + public PKCriteria(int ownerID) + { + _OwnerID = ownerID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.ReadData", GetHashCode()); + try + { + _OwnerID = dr.GetInt32("OwnerID"); + _SessionID = dr.GetInt32("SessionID"); + _OwnerType = dr.GetByte("OwnerType"); + _OwnerItemID = dr.GetInt32("OwnerItemID"); + _DTSStart = dr.GetDateTime("DTSStart"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("OwnerInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "getOwner"; + cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("OwnerInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + OwnerInfoExtension _OwnerInfoExtension = new OwnerInfoExtension(); + [Serializable()] + partial class OwnerInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(OwnerInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class OwnerInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is OwnerInfo) + { + // Return the ToString value + return ((OwnerInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs index c7e1b8b8..a058a679 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Part.cs @@ -20,998 +20,988 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Part Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PartConverter))] - public partial class Part : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshParts = new List(); - private void AddToRefreshList(List refreshParts) - { - if (IsDirty) - refreshParts.Add(this); - } - private void ClearRefreshList() - { - _RefreshParts = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshParts); - } - private void ProcessRefreshList() - { - foreach (Part tmp in _RefreshParts) - { - PartInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Part part) - { - if (!_CacheList.Contains(part)) _CacheList.Add(part); // In AddToCache - } - protected static void RemoveFromCache(Part part) - { - while (_CacheList.Contains(part)) _CacheList.Remove(part); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Part(s) from temporary _CacheList to _CacheByPrimaryKey - { - Part tmp = _CacheList[0]; // Get the first Part - string pKey = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Part - } - } - protected static Part GetCachedByPrimaryKey(int contentID, int fromType) - { - ConvertListToDictionary(); - string key = contentID.ToString() + "_" + fromType.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if (_MyItem != value) - { - _MyItem = value; - _ItemID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)) || (_MyItem == null ? false : _MyItem.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)) && (_MyItem == null ? true : _MyItem.IsValidList(list)); - } - // CSLATODO: Replace base Part.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Part - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Part.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Part - protected override object GetIdValue() - { - return MyPartUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemRequired, "MyItem"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _PartExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _PartExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyItemRequired(Part target, Csla.Validation.RuleArgs e) - { - if (target._ItemID == 0 && target._MyItem == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(FromType, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _PartExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _PartExtension.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; } } - private static int _PartUnique = 0; - protected static int PartUnique - { get { return ++_PartUnique; } } - private int _MyPartUnique = PartUnique; - public int MyPartUnique // Absolutely Unique ID - Editable - { get { return _MyPartUnique; } } - protected Part() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Part() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) - { - List listPart = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items - while (listPart.Contains(this)) listPart.Remove(this); // Remove the item from the list - if (listPart.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list - } - } - public static Part New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Part"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.New", ex); - } - } - public static Part New(Content myContent, int fromType, Item myItem) - { - Part tmp = Part.New(); - tmp._MyContent = myContent; - tmp._FromType = fromType; - tmp.MyItem = myItem; - return tmp; - } - public static Part MakePart(Content myContent, int fromType, Item myItem) - { - Part tmp = Part.New(myContent, fromType, myItem); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Part New(Content myContent, int fromType, Item myItem, DateTime dts, string userID) - { - Part tmp = Part.New(); - tmp._MyContent = myContent; - tmp._FromType = fromType; - tmp.MyItem = myItem; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Part MakePart(Content myContent, int fromType, Item myItem, DateTime dts, string userID) - { - Part tmp = Part.New(myContent, fromType, myItem, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Part Get(int contentID, int fromType) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Part"); - try - { - Part tmp = GetCachedByPrimaryKey(contentID, fromType); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Part - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.Get", ex); - } - } - public static Part Get(SafeDataReader dr) - { - if (dr.Read()) return new Part(dr); - return null; - } - internal Part(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int contentID, int fromType) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Part"); - try - { - DataPortal.Delete(new PKCriteria(contentID, fromType)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.Delete", ex); - } - } - public override Part Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Part"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Part"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Part"); - try - { - BuildRefreshList(); - Part part = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(part);//Refresh the item in AllList - ProcessRefreshList(); - return part; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - private int _FromType; - public int FromType - { get { return _FromType; } } - public PKCriteria(int contentID, int fromType) - { - _ContentID = contentID; - _FromType = fromType; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// Part Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartConverter))] + public partial class Part : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshParts = new List(); + private void AddToRefreshList(List refreshParts) + { + if (IsDirty) + refreshParts.Add(this); + } + private void ClearRefreshList() + { + _RefreshParts = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshParts); + } + private void ProcessRefreshList() + { + foreach (Part tmp in _RefreshParts) + { + PartInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Part part) + { + if (!_CacheList.Contains(part)) _CacheList.Add(part); // In AddToCache + } + protected static void RemoveFromCache(Part part) + { + while (_CacheList.Contains(part)) _CacheList.Remove(part); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Part(s) from temporary _CacheList to _CacheByPrimaryKey + { + Part tmp = _CacheList[0]; // Get the first Part + string pKey = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Part + } + } + protected static Part GetCachedByPrimaryKey(int contentID, int fromType) + { + ConvertListToDictionary(); + string key = contentID.ToString() + "_" + fromType.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItem != value) + { + _MyItem = value; + _ItemID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)) || (_MyItem == null ? false : _MyItem.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)) && (_MyItem == null ? true : _MyItem.IsValidList(list)); + } + // CSLATODO: Replace base Part.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Part + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Part.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Part + protected override object GetIdValue() + { + return MyPartUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemRequired, "MyItem"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _PartExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _PartExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyItemRequired(Part target, Csla.Validation.RuleArgs e) + { + if (target._ItemID == 0 && target._MyItem == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(FromType, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _PartExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _PartExtension.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; } } + private static int _PartUnique = 0; + protected static int PartUnique + { get { return ++_PartUnique; } } + private int _MyPartUnique = PartUnique; + public int MyPartUnique // Absolutely Unique ID - Editable + { get { return _MyPartUnique; } } + protected Part() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Part() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) + { + List listPart = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items + while (listPart.Contains(this)) listPart.Remove(this); // Remove the item from the list + if (listPart.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list + } + } + public static Part New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Part"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.New", ex); + } + } + public static Part New(Content myContent, int fromType, Item myItem) + { + Part tmp = Part.New(); + tmp._MyContent = myContent; + tmp._FromType = fromType; + tmp.MyItem = myItem; + return tmp; + } + public static Part MakePart(Content myContent, int fromType, Item myItem) + { + Part tmp = Part.New(myContent, fromType, myItem); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Part New(Content myContent, int fromType, Item myItem, DateTime dts, string userID) + { + Part tmp = Part.New(); + tmp._MyContent = myContent; + tmp._FromType = fromType; + tmp.MyItem = myItem; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Part MakePart(Content myContent, int fromType, Item myItem, DateTime dts, string userID) + { + Part tmp = Part.New(myContent, fromType, myItem, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Part Get(int contentID, int fromType) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Part"); + try + { + Part tmp = GetCachedByPrimaryKey(contentID, fromType); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Part + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.Get", ex); + } + } + public static Part Get(SafeDataReader dr) + { + if (dr.Read()) return new Part(dr); + return null; + } + internal Part(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int contentID, int fromType) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Part"); + try + { + DataPortal.Delete(new PKCriteria(contentID, fromType)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.Delete", ex); + } + } + public override Part Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Part"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Part"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Part"); + try + { + BuildRefreshList(); + Part part = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(part);//Refresh the item in AllList + ProcessRefreshList(); + return part; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + private int _FromType; + public int FromType + { get { return _FromType; } } + public PKCriteria(int contentID, int fromType) + { + _ContentID = contentID; + _FromType = fromType; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _PartExtension.DefaultDTS; - _UserID = _PartExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPart"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.Parameters.AddWithValue("@FromType", criteria.FromType); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPart"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - cm.Parameters.AddWithValue("@ItemID", ItemID); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPart"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@FromType", fromType); - cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Add", ex); - throw new DbCslaException("Part.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Part.SQLUpdate", GetHashCode()); - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePart"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - cm.Parameters.AddWithValue("@ItemID", ItemID); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Part.Add(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID); - else - _LastChanged = Part.Update(cn, _ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, int contentID, int fromType, int itemID, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePart"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@FromType", fromType); - cm.Parameters.AddWithValue("@ItemID", itemID); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Update", ex); - throw new DbCslaException("Part.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ContentID, _FromType)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePart"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.Parameters.AddWithValue("@FromType", criteria.FromType); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int contentID, int fromType) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePart"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@FromType", fromType); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Remove", ex); - throw new DbCslaException("Part.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID, int fromType) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID, fromType)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private int _FromType; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID, int fromType) - { - _ContentID = contentID; - _FromType = fromType; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsPart"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Execute", ex); - throw new DbCslaException("Part.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - PartExtension _PartExtension = new PartExtension(); - [Serializable()] - partial class PartExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class PartConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Part) - { - // Return the ToString value - return ((Part)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _PartExtension.DefaultDTS; + _UserID = _PartExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPart"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.Parameters.AddWithValue("@FromType", criteria.FromType); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItem != null) _MyItem.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPart"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", ItemID); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPart"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Add", ex); + throw new DbCslaException("Part.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Part.SQLUpdate", GetHashCode()); + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItem != null) _MyItem.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePart"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", ItemID); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Part.Add(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID); + else + _LastChanged = Part.Update(cn, _ContentID, _FromType, _ItemID, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, int contentID, int fromType, int itemID, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePart"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", itemID); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Update", ex); + throw new DbCslaException("Part.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ContentID, _FromType)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePart"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.Parameters.AddWithValue("@FromType", criteria.FromType); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int contentID, int fromType) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePart"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@FromType", fromType); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Remove", ex); + throw new DbCslaException("Part.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID, int fromType) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID, fromType)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private int _FromType; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID, int fromType) + { + _ContentID = contentID; + _FromType = fromType; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsPart"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Execute", ex); + throw new DbCslaException("Part.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + PartExtension _PartExtension = new PartExtension(); + [Serializable()] + partial class PartExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class PartConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Part) + { + // Return the ToString value + return ((Part)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs index ce1af975..6e4fdcc9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartAudit.cs @@ -20,905 +20,892 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// PartAudit Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PartAuditConverter))] - public partial class PartAudit : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshPartAudits = new List(); - private void AddToRefreshList(List refreshPartAudits) - { - if (IsDirty) - refreshPartAudits.Add(this); - } - private void ClearRefreshList() - { - _RefreshPartAudits = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshPartAudits); - } - private void ProcessRefreshList() - { - foreach (PartAudit tmp in _RefreshPartAudits) - { - PartAuditInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(PartAudit partAudit) - { - if (!_CacheList.Contains(partAudit)) _CacheList.Add(partAudit); // In AddToCache - } - protected static void RemoveFromCache(PartAudit partAudit) - { - while (_CacheList.Contains(partAudit)) _CacheList.Remove(partAudit); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move PartAudit(s) from temporary _CacheList to _CacheByPrimaryKey - { - PartAudit tmp = _CacheList[0]; // Get the first PartAudit - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first PartAudit - } - } - protected static PartAudit GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAuditID = -1; - public static int NextAuditID - { - get { return _nextAuditID--; } - } - private long _AuditID; - [System.ComponentModel.DataObjectField(true, true)] - public long AuditID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ContentID", true); - if (_ContentID != value) - { - _ContentID = value; - PropertyHasChanged(); - } - } - } - private int _FromType; - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FromType", true); - if (_FromType != value) - { - _FromType = value; - PropertyHasChanged(); - } - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemID", true); - if (_ItemID != value) - { - _ItemID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DeleteStatus", true); - if (_DeleteStatus != value) - { - _DeleteStatus = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base PartAudit.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PartAudit - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check PartAudit.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PartAudit - protected override object GetIdValue() - { - return MyPartAuditUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _PartAuditExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _PartAuditExtension.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, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(FromType, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DeleteStatus, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(FromType, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DeleteStatus, ""); - _PartAuditExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _PartAuditExtension.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; } } - private static int _PartAuditUnique = 0; - protected static int PartAuditUnique - { get { return ++_PartAuditUnique; } } - private int _MyPartAuditUnique = PartAuditUnique; - public int MyPartAuditUnique // Absolutely Unique ID - Editable - { get { return _MyPartAuditUnique; } } - protected PartAudit() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~PartAudit() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) - { - List listPartAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listPartAudit.Contains(this)) listPartAudit.Remove(this); // Remove the item from the list - if (listPartAudit.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - } - public static PartAudit New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a PartAudit"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartAudit.New", ex); - } - } - public static PartAudit New(int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) - { - PartAudit tmp = PartAudit.New(); - tmp.ContentID = contentID; - tmp.FromType = fromType; - tmp.ItemID = itemID; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.DeleteStatus = deleteStatus; - return tmp; - } - public static PartAudit MakePartAudit(int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) - { - PartAudit tmp = PartAudit.New(contentID, fromType, itemID, dts, userID, deleteStatus); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static PartAudit Get(long auditID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a PartAudit"); - try - { - PartAudit tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up PartAudit - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartAudit.Get", ex); - } - } - public static PartAudit Get(SafeDataReader dr) - { - if (dr.Read()) return new PartAudit(dr); - return null; - } - internal PartAudit(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(long auditID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a PartAudit"); - try - { - DataPortal.Delete(new PKCriteria(auditID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartAudit.Delete", ex); - } - } - public override PartAudit Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a PartAudit"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a PartAudit"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a PartAudit"); - try - { - BuildRefreshList(); - PartAudit partAudit = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(partAudit);//Refresh the item in AllList - ProcessRefreshList(); - return partAudit; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AuditID = NextAuditID; - // Database Defaults + /// + /// PartAudit Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartAuditConverter))] + public partial class PartAudit : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshPartAudits = new List(); + private void AddToRefreshList(List refreshPartAudits) + { + if (IsDirty) + refreshPartAudits.Add(this); + } + private void ClearRefreshList() + { + _RefreshPartAudits = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshPartAudits); + } + private void ProcessRefreshList() + { + foreach (PartAudit tmp in _RefreshPartAudits) + { + PartAuditInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PartAudit partAudit) + { + if (!_CacheList.Contains(partAudit)) _CacheList.Add(partAudit); // In AddToCache + } + protected static void RemoveFromCache(PartAudit partAudit) + { + while (_CacheList.Contains(partAudit)) _CacheList.Remove(partAudit); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move PartAudit(s) from temporary _CacheList to _CacheByPrimaryKey + { + PartAudit tmp = _CacheList[0]; // Get the first PartAudit + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first PartAudit + } + } + protected static PartAudit GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAuditID = -1; + public static int NextAuditID + { + get { return _nextAuditID--; } + } + private long _AuditID; + [System.ComponentModel.DataObjectField(true, true)] + public long AuditID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ContentID != value) + { + _ContentID = value; + PropertyHasChanged(); + } + } + } + private int _FromType; + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_FromType != value) + { + _FromType = value; + PropertyHasChanged(); + } + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemID != value) + { + _ItemID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DeleteStatus != value) + { + _DeleteStatus = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base PartAudit.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PartAudit + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check PartAudit.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PartAudit + protected override object GetIdValue() + { + return MyPartAuditUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _PartAuditExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _PartAuditExtension.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, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(FromType, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DeleteStatus, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(FromType, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DeleteStatus, ""); + _PartAuditExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _PartAuditExtension.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; } } + private static int _PartAuditUnique = 0; + protected static int PartAuditUnique + { get { return ++_PartAuditUnique; } } + private int _MyPartAuditUnique = PartAuditUnique; + public int MyPartAuditUnique // Absolutely Unique ID - Editable + { get { return _MyPartAuditUnique; } } + protected PartAudit() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~PartAudit() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) + { + List listPartAudit = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listPartAudit.Contains(this)) listPartAudit.Remove(this); // Remove the item from the list + if (listPartAudit.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + } + public static PartAudit New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a PartAudit"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAudit.New", ex); + } + } + public static PartAudit New(int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + PartAudit tmp = PartAudit.New(); + tmp.ContentID = contentID; + tmp.FromType = fromType; + tmp.ItemID = itemID; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.DeleteStatus = deleteStatus; + return tmp; + } + public static PartAudit MakePartAudit(int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + PartAudit tmp = PartAudit.New(contentID, fromType, itemID, dts, userID, deleteStatus); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static PartAudit Get(long auditID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a PartAudit"); + try + { + PartAudit tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PartAudit + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAudit.Get", ex); + } + } + public static PartAudit Get(SafeDataReader dr) + { + if (dr.Read()) return new PartAudit(dr); + return null; + } + internal PartAudit(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(long auditID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a PartAudit"); + try + { + DataPortal.Delete(new PKCriteria(auditID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAudit.Delete", ex); + } + } + public override PartAudit Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a PartAudit"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a PartAudit"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a PartAudit"); + try + { + BuildRefreshList(); + PartAudit partAudit = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(partAudit);//Refresh the item in AllList + ProcessRefreshList(); + return partAudit; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AuditID = NextAuditID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartAudit.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPartAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartAudit.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartAudit.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPartAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - cm.Parameters.AddWithValue("@ItemID", _ItemID); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartAudit.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Add(SqlConnection cn, ref long auditID, int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPartAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@FromType", fromType); - cm.Parameters.AddWithValue("@ItemID", itemID); - 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; - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Add", ex); - throw new DbCslaException("PartAudit.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] PartAudit.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePartAudit"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AuditID", _AuditID); - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - cm.Parameters.AddWithValue("@ItemID", _ItemID); - 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - PartAudit.Add(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus); - else - PartAudit.Update(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Update(SqlConnection cn, ref long auditID, int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePartAudit"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AuditID", auditID); - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@FromType", fromType); - cm.Parameters.AddWithValue("@ItemID", itemID); - 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 - // No Timestamp value to return - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Update", ex); - throw new DbCslaException("PartAudit.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}] PartAudit.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePartAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartAudit.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, long auditID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePartAudit"; - // Input PK Fields - cm.Parameters.AddWithValue("@AuditID", auditID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Remove", ex); - throw new DbCslaException("PartAudit.Remove", ex); - } - } - #endregion - // Standard Default Code - #region extension - PartAuditExtension _PartAuditExtension = new PartAuditExtension(); - [Serializable()] - partial class PartAuditExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class PartAuditConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PartAudit) - { - // Return the ToString value - return ((PartAudit)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPartAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Add(SqlConnection cn, ref long auditID, int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPartAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", itemID); + 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; + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Add", ex); + throw new DbCslaException("PartAudit.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] PartAudit.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePartAudit"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AuditID", _AuditID); + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + PartAudit.Add(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus); + else + PartAudit.Update(cn, ref _AuditID, _ContentID, _FromType, _ItemID, _DTS, _UserID, _DeleteStatus); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Update(SqlConnection cn, ref long auditID, int contentID, int fromType, int itemID, DateTime dts, string userID, int deleteStatus) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePartAudit"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AuditID", auditID); + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", itemID); + 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 + // No Timestamp value to return + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Update", ex); + throw new DbCslaException("PartAudit.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}] PartAudit.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePartAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAudit.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, long auditID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAudit.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePartAudit"; + // Input PK Fields + cm.Parameters.AddWithValue("@AuditID", auditID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAudit.Remove", ex); + throw new DbCslaException("PartAudit.Remove", ex); + } + } + #endregion + // Standard Default Code + #region extension + PartAuditExtension _PartAuditExtension = new PartAuditExtension(); + [Serializable()] + partial class PartAuditExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class PartAuditConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartAudit) + { + // Return the ToString value + return ((PartAudit)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfo.cs index 85eff6da..f57dd7bc 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartAuditInfo.cs @@ -19,361 +19,354 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void PartAuditInfoEvent(object sender); - /// - /// PartAuditInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PartAuditInfoConverter))] - public partial class PartAuditInfo : ReadOnlyBase, IDisposable - { - public event PartAuditInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(PartAuditInfo partAuditInfo) - { - if (!_CacheList.Contains(partAuditInfo)) _CacheList.Add(partAuditInfo); // In AddToCache - } - protected static void RemoveFromCache(PartAuditInfo partAuditInfo) - { - while (_CacheList.Contains(partAuditInfo)) _CacheList.Remove(partAuditInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move PartAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - PartAuditInfo tmp = _CacheList[0]; // Get the first PartAuditInfo - string pKey = tmp.AuditID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first PartAuditInfo - } - } - internal static void AddList(PartAuditInfoList lst) - { - foreach (PartAuditInfo item in lst) AddToCache(item); - } - protected static PartAuditInfo GetCachedByPrimaryKey(long auditID) - { - ConvertListToDictionary(); - string key = auditID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected PartAudit _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AuditID", true); - return _AuditID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private int _FromType; - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DeleteStatus; - public int DeleteStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DeleteStatus", true); - return _DeleteStatus; - } - } - // CSLATODO: Replace base PartAuditInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PartAuditInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check PartAuditInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PartAuditInfo - protected override object GetIdValue() - { - return MyPartAuditInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _PartAuditInfoUnique = 0; - private static int PartAuditInfoUnique - { get { return ++_PartAuditInfoUnique; } } - private int _MyPartAuditInfoUnique = PartAuditInfoUnique; - public int MyPartAuditInfoUnique // Absolutely Unique ID - Info - { get { return _MyPartAuditInfoUnique; } } - protected PartAuditInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~PartAuditInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; - List listPartAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items - while (listPartAuditInfo.Contains(this)) listPartAuditInfo.Remove(this); // Remove the item from the list - if (listPartAuditInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list - } - public virtual PartAudit Get() - { - return _Editable = PartAudit.Get(_AuditID); - } - public static void Refresh(PartAudit tmp) - { - string key = tmp.AuditID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PartAuditInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(PartAudit tmp) - { - _ContentID = tmp.ContentID; - _FromType = tmp.FromType; - _ItemID = tmp.ItemID; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DeleteStatus = tmp.DeleteStatus; - _PartAuditInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static PartAuditInfo Get(long auditID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a PartAudit"); - try - { - PartAuditInfo tmp = GetCachedByPrimaryKey(auditID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(auditID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up PartAuditInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartAuditInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal PartAuditInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.Constructor", ex); - throw new DbCslaException("PartAuditInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private long _AuditID; - public long AuditID - { get { return _AuditID; } } - public PKCriteria(long auditID) - { - _AuditID = auditID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.ReadData", GetHashCode()); - try - { - _AuditID = dr.GetInt64("AuditID"); - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DeleteStatus = dr.GetInt32("DeleteStatus"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartAuditInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPartAudit"; - cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartAuditInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - PartAuditInfoExtension _PartAuditInfoExtension = new PartAuditInfoExtension(); - [Serializable()] - partial class PartAuditInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(PartAuditInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class PartAuditInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PartAuditInfo) - { - // Return the ToString value - return ((PartAuditInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void PartAuditInfoEvent(object sender); + /// + /// PartAuditInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartAuditInfoConverter))] + public partial class PartAuditInfo : ReadOnlyBase, IDisposable + { + public event PartAuditInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PartAuditInfo partAuditInfo) + { + if (!_CacheList.Contains(partAuditInfo)) _CacheList.Add(partAuditInfo); // In AddToCache + } + protected static void RemoveFromCache(PartAuditInfo partAuditInfo) + { + while (_CacheList.Contains(partAuditInfo)) _CacheList.Remove(partAuditInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move PartAuditInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + PartAuditInfo tmp = _CacheList[0]; // Get the first PartAuditInfo + string pKey = tmp.AuditID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first PartAuditInfo + } + } + internal static void AddList(PartAuditInfoList lst) + { + foreach (PartAuditInfo item in lst) AddToCache(item); + } + protected static PartAuditInfo GetCachedByPrimaryKey(long auditID) + { + ConvertListToDictionary(); + string key = auditID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected PartAudit _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AuditID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private int _FromType; + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DeleteStatus; + public int DeleteStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DeleteStatus; + } + } + // CSLATODO: Replace base PartAuditInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PartAuditInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check PartAuditInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PartAuditInfo + protected override object GetIdValue() + { + return MyPartAuditInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _PartAuditInfoUnique = 0; + private static int PartAuditInfoUnique + { get { return ++_PartAuditInfoUnique; } } + private int _MyPartAuditInfoUnique = PartAuditInfoUnique; + public int MyPartAuditInfoUnique // Absolutely Unique ID - Info + { get { return _MyPartAuditInfoUnique; } } + protected PartAuditInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~PartAuditInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AuditID.ToString())) return; + List listPartAuditInfo = _CacheByPrimaryKey[AuditID.ToString()]; // Get the list of items + while (listPartAuditInfo.Contains(this)) listPartAuditInfo.Remove(this); // Remove the item from the list + if (listPartAuditInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AuditID.ToString()); // remove the list + } + public virtual PartAudit Get() + { + return _Editable = PartAudit.Get(_AuditID); + } + public static void Refresh(PartAudit tmp) + { + string key = tmp.AuditID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartAuditInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(PartAudit tmp) + { + _ContentID = tmp.ContentID; + _FromType = tmp.FromType; + _ItemID = tmp.ItemID; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DeleteStatus = tmp.DeleteStatus; + _PartAuditInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static PartAuditInfo Get(long auditID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a PartAudit"); + try + { + PartAuditInfo tmp = GetCachedByPrimaryKey(auditID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(auditID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PartAuditInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartAuditInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal PartAuditInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.Constructor", ex); + throw new DbCslaException("PartAuditInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private long _AuditID; + public long AuditID + { get { return _AuditID; } } + public PKCriteria(long auditID) + { + _AuditID = auditID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.ReadData", GetHashCode()); + try + { + _AuditID = dr.GetInt64("AuditID"); + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DeleteStatus = dr.GetInt32("DeleteStatus"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAuditInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartAuditInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartAudit"; + cm.Parameters.AddWithValue("@AuditID", criteria.AuditID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartAuditInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartAuditInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + PartAuditInfoExtension _PartAuditInfoExtension = new PartAuditInfoExtension(); + [Serializable()] + partial class PartAuditInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(PartAuditInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class PartAuditInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartAuditInfo) + { + // Return the ToString value + return ((PartAuditInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs index dc5ebc1e..1586b596 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfo.cs @@ -19,410 +19,412 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void PartInfoEvent(object sender); - /// - /// PartInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PartInfoConverter))] - public partial class PartInfo : ReadOnlyBase, IDisposable - { - public event PartInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(PartInfo partInfo) - { - if (!_CacheList.Contains(partInfo)) _CacheList.Add(partInfo); // In AddToCache - } - protected static void RemoveFromCache(PartInfo partInfo) - { - while (_CacheList.Contains(partInfo)) _CacheList.Remove(partInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move PartInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - PartInfo tmp = _CacheList[0]; // Get the first PartInfo - string pKey = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first PartInfo - } - } - internal static void AddList(PartInfoList lst) - { - foreach (PartInfo item in lst) AddToCache(item); - } - protected static PartInfo GetCachedByPrimaryKey(int contentID, int fromType) - { - ConvertListToDictionary(); - string key = contentID.ToString() + "_" + fromType.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Part _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private ItemInfo _MyItem; - public ItemInfo MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID); - return _MyItem; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base PartInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PartInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check PartInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PartInfo - protected override object GetIdValue() - { - return MyPartInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _PartInfoUnique = 0; - private static int PartInfoUnique - { get { return ++_PartInfoUnique; } } - private int _MyPartInfoUnique = PartInfoUnique; - public int MyPartInfoUnique // Absolutely Unique ID - Info - { get { return _MyPartInfoUnique; } } - protected PartInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~PartInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; - List listPartInfo = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items - while (listPartInfo.Contains(this)) listPartInfo.Remove(this); // Remove the item from the list - if (listPartInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list - } - public virtual Part Get() - { - return _Editable = Part.Get(_ContentID, _FromType); - } - public static void Refresh(Part tmp) - { - string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Part tmp) - { - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PartInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(Content myContent, ContentPart tmp) - { - string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentPart tmp) - { - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PartInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ItemPart tmp) - { - string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemPart tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PartInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static PartInfo Get(int contentID, int fromType) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Part"); - try - { - PartInfo tmp = GetCachedByPrimaryKey(contentID, fromType); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up PartInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal PartInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.Constructor", ex); - throw new DbCslaException("PartInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - private int _FromType; - public int FromType - { get { return _FromType; } } - public PKCriteria(int contentID, int fromType) - { - _ContentID = contentID; - _FromType = fromType; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPart"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.Parameters.AddWithValue("@FromType", criteria.FromType); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - PartInfoExtension _PartInfoExtension = new PartInfoExtension(); - [Serializable()] - partial class PartInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(PartInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class PartInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PartInfo) - { - // Return the ToString value - return ((PartInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void PartInfoEvent(object sender); + /// + /// PartInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartInfoConverter))] + public partial class PartInfo : ReadOnlyBase, IDisposable + { + public event PartInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PartInfo partInfo) + { + if (!_CacheList.Contains(partInfo)) _CacheList.Add(partInfo); // In AddToCache + } + protected static void RemoveFromCache(PartInfo partInfo) + { + while (_CacheList.Contains(partInfo)) _CacheList.Remove(partInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move PartInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + PartInfo tmp = _CacheList[0]; // Get the first PartInfo + string pKey = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first PartInfo + } + } + internal static void AddList(PartInfoList lst) + { + foreach (PartInfo item in lst) AddToCache(item); + } + protected static PartInfo GetCachedByPrimaryKey(int contentID, int fromType) + { + ConvertListToDictionary(); + string key = contentID.ToString() + "_" + fromType.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + public static void ClearPartInfoCache() + { + _CacheByPrimaryKey.Clear(); + while (_CacheList.Count > 0) + { _CacheList[0].Dispose(); } + + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Part _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private ItemInfo _MyItem; + public ItemInfo MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID); + return _MyItem; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base PartInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PartInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check PartInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PartInfo + protected override object GetIdValue() + { + return MyPartInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _PartInfoUnique = 0; + private static int PartInfoUnique + { get { return ++_PartInfoUnique; } } + private int _MyPartInfoUnique = PartInfoUnique; + public int MyPartInfoUnique // Absolutely Unique ID - Info + { get { return _MyPartInfoUnique; } } + protected PartInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~PartInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + Changed = null; + _MyItems?.Dispose(); + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; + List listPartInfo = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items + while (listPartInfo.Contains(this)) listPartInfo.Remove(this); // Remove the item from the list + if (listPartInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list + } + public virtual Part Get() + { + return _Editable = Part.Get(_ContentID, _FromType); + } + public static void Refresh(Part tmp) + { + string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Part tmp) + { + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(Content myContent, ContentPart tmp) + { + string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentPart tmp) + { + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ItemPart tmp) + { + string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemPart tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static PartInfo Get(int contentID, int fromType) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Part"); + try + { + PartInfo tmp = GetCachedByPrimaryKey(contentID, fromType); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PartInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal PartInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.Constructor", ex); + throw new DbCslaException("PartInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + private int _FromType; + public int FromType + { get { return _FromType; } } + public PKCriteria(int contentID, int fromType) + { + _ContentID = contentID; + _FromType = fromType; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPart"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.Parameters.AddWithValue("@FromType", criteria.FromType); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + PartInfoExtension _PartInfoExtension = new PartInfoExtension(); + [Serializable()] + partial class PartInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(PartInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class PartInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartInfo) + { + // Return the ToString value + return ((PartInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PartInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfoList.cs index 7867c9fd..b9f44c2a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PartInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PartInfoList.cs @@ -19,324 +19,324 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - /// - /// PartInfoList Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PartInfoListConverter))] - public partial class PartInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Business Methods - internal new IList Items - { get { return base.Items; } } - public void AddEvents() - { - foreach (PartInfo tmp in this) - { - tmp.Changed += new PartInfoEvent(tmp_Changed); - } - } - void tmp_Changed(object sender) - { - for (int i = 0; i < Count; i++) - { - if (base[i] == sender) - this.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; } } - ~PartInfoList() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - foreach (PartInfo tmp in this) - { - tmp.Changed -= new PartInfoEvent(tmp_Changed); - } - } - #endregion - #region Factory Methods - public static PartInfoList _PartInfoList = null; - /// - /// Return a list of all PartInfo. - /// - public static PartInfoList Get() - { - try - { - if (_PartInfoList != null) - return _PartInfoList; - PartInfoList tmp = DataPortal.Fetch(); - PartInfo.AddList(tmp); - tmp.AddEvents(); - _PartInfoList = tmp; - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartInfoList.Get", ex); - } - } - /// - /// Reset the list of all PartInfo. - /// - public static void Reset() - { - _PartInfoList = null; - } - // CSLATODO: Add alternative gets - - //public static PartInfoList Get() - //{ - // try - // { - // return DataPortal.Fetch(new FilteredCriteria()); - // } - // catch (Exception ex) - // { - // throw new DbCslaException("Error on PartInfoList.Get", ex); - // } - //} - public static PartInfoList GetByContentID(int contentID) - { - try - { - PartInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); - PartInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartInfoList.GetByContentID", ex); - } - } - public static PartInfoList GetByItemID(int itemID) - { - try - { - PartInfoList tmp = DataPortal.Fetch(new ItemIDCriteria(itemID)); - PartInfo.AddList(tmp); - tmp.AddEvents(); - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartInfoList.GetByItemID", ex); - } - } - private PartInfoList() - { /* require use of factory methods */ } - #endregion - #region Data Access Portal - private void DataPortal_Fetch() - { - this.RaiseListChangedEvents = false; - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getParts"; - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - IsReadOnly = false; - while (dr.Read()) this.Add(new PartInfo(dr)); - IsReadOnly = true; - } - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_Fetch", ex); - throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex); - } - this.RaiseListChangedEvents = true; - } - [Serializable()] - private class ContentIDCriteria - { - public ContentIDCriteria(int contentID) - { - _ContentID = contentID; - } - private int _ContentID; - public int ContentID - { - get { return _ContentID; } - set { _ContentID = value; } - } - } - private void DataPortal_Fetch(ContentIDCriteria criteria) - { - this.RaiseListChangedEvents = false; - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_FetchContentID", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPartsByContentID"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - IsReadOnly = false; - while (dr.Read()) this.Add(new PartInfo(dr)); - IsReadOnly = true; - } - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_FetchContentID", ex); - throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex); - } - this.RaiseListChangedEvents = true; - } - [Serializable()] - private class ItemIDCriteria - { - public ItemIDCriteria(int itemID) - { - _ItemID = itemID; - } - private int _ItemID; - public int ItemID - { - get { return _ItemID; } - set { _ItemID = value; } - } - } - private void DataPortal_Fetch(ItemIDCriteria criteria) - { - this.RaiseListChangedEvents = false; - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_FetchItemID", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPartsByItemID"; - cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - IsReadOnly = false; - while (dr.Read()) this.Add(new PartInfo(dr)); - IsReadOnly = true; - } - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_FetchItemID", ex); - throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex); - } - 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; } - /// - /// Called to get the properties of this type. Returns properties with certain - /// attributes. this restriction is not implemented here. - /// - /// - /// - public PropertyDescriptorCollection GetProperties(Attribute[] attributes) - { return GetProperties(); } - /// - /// Called to get the properties of this type. - /// - /// - 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++) - { - // Create a property descriptor for the item and add to the property descriptor collection - PartInfoListPropertyDescriptor pd = new PartInfoListPropertyDescriptor(this, i); - pds.Add(pd); - } - // return the property descriptor collection - return pds; - } - #endregion - } // Class - #region Property Descriptor - /// - /// Summary description for CollectionPropertyDescriptor. - /// - public partial class PartInfoListPropertyDescriptor : vlnListPropertyDescriptor - { - private PartInfo Item { get { return (PartInfo)_Item; } } - public PartInfoListPropertyDescriptor(PartInfoList collection, int index) : base(collection, index) { ;} - } - #endregion - #region Converter - internal class PartInfoListConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PartInfoList) - { - // Return department and department role separated by comma. - return ((PartInfoList)value).Items.Count.ToString() + " Parts"; - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// PartInfoList Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartInfoListConverter))] + public partial class PartInfoList : ReadOnlyListBase, ICustomTypeDescriptor, IDisposable + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Business Methods + internal new IList Items + { get { return base.Items; } } + public void AddEvents() + { + foreach (PartInfo tmp in this) + { + tmp.Changed += new PartInfoEvent(tmp_Changed); + } + } + void tmp_Changed(object sender) + { + for (int i = 0; i < Count; i++) + { + if (base[i] == sender) + this.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; } } + ~PartInfoList() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + foreach (PartInfo tmp in this) + { + tmp.Changed -= tmp_Changed; + } + } + #endregion + #region Factory Methods + public static PartInfoList _PartInfoList = null; + /// + /// Return a list of all PartInfo. + /// + public static PartInfoList Get() + { + try + { + if (_PartInfoList != null) + return _PartInfoList; + PartInfoList tmp = DataPortal.Fetch(); + PartInfo.AddList(tmp); + tmp.AddEvents(); + _PartInfoList = tmp; + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartInfoList.Get", ex); + } + } + /// + /// Reset the list of all PartInfo. + /// + public static void Reset() + { + _PartInfoList = null; + } + // CSLATODO: Add alternative gets - + //public static PartInfoList Get() + //{ + // try + // { + // return DataPortal.Fetch(new FilteredCriteria()); + // } + // catch (Exception ex) + // { + // throw new DbCslaException("Error on PartInfoList.Get", ex); + // } + //} + public static PartInfoList GetByContentID(int contentID) + { + try + { + PartInfoList tmp = DataPortal.Fetch(new ContentIDCriteria(contentID)); + PartInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartInfoList.GetByContentID", ex); + } + } + public static PartInfoList GetByItemID(int itemID) + { + try + { + PartInfoList tmp = DataPortal.Fetch(new ItemIDCriteria(itemID)); + PartInfo.AddList(tmp); + tmp.AddEvents(); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartInfoList.GetByItemID", ex); + } + } + private PartInfoList() + { /* require use of factory methods */ } + #endregion + #region Data Access Portal + private void DataPortal_Fetch() + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getParts"; + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PartInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ContentIDCriteria + { + public ContentIDCriteria(int contentID) + { + _ContentID = contentID; + } + private int _ContentID; + public int ContentID + { + get { return _ContentID; } + set { _ContentID = value; } + } + } + private void DataPortal_Fetch(ContentIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_FetchContentID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartsByContentID"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PartInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_FetchContentID", ex); + throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + [Serializable()] + private class ItemIDCriteria + { + public ItemIDCriteria(int itemID) + { + _ItemID = itemID; + } + private int _ItemID; + public int ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + } + private void DataPortal_Fetch(ItemIDCriteria criteria) + { + this.RaiseListChangedEvents = false; + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfoList.DataPortal_FetchItemID", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPartsByItemID"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) this.Add(new PartInfo(dr)); + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfoList.DataPortal_FetchItemID", ex); + throw new DbCslaException("PartInfoList.DataPortal_Fetch", ex); + } + 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; } + /// + /// Called to get the properties of this type. Returns properties with certain + /// attributes. this restriction is not implemented here. + /// + /// + /// + public PropertyDescriptorCollection GetProperties(Attribute[] attributes) + { return GetProperties(); } + /// + /// Called to get the properties of this type. + /// + /// + 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++) + { + // Create a property descriptor for the item and add to the property descriptor collection + PartInfoListPropertyDescriptor pd = new PartInfoListPropertyDescriptor(this, i); + pds.Add(pd); + } + // return the property descriptor collection + return pds; + } + #endregion + } // Class + #region Property Descriptor + /// + /// Summary description for CollectionPropertyDescriptor. + /// + public partial class PartInfoListPropertyDescriptor : vlnListPropertyDescriptor + { + private PartInfo Item { get { return (PartInfo)_Item; } } + public PartInfoListPropertyDescriptor(PartInfoList collection, int index) : base(collection, index) {; } + } + #endregion + #region Converter + internal class PartInfoListConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartInfoList) + { + // Return department and department role separated by comma. + return ((PartInfoList)value).Items.Count.ToString() + " Parts"; + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Pdf.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Pdf.cs index e82dd404..699521a0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Pdf.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Pdf.cs @@ -20,1141 +20,1126 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Pdf Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PdfConverter))] - public partial class Pdf : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshPdfs = new List(); - private void AddToRefreshList(List refreshPdfs) - { - if (IsDirty) - refreshPdfs.Add(this); - } - private void ClearRefreshList() - { - _RefreshPdfs = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshPdfs); - } - private void ProcessRefreshList() - { - foreach (Pdf tmp in _RefreshPdfs) - { - PdfInfo.Refresh(tmp); - if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Pdf pdf) - { - if (!_CacheList.Contains(pdf)) _CacheList.Add(pdf); // In AddToCache - } - protected static void RemoveFromCache(Pdf pdf) - { - while (_CacheList.Contains(pdf)) _CacheList.Remove(pdf); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Pdf(s) from temporary _CacheList to _CacheByPrimaryKey - { - Pdf tmp = _CacheList[0]; // Get the first Pdf - string pKey = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Pdf - } - } - protected static Pdf GetCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - ConvertListToDictionary(); - string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _DocID; - [System.ComponentModel.DataObjectField(true, true)] - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private Document _MyDocument; - [System.ComponentModel.DataObjectField(true, true)] - public Document MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); - return _MyDocument; - } - } - private int _DebugStatus; - /// - /// > 0 for Debug - /// - [System.ComponentModel.DataObjectField(true, true)] - public int DebugStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DebugStatus", true); - return _DebugStatus; - } - } - private int _TopRow; - [System.ComponentModel.DataObjectField(true, true)] - public int TopRow - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TopRow", true); - return _TopRow; - } - } - private int _PageLength; - [System.ComponentModel.DataObjectField(true, true)] - public int PageLength - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageLength", true); - return _PageLength; - } - } - private int _LeftMargin; - [System.ComponentModel.DataObjectField(true, true)] - public int LeftMargin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LeftMargin", true); - return _LeftMargin; - } - } - private int _PageWidth; - [System.ComponentModel.DataObjectField(true, true)] - public int PageWidth - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageWidth", true); - return _PageWidth; - } - } - private double _PageCount; - /// - /// Count of whole and partial pages - /// - public double PageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageCount", true); - return _PageCount; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PageCount", true); - if (_PageCount != value) - { - _PageCount = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocPdf; - public byte[] DocPdf - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocPdf", true); - return _DocPdf; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocPdf", true); - if (_DocPdf != value) - { - _DocPdf = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)); - } - // CSLATODO: Replace base Pdf.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Pdf - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Pdf.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Pdf - protected override object GetIdValue() - { - return MyPdfUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _PdfExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _PdfExtension.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, ""); - //AuthorizationRules.AllowRead(DebugStatus, ""); - //AuthorizationRules.AllowRead(TopRow, ""); - //AuthorizationRules.AllowRead(PageLength, ""); - //AuthorizationRules.AllowRead(LeftMargin, ""); - //AuthorizationRules.AllowRead(PageWidth, ""); - //AuthorizationRules.AllowRead(PageCount, ""); - //AuthorizationRules.AllowRead(DocPdf, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(PageCount, ""); - //AuthorizationRules.AllowWrite(DocPdf, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _PdfExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _PdfExtension.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; } } - private static int _PdfUnique = 0; - protected static int PdfUnique - { get { return ++_PdfUnique; } } - private int _MyPdfUnique = PdfUnique; - public int MyPdfUnique // Absolutely Unique ID - Editable - { get { return _MyPdfUnique; } } - protected Pdf() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Pdf() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString())) - { - List listPdf = _CacheByPrimaryKey[DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()]; // Get the list of items - while (listPdf.Contains(this)) listPdf.Remove(this); // Remove the item from the list - if (listPdf.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()); // remove the list - } - } - public static Pdf New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Pdf"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Pdf.New", ex); - } - } - public static Pdf New(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount) - { - Pdf tmp = Pdf.New(); - tmp._MyDocument = myDocument; - tmp._DebugStatus = debugStatus; - tmp._TopRow = topRow; - tmp._PageLength = pageLength; - tmp._LeftMargin = leftMargin; - tmp._PageWidth = pageWidth; - tmp.PageCount = pageCount; - return tmp; - } - public static Pdf New(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID) - { - Pdf tmp = Pdf.New(); - tmp._MyDocument = myDocument; - tmp._DebugStatus = debugStatus; - tmp._TopRow = topRow; - tmp._PageLength = pageLength; - tmp._LeftMargin = leftMargin; - tmp._PageWidth = pageWidth; - tmp.PageCount = pageCount; - tmp.DocPdf = docPdf; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Pdf MakePdf(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID) - { - Pdf tmp = Pdf.New(myDocument, debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount, docPdf, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Pdf New(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf) - { - Pdf tmp = Pdf.New(); - tmp._MyDocument = myDocument; - tmp._DebugStatus = debugStatus; - tmp._TopRow = topRow; - tmp._PageLength = pageLength; - tmp._LeftMargin = leftMargin; - tmp._PageWidth = pageWidth; - tmp.PageCount = pageCount; - tmp.DocPdf = docPdf; - return tmp; - } - public static Pdf MakePdf(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf) - { - Pdf tmp = Pdf.New(myDocument, debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount, docPdf); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Pdf Get(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Pdf"); - try - { - Pdf tmp = GetCachedByPrimaryKey(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Pdf - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Pdf.Get", ex); - } - } - public static Pdf Get(SafeDataReader dr) - { - if (dr.Read()) return new Pdf(dr); - return null; - } - internal Pdf(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Pdf"); - try - { - DataPortal.Delete(new PKCriteria(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Pdf.Delete", ex); - } - } - public override Pdf Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Pdf"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Pdf"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Pdf"); - try - { - BuildRefreshList(); - Pdf pdf = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(pdf);//Refresh the item in AllList - ProcessRefreshList(); - return pdf; - } - catch (Exception ex) - { - if (MSWordToPDF.DocReplace != null) // if creating an Approved export then ignore the error - { - _MyLog.WarnFormat("here"); - GC.Collect(); // memory garbage collection - return this; - } - else - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DocID; - public int DocID - { get { return _DocID; } } - private int _DebugStatus; - public int DebugStatus - { get { return _DebugStatus; } } - private int _TopRow; - public int TopRow - { get { return _TopRow; } } - private int _PageLength; - public int PageLength - { get { return _PageLength; } } - private int _LeftMargin; - public int LeftMargin - { get { return _LeftMargin; } } - private int _PageWidth; - public int PageWidth - { get { return _PageWidth; } } - public PKCriteria(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - _DocID = docID; - _DebugStatus = debugStatus; - _TopRow = topRow; - _PageLength = pageLength; - _LeftMargin = leftMargin; - _PageWidth = pageWidth; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// Pdf Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PdfConverter))] + public partial class Pdf : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshPdfs = new List(); + private void AddToRefreshList(List refreshPdfs) + { + if (IsDirty) + refreshPdfs.Add(this); + } + private void ClearRefreshList() + { + _RefreshPdfs = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshPdfs); + } + private void ProcessRefreshList() + { + foreach (Pdf tmp in _RefreshPdfs) + { + PdfInfo.Refresh(tmp); + if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Pdf pdf) + { + if (!_CacheList.Contains(pdf)) _CacheList.Add(pdf); // In AddToCache + } + protected static void RemoveFromCache(Pdf pdf) + { + while (_CacheList.Contains(pdf)) _CacheList.Remove(pdf); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Pdf(s) from temporary _CacheList to _CacheByPrimaryKey + { + Pdf tmp = _CacheList[0]; // Get the first Pdf + string pKey = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Pdf + } + } + protected static Pdf GetCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + ConvertListToDictionary(); + string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _DocID; + [System.ComponentModel.DataObjectField(true, true)] + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private Document _MyDocument; + [System.ComponentModel.DataObjectField(true, true)] + public Document MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); + return _MyDocument; + } + } + private int _DebugStatus; + /// + /// > 0 for Debug + /// + [System.ComponentModel.DataObjectField(true, true)] + public int DebugStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DebugStatus; + } + } + private int _TopRow; + [System.ComponentModel.DataObjectField(true, true)] + public int TopRow + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TopRow; + } + } + private int _PageLength; + [System.ComponentModel.DataObjectField(true, true)] + public int PageLength + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageLength; + } + } + private int _LeftMargin; + [System.ComponentModel.DataObjectField(true, true)] + public int LeftMargin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LeftMargin; + } + } + private int _PageWidth; + [System.ComponentModel.DataObjectField(true, true)] + public int PageWidth + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageWidth; + } + } + private double _PageCount; + /// + /// Count of whole and partial pages + /// + public double PageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageCount; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PageCount != value) + { + _PageCount = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocPdf; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocPdf != value) + { + _DocPdf = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)); + } + // CSLATODO: Replace base Pdf.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Pdf + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Pdf.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Pdf + protected override object GetIdValue() + { + return MyPdfUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _PdfExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _PdfExtension.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, ""); + //AuthorizationRules.AllowRead(DebugStatus, ""); + //AuthorizationRules.AllowRead(TopRow, ""); + //AuthorizationRules.AllowRead(PageLength, ""); + //AuthorizationRules.AllowRead(LeftMargin, ""); + //AuthorizationRules.AllowRead(PageWidth, ""); + //AuthorizationRules.AllowRead(PageCount, ""); + //AuthorizationRules.AllowRead(DocPdf, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(PageCount, ""); + //AuthorizationRules.AllowWrite(DocPdf, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _PdfExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _PdfExtension.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; } } + private static int _PdfUnique = 0; + protected static int PdfUnique + { get { return ++_PdfUnique; } } + private int _MyPdfUnique = PdfUnique; + public int MyPdfUnique // Absolutely Unique ID - Editable + { get { return _MyPdfUnique; } } + protected Pdf() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Pdf() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString())) + { + List listPdf = _CacheByPrimaryKey[DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()]; // Get the list of items + while (listPdf.Contains(this)) listPdf.Remove(this); // Remove the item from the list + if (listPdf.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()); // remove the list + } + } + public static Pdf New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Pdf"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Pdf.New", ex); + } + } + public static Pdf New(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount) + { + Pdf tmp = Pdf.New(); + tmp._MyDocument = myDocument; + tmp._DebugStatus = debugStatus; + tmp._TopRow = topRow; + tmp._PageLength = pageLength; + tmp._LeftMargin = leftMargin; + tmp._PageWidth = pageWidth; + tmp.PageCount = pageCount; + return tmp; + } + public static Pdf New(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID) + { + Pdf tmp = Pdf.New(); + tmp._MyDocument = myDocument; + tmp._DebugStatus = debugStatus; + tmp._TopRow = topRow; + tmp._PageLength = pageLength; + tmp._LeftMargin = leftMargin; + tmp._PageWidth = pageWidth; + tmp.PageCount = pageCount; + tmp.DocPdf = docPdf; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Pdf MakePdf(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID) + { + Pdf tmp = Pdf.New(myDocument, debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount, docPdf, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Pdf New(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf) + { + Pdf tmp = Pdf.New(); + tmp._MyDocument = myDocument; + tmp._DebugStatus = debugStatus; + tmp._TopRow = topRow; + tmp._PageLength = pageLength; + tmp._LeftMargin = leftMargin; + tmp._PageWidth = pageWidth; + tmp.PageCount = pageCount; + tmp.DocPdf = docPdf; + return tmp; + } + public static Pdf MakePdf(Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf) + { + Pdf tmp = Pdf.New(myDocument, debugStatus, topRow, pageLength, leftMargin, pageWidth, pageCount, docPdf); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Pdf Get(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Pdf"); + try + { + Pdf tmp = GetCachedByPrimaryKey(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Pdf + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Pdf.Get", ex); + } + } + public static Pdf Get(SafeDataReader dr) + { + if (dr.Read()) return new Pdf(dr); + return null; + } + internal Pdf(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Pdf"); + try + { + DataPortal.Delete(new PKCriteria(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Pdf.Delete", ex); + } + } + public override Pdf Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Pdf"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Pdf"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Pdf"); + try + { + BuildRefreshList(); + Pdf pdf = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(pdf);//Refresh the item in AllList + ProcessRefreshList(); + return pdf; + } + catch (Exception ex) + { + if (MSWordToPDF.DocReplace != null) // if creating an Approved export then ignore the error + { + _MyLog.WarnFormat("here"); + GC.Collect(); // memory garbage collection + return this; + } + else + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DocID; + public int DocID + { get { return _DocID; } } + private int _DebugStatus; + public int DebugStatus + { get { return _DebugStatus; } } + private int _TopRow; + public int TopRow + { get { return _TopRow; } } + private int _PageLength; + public int PageLength + { get { return _PageLength; } } + private int _LeftMargin; + public int LeftMargin + { get { return _LeftMargin; } } + private int _PageWidth; + public int PageWidth + { get { return _PageWidth; } } + public PKCriteria(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + _DocID = docID; + _DebugStatus = debugStatus; + _TopRow = topRow; + _PageLength = pageLength; + _LeftMargin = leftMargin; + _PageWidth = pageWidth; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _PdfExtension.DefaultDTS; - _UserID = _PdfExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.ReadData", GetHashCode()); - try - { - _DocID = dr.GetInt32("DocID"); - _DebugStatus = dr.GetInt32("DebugStatus"); - _TopRow = dr.GetInt32("TopRow"); - _PageLength = dr.GetInt32("PageLength"); - _LeftMargin = dr.GetInt32("LeftMargin"); - _PageWidth = dr.GetInt32("PageWidth"); - _PageCount = dr.GetDouble("PageCount"); - _DocPdf = (byte[])dr.GetValue("DocPdf"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Pdf.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPdf"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - cm.Parameters.AddWithValue("@DebugStatus", criteria.DebugStatus); - cm.Parameters.AddWithValue("@TopRow", criteria.TopRow); - cm.Parameters.AddWithValue("@PageLength", criteria.PageLength); - cm.Parameters.AddWithValue("@LeftMargin", criteria.LeftMargin); - cm.Parameters.AddWithValue("@PageWidth", criteria.PageWidth); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Pdf.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Pdf.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyDocument != null) _MyDocument.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPdf"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DocID", DocID); - cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus); - cm.Parameters.AddWithValue("@TopRow", _TopRow); - cm.Parameters.AddWithValue("@PageLength", _PageLength); - cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin); - cm.Parameters.AddWithValue("@PageWidth", _PageWidth); - cm.Parameters.AddWithValue("@PageCount", _PageCount); - cm.Parameters.AddWithValue("@DocPdf", _DocPdf); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Pdf.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPdf"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DocID", myDocument.DocID); - cm.Parameters.AddWithValue("@DebugStatus", debugStatus); - cm.Parameters.AddWithValue("@TopRow", topRow); - cm.Parameters.AddWithValue("@PageLength", pageLength); - cm.Parameters.AddWithValue("@LeftMargin", leftMargin); - cm.Parameters.AddWithValue("@PageWidth", pageWidth); - cm.Parameters.AddWithValue("@PageCount", pageCount); - cm.Parameters.AddWithValue("@DocPdf", docPdf); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.Add", ex); - throw new DbCslaException("Pdf.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Pdf.SQLUpdate", GetHashCode()); - try - { - if (_MyDocument != null) _MyDocument.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePdf"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@DocID", DocID); - cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus); - cm.Parameters.AddWithValue("@TopRow", _TopRow); - cm.Parameters.AddWithValue("@PageLength", _PageLength); - cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin); - cm.Parameters.AddWithValue("@PageWidth", _PageWidth); - cm.Parameters.AddWithValue("@PageCount", _PageCount); - cm.Parameters.AddWithValue("@DocPdf", _DocPdf); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Pdf.Add(cn, _MyDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID); - else - _LastChanged = Pdf.Update(cn, _DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePdf"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DocID", docID); - cm.Parameters.AddWithValue("@DebugStatus", debugStatus); - cm.Parameters.AddWithValue("@TopRow", topRow); - cm.Parameters.AddWithValue("@PageLength", pageLength); - cm.Parameters.AddWithValue("@LeftMargin", leftMargin); - cm.Parameters.AddWithValue("@PageWidth", pageWidth); - cm.Parameters.AddWithValue("@PageCount", pageCount); - cm.Parameters.AddWithValue("@DocPdf", docPdf); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.Update", ex); - throw new DbCslaException("Pdf.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePdf"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - cm.Parameters.AddWithValue("@DebugStatus", criteria.DebugStatus); - cm.Parameters.AddWithValue("@TopRow", criteria.TopRow); - cm.Parameters.AddWithValue("@PageLength", criteria.PageLength); - cm.Parameters.AddWithValue("@LeftMargin", criteria.LeftMargin); - cm.Parameters.AddWithValue("@PageWidth", criteria.PageWidth); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Pdf.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePdf"; - // Input PK Fields - cm.Parameters.AddWithValue("@DocID", docID); - cm.Parameters.AddWithValue("@DebugStatus", debugStatus); - cm.Parameters.AddWithValue("@TopRow", topRow); - cm.Parameters.AddWithValue("@PageLength", pageLength); - cm.Parameters.AddWithValue("@LeftMargin", leftMargin); - cm.Parameters.AddWithValue("@PageWidth", pageWidth); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.Remove", ex); - throw new DbCslaException("Pdf.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Pdf.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DocID; - private int _DebugStatus; - private int _TopRow; - private int _PageLength; - private int _LeftMargin; - private int _PageWidth; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - _DocID = docID; - _DebugStatus = debugStatus; - _TopRow = topRow; - _PageLength = pageLength; - _LeftMargin = leftMargin; - _PageWidth = pageWidth; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsPdf"; - cm.Parameters.AddWithValue("@DocID", _DocID); - cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus); - cm.Parameters.AddWithValue("@TopRow", _TopRow); - cm.Parameters.AddWithValue("@PageLength", _PageLength); - cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin); - cm.Parameters.AddWithValue("@PageWidth", _PageWidth); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Execute", ex); - throw new DbCslaException("Pdf.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - PdfExtension _PdfExtension = new PdfExtension(); - [Serializable()] - partial class PdfExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class PdfConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Pdf) - { - // Return the ToString value - return ((Pdf)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _PdfExtension.DefaultDTS; + _UserID = _PdfExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.ReadData", GetHashCode()); + try + { + _DocID = dr.GetInt32("DocID"); + _DebugStatus = dr.GetInt32("DebugStatus"); + _TopRow = dr.GetInt32("TopRow"); + _PageLength = dr.GetInt32("PageLength"); + _LeftMargin = dr.GetInt32("LeftMargin"); + _PageWidth = dr.GetInt32("PageWidth"); + _PageCount = dr.GetDouble("PageCount"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Pdf.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPdf"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + cm.Parameters.AddWithValue("@DebugStatus", criteria.DebugStatus); + cm.Parameters.AddWithValue("@TopRow", criteria.TopRow); + cm.Parameters.AddWithValue("@PageLength", criteria.PageLength); + cm.Parameters.AddWithValue("@LeftMargin", criteria.LeftMargin); + cm.Parameters.AddWithValue("@PageWidth", criteria.PageWidth); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Pdf.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Pdf.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyDocument != null) _MyDocument.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPdf"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DocID", DocID); + cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus); + cm.Parameters.AddWithValue("@TopRow", _TopRow); + cm.Parameters.AddWithValue("@PageLength", _PageLength); + cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin); + cm.Parameters.AddWithValue("@PageWidth", _PageWidth); + cm.Parameters.AddWithValue("@PageCount", _PageCount); + cm.Parameters.AddWithValue("@DocPdf", _DocPdf); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Pdf.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, Document myDocument, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPdf"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DocID", myDocument.DocID); + cm.Parameters.AddWithValue("@DebugStatus", debugStatus); + cm.Parameters.AddWithValue("@TopRow", topRow); + cm.Parameters.AddWithValue("@PageLength", pageLength); + cm.Parameters.AddWithValue("@LeftMargin", leftMargin); + cm.Parameters.AddWithValue("@PageWidth", pageWidth); + cm.Parameters.AddWithValue("@PageCount", pageCount); + cm.Parameters.AddWithValue("@DocPdf", docPdf); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.Add", ex); + throw new DbCslaException("Pdf.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Pdf.SQLUpdate", GetHashCode()); + try + { + if (_MyDocument != null) _MyDocument.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePdf"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@DocID", DocID); + cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus); + cm.Parameters.AddWithValue("@TopRow", _TopRow); + cm.Parameters.AddWithValue("@PageLength", _PageLength); + cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin); + cm.Parameters.AddWithValue("@PageWidth", _PageWidth); + cm.Parameters.AddWithValue("@PageCount", _PageCount); + cm.Parameters.AddWithValue("@DocPdf", _DocPdf); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Pdf.Add(cn, _MyDocument, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID); + else + _LastChanged = Pdf.Update(cn, _DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth, _PageCount, _DocPdf, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth, double pageCount, byte[] docPdf, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePdf"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DocID", docID); + cm.Parameters.AddWithValue("@DebugStatus", debugStatus); + cm.Parameters.AddWithValue("@TopRow", topRow); + cm.Parameters.AddWithValue("@PageLength", pageLength); + cm.Parameters.AddWithValue("@LeftMargin", leftMargin); + cm.Parameters.AddWithValue("@PageWidth", pageWidth); + cm.Parameters.AddWithValue("@PageCount", pageCount); + cm.Parameters.AddWithValue("@DocPdf", docPdf); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.Update", ex); + throw new DbCslaException("Pdf.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePdf"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + cm.Parameters.AddWithValue("@DebugStatus", criteria.DebugStatus); + cm.Parameters.AddWithValue("@TopRow", criteria.TopRow); + cm.Parameters.AddWithValue("@PageLength", criteria.PageLength); + cm.Parameters.AddWithValue("@LeftMargin", criteria.LeftMargin); + cm.Parameters.AddWithValue("@PageWidth", criteria.PageWidth); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Pdf.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePdf"; + // Input PK Fields + cm.Parameters.AddWithValue("@DocID", docID); + cm.Parameters.AddWithValue("@DebugStatus", debugStatus); + cm.Parameters.AddWithValue("@TopRow", topRow); + cm.Parameters.AddWithValue("@PageLength", pageLength); + cm.Parameters.AddWithValue("@LeftMargin", leftMargin); + cm.Parameters.AddWithValue("@PageWidth", pageWidth); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.Remove", ex); + throw new DbCslaException("Pdf.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Pdf.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DocID; + private int _DebugStatus; + private int _TopRow; + private int _PageLength; + private int _LeftMargin; + private int _PageWidth; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + _DocID = docID; + _DebugStatus = debugStatus; + _TopRow = topRow; + _PageLength = pageLength; + _LeftMargin = leftMargin; + _PageWidth = pageWidth; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsPdf"; + cm.Parameters.AddWithValue("@DocID", _DocID); + cm.Parameters.AddWithValue("@DebugStatus", _DebugStatus); + cm.Parameters.AddWithValue("@TopRow", _TopRow); + cm.Parameters.AddWithValue("@PageLength", _PageLength); + cm.Parameters.AddWithValue("@LeftMargin", _LeftMargin); + cm.Parameters.AddWithValue("@PageWidth", _PageWidth); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Execute", ex); + throw new DbCslaException("Pdf.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + PdfExtension _PdfExtension = new PdfExtension(); + [Serializable()] + partial class PdfExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class PdfConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Pdf) + { + // Return the ToString value + return ((Pdf)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PdfInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PdfInfo.cs index d9c233a8..67fb92d5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PdfInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PdfInfo.cs @@ -19,471 +19,460 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void PdfInfoEvent(object sender); - /// - /// PdfInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PdfInfoConverter))] - public partial class PdfInfo : ReadOnlyBase, IDisposable - { - public event PdfInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(PdfInfo pdfInfo) - { - if (!_CacheList.Contains(pdfInfo)) _CacheList.Add(pdfInfo); // In AddToCache - } - protected static void RemoveFromCache(PdfInfo pdfInfo) - { - while (_CacheList.Contains(pdfInfo)) _CacheList.Remove(pdfInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move PdfInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - PdfInfo tmp = _CacheList[0]; // Get the first PdfInfo - string pKey = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first PdfInfo - } - } - internal static void AddList(PdfInfoList lst) - { - foreach (PdfInfo item in lst) AddToCache(item); - } - protected static PdfInfo GetCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - ConvertListToDictionary(); - string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - // B2023-024 PROMS was using old cached PDF data when printing Word sections. - // Added this method to clear the PDF print cache for a specified section. - // This is called from RemovePDFFromCache() in PDFExt.cs - protected static void RemoveFromCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - ConvertListToDictionary(); - string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) - { - _CacheByPrimaryKey.Remove(key); - } - return; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Pdf _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private DocumentInfo _MyDocument; - [System.ComponentModel.DataObjectField(true, true)] - public DocumentInfo MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); - return _MyDocument; - } - } - private int _DebugStatus; - /// - /// > 0 for Debug - /// - [System.ComponentModel.DataObjectField(true, true)] - public int DebugStatus - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DebugStatus", true); - return _DebugStatus; - } - } - private int _TopRow; - [System.ComponentModel.DataObjectField(true, true)] - public int TopRow - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TopRow", true); - return _TopRow; - } - } - private int _PageLength; - [System.ComponentModel.DataObjectField(true, true)] - public int PageLength - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageLength", true); - return _PageLength; - } - } - private int _LeftMargin; - [System.ComponentModel.DataObjectField(true, true)] - public int LeftMargin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LeftMargin", true); - return _LeftMargin; - } - } - private int _PageWidth; - [System.ComponentModel.DataObjectField(true, true)] - public int PageWidth - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageWidth", true); - return _PageWidth; - } - } - private double _PageCount; - /// - /// Count of whole and partial pages - /// - public double PageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PageCount", true); - return _PageCount; - } - } - private byte[] _DocPdf; - public byte[] DocPdf - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocPdf", true); - return _DocPdf; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base PdfInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PdfInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check PdfInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PdfInfo - protected override object GetIdValue() - { - return MyPdfInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _PdfInfoUnique = 0; - private static int PdfInfoUnique - { get { return ++_PdfInfoUnique; } } - private int _MyPdfInfoUnique = PdfInfoUnique; - public int MyPdfInfoUnique // Absolutely Unique ID - Info - { get { return _MyPdfInfoUnique; } } - protected PdfInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~PdfInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString())) return; - List listPdfInfo = _CacheByPrimaryKey[DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()]; // Get the list of items - while (listPdfInfo.Contains(this)) listPdfInfo.Remove(this); // Remove the item from the list - if (listPdfInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()); // remove the list - } - public virtual Pdf Get() - { - return _Editable = Pdf.Get(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth); - } - public static void Refresh(Pdf tmp) - { - string key = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Pdf tmp) - { - _PageCount = tmp.PageCount; - _DocPdf = tmp.DocPdf; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PdfInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(Document myDocument, DocumentPdf tmp) - { - string key = myDocument.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocumentPdf tmp) - { - _PageCount = tmp.PageCount; - _DocPdf = tmp.DocPdf; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PdfInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static PdfInfo Get(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Pdf"); - try - { - PdfInfo tmp = GetCachedByPrimaryKey(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); - if (tmp.DocID > 0) AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up PdfInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PdfInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal PdfInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfo.Constructor", ex); - throw new DbCslaException("PdfInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DocID; - public int DocID - { get { return _DocID; } } - private int _DebugStatus; - public int DebugStatus - { get { return _DebugStatus; } } - private int _TopRow; - public int TopRow - { get { return _TopRow; } } - private int _PageLength; - public int PageLength - { get { return _PageLength; } } - private int _LeftMargin; - public int LeftMargin - { get { return _LeftMargin; } } - private int _PageWidth; - public int PageWidth - { get { return _PageWidth; } } - public PKCriteria(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) - { - _DocID = docID; - _DebugStatus = debugStatus; - _TopRow = topRow; - _PageLength = pageLength; - _LeftMargin = leftMargin; - _PageWidth = pageWidth; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfo.ReadData", GetHashCode()); - try - { - _DocID = dr.GetInt32("DocID"); - _DebugStatus = dr.GetInt32("DebugStatus"); - _TopRow = dr.GetInt32("TopRow"); - _PageLength = dr.GetInt32("PageLength"); - _LeftMargin = dr.GetInt32("LeftMargin"); - _PageWidth = dr.GetInt32("PageWidth"); - _PageCount = dr.GetDouble("PageCount"); - _DocPdf = (byte[])dr.GetValue("DocPdf"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PdfInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPdf"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - cm.Parameters.AddWithValue("@DebugStatus", criteria.DebugStatus); - cm.Parameters.AddWithValue("@TopRow", criteria.TopRow); - cm.Parameters.AddWithValue("@PageLength", criteria.PageLength); - cm.Parameters.AddWithValue("@LeftMargin", criteria.LeftMargin); - cm.Parameters.AddWithValue("@PageWidth", criteria.PageWidth); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PdfInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - PdfInfoExtension _PdfInfoExtension = new PdfInfoExtension(); - [Serializable()] - partial class PdfInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(PdfInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class PdfInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PdfInfo) - { - // Return the ToString value - return ((PdfInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void PdfInfoEvent(object sender); + /// + /// PdfInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PdfInfoConverter))] + public partial class PdfInfo : ReadOnlyBase, IDisposable + { + public event PdfInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PdfInfo pdfInfo) + { + if (!_CacheList.Contains(pdfInfo)) _CacheList.Add(pdfInfo); // In AddToCache + } + protected static void RemoveFromCache(PdfInfo pdfInfo) + { + while (_CacheList.Contains(pdfInfo)) _CacheList.Remove(pdfInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move PdfInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + PdfInfo tmp = _CacheList[0]; // Get the first PdfInfo + string pKey = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first PdfInfo + } + } + internal static void AddList(PdfInfoList lst) + { + foreach (PdfInfo item in lst) AddToCache(item); + } + protected static PdfInfo GetCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + ConvertListToDictionary(); + string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + // B2023-024 PROMS was using old cached PDF data when printing Word sections. + // Added this method to clear the PDF print cache for a specified section. + // This is called from RemovePDFFromCache() in PDFExt.cs + protected static void RemoveFromCachedByPrimaryKey(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + ConvertListToDictionary(); + string key = docID.ToString() + "_" + debugStatus.ToString() + "_" + topRow.ToString() + "_" + pageLength.ToString() + "_" + leftMargin.ToString() + "_" + pageWidth.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) + { + _CacheByPrimaryKey.Remove(key); + } + return; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Pdf _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private DocumentInfo _MyDocument; + [System.ComponentModel.DataObjectField(true, true)] + public DocumentInfo MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); + return _MyDocument; + } + } + private int _DebugStatus; + /// + /// > 0 for Debug + /// + [System.ComponentModel.DataObjectField(true, true)] + public int DebugStatus + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DebugStatus; + } + } + private int _TopRow; + [System.ComponentModel.DataObjectField(true, true)] + public int TopRow + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TopRow; + } + } + private int _PageLength; + [System.ComponentModel.DataObjectField(true, true)] + public int PageLength + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageLength; + } + } + private int _LeftMargin; + [System.ComponentModel.DataObjectField(true, true)] + public int LeftMargin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LeftMargin; + } + } + private int _PageWidth; + [System.ComponentModel.DataObjectField(true, true)] + public int PageWidth + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageWidth; + } + } + private double _PageCount; + /// + /// Count of whole and partial pages + /// + public double PageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PageCount; + } + } + private byte[] _DocPdf; + public byte[] DocPdf + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocPdf; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base PdfInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PdfInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check PdfInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PdfInfo + protected override object GetIdValue() + { + return MyPdfInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _PdfInfoUnique = 0; + private static int PdfInfoUnique + { get { return ++_PdfInfoUnique; } } + private int _MyPdfInfoUnique = PdfInfoUnique; + public int MyPdfInfoUnique // Absolutely Unique ID - Info + { get { return _MyPdfInfoUnique; } } + protected PdfInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~PdfInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString())) return; + List listPdfInfo = _CacheByPrimaryKey[DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()]; // Get the list of items + while (listPdfInfo.Contains(this)) listPdfInfo.Remove(this); // Remove the item from the list + if (listPdfInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(DocID.ToString() + "_" + DebugStatus.ToString() + "_" + TopRow.ToString() + "_" + PageLength.ToString() + "_" + LeftMargin.ToString() + "_" + PageWidth.ToString()); // remove the list + } + public virtual Pdf Get() + { + return _Editable = Pdf.Get(_DocID, _DebugStatus, _TopRow, _PageLength, _LeftMargin, _PageWidth); + } + public static void Refresh(Pdf tmp) + { + string key = tmp.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Pdf tmp) + { + _PageCount = tmp.PageCount; + _DocPdf = tmp.DocPdf; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PdfInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(Document myDocument, DocumentPdf tmp) + { + string key = myDocument.DocID.ToString() + "_" + tmp.DebugStatus.ToString() + "_" + tmp.TopRow.ToString() + "_" + tmp.PageLength.ToString() + "_" + tmp.LeftMargin.ToString() + "_" + tmp.PageWidth.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PdfInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocumentPdf tmp) + { + _PageCount = tmp.PageCount; + _DocPdf = tmp.DocPdf; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PdfInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static PdfInfo Get(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Pdf"); + try + { + PdfInfo tmp = GetCachedByPrimaryKey(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID, debugStatus, topRow, pageLength, leftMargin, pageWidth)); + if (tmp.DocID > 0) AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PdfInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PdfInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal PdfInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfo.Constructor", ex); + throw new DbCslaException("PdfInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DocID; + public int DocID + { get { return _DocID; } } + private int _DebugStatus; + public int DebugStatus + { get { return _DebugStatus; } } + private int _TopRow; + public int TopRow + { get { return _TopRow; } } + private int _PageLength; + public int PageLength + { get { return _PageLength; } } + private int _LeftMargin; + public int LeftMargin + { get { return _LeftMargin; } } + private int _PageWidth; + public int PageWidth + { get { return _PageWidth; } } + public PKCriteria(int docID, int debugStatus, int topRow, int pageLength, int leftMargin, int pageWidth) + { + _DocID = docID; + _DebugStatus = debugStatus; + _TopRow = topRow; + _PageLength = pageLength; + _LeftMargin = leftMargin; + _PageWidth = pageWidth; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfo.ReadData", GetHashCode()); + try + { + _DocID = dr.GetInt32("DocID"); + _DebugStatus = dr.GetInt32("DebugStatus"); + _TopRow = dr.GetInt32("TopRow"); + _PageLength = dr.GetInt32("PageLength"); + _LeftMargin = dr.GetInt32("LeftMargin"); + _PageWidth = dr.GetInt32("PageWidth"); + _PageCount = dr.GetDouble("PageCount"); + _DocPdf = (byte[])dr.GetValue("DocPdf"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PdfInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PdfInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPdf"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + cm.Parameters.AddWithValue("@DebugStatus", criteria.DebugStatus); + cm.Parameters.AddWithValue("@TopRow", criteria.TopRow); + cm.Parameters.AddWithValue("@PageLength", criteria.PageLength); + cm.Parameters.AddWithValue("@LeftMargin", criteria.LeftMargin); + cm.Parameters.AddWithValue("@PageWidth", criteria.PageWidth); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PdfInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PdfInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + PdfInfoExtension _PdfInfoExtension = new PdfInfoExtension(); + [Serializable()] + partial class PdfInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(PdfInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class PdfInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PdfInfo) + { + // Return the ToString value + return ((PdfInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs index 0af8072f..29c0ef05 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Permission.cs @@ -20,1248 +20,1226 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Permission Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PermissionConverter))] - public partial class Permission : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshPermissions = new List(); - private void AddToRefreshList(List refreshPermissions) - { - if (IsDirty) - refreshPermissions.Add(this); - } - private void ClearRefreshList() - { - _RefreshPermissions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshPermissions); - } - private void ProcessRefreshList() - { - foreach (Permission tmp in _RefreshPermissions) - { - PermissionInfo.Refresh(tmp); - if (tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Permission permission) - { - if (!_CacheList.Contains(permission)) _CacheList.Add(permission); // In AddToCache - } - protected static void RemoveFromCache(Permission permission) - { - while (_CacheList.Contains(permission)) _CacheList.Remove(permission); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Permission(s) from temporary _CacheList to _CacheByPrimaryKey - { - Permission tmp = _CacheList[0]; // Get the first Permission - string pKey = tmp.PID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Permission - } - } - protected static Permission GetCachedByPrimaryKey(int pid) - { - ConvertListToDictionary(); - string key = pid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextPID = -1; - public static int NextPID - { - get { return _nextPID--; } - } - private int _PID; - [System.ComponentModel.DataObjectField(true, true)] - public int PID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PID", true); - return _PID; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private Role _MyRole; - public Role MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); - return _MyRole; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRole", true); - if (_MyRole != value) - { - _MyRole = value; - _RID = value.RID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _PermLevel; - /// - /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments - /// - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermLevel", true); - return _PermLevel; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermLevel", true); - if (_PermLevel != value) - { - _PermLevel = value; - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private int _PermValue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermValue", true); - return _PermValue; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermValue", true); - if (_PermValue != value) - { - _PermValue = value; - PropertyHasChanged(); - } - } - } - private int _PermAD; - /// - /// 0 - Allow, 1 - Deny - /// - public int PermAD - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermAD", true); - return _PermAD; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermAD", true); - if (_PermAD != value) - { - _PermAD = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValidList(list)); - } - // CSLATODO: Replace base Permission.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Permission - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Permission.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Permission - protected override object GetIdValue() - { - return MyPermissionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRoleRequired, "MyRole"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _PermissionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _PermissionExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(Permission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(Permission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyRoleRequired(Permission target, Csla.Validation.RuleArgs e) - { - if (target._RID == 0 && target._MyRole == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(PID, ""); - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowRead(PermLevel, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowRead(PermValue, ""); - //AuthorizationRules.AllowRead(PermAD, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(RID, ""); - //AuthorizationRules.AllowWrite(PermLevel, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowWrite(PermValue, ""); - //AuthorizationRules.AllowWrite(PermAD, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _PermissionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _PermissionExtension.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; } } - private static int _PermissionUnique = 0; - protected static int PermissionUnique - { get { return ++_PermissionUnique; } } - private int _MyPermissionUnique = PermissionUnique; - public int MyPermissionUnique // Absolutely Unique ID - Editable - { get { return _MyPermissionUnique; } } - protected Permission() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Permission() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(PID.ToString())) - { - List listPermission = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items - while (listPermission.Contains(this)) listPermission.Remove(this); // Remove the item from the list - if (listPermission.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list - } - } - public static Permission New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Permission"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.New", ex); - } - } - public static Permission New(Role myRole, int permLevel, int versionType, int permValue) - { - Permission tmp = Permission.New(); - tmp.MyRole = myRole; - tmp.PermLevel = permLevel; - tmp.VersionType = versionType; - tmp.PermValue = permValue; - return tmp; - } - public static Permission New(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Permission tmp = Permission.New(); - tmp.MyRole = myRole; - tmp.PermLevel = permLevel; - tmp.VersionType = versionType; - tmp.PermValue = permValue; - tmp.PermAD = permAD; - tmp.StartDate = startDate; - tmp.EndDate = endDate; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, permAD, startDate, endDate, config, dts, usrID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Permission New(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) - { - Permission tmp = Permission.New(); - tmp.MyRole = myRole; - tmp.PermLevel = permLevel; - tmp.VersionType = versionType; - tmp.PermValue = permValue; - tmp.EndDate = endDate; - tmp.Config = config; - return tmp; - } - public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) - { - Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, endDate, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Permission Get(int pid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Permission"); - try - { - Permission tmp = GetCachedByPrimaryKey(pid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(pid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Permission - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.Get", ex); - } - } - public static Permission Get(SafeDataReader dr) - { - if (dr.Read()) return new Permission(dr); - return null; - } - internal Permission(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int pid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Permission"); - try - { - DataPortal.Delete(new PKCriteria(pid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.Delete", ex); - } - } - public override Permission Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Permission"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Permission"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Permission"); - try - { - BuildRefreshList(); - Permission permission = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(permission);//Refresh the item in AllList - ProcessRefreshList(); - return permission; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _PID; - public int PID - { get { return _PID; } } - public PKCriteria(int pid) - { - _PID = pid; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _PID = NextPID; - // Database Defaults - _PermAD = _PermissionExtension.DefaultPermAD; - _StartDate = _PermissionExtension.DefaultStartDate; - _DTS = _PermissionExtension.DefaultDTS; - _UsrID = _PermissionExtension.DefaultUsrID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.ReadData", GetHashCode()); - try - { - _PID = dr.GetInt32("PID"); - _RID = dr.GetInt32("RID"); - _PermLevel = dr.GetInt32("PermLevel"); - _VersionType = dr.GetInt32("VersionType"); - _PermValue = dr.GetInt32("PermValue"); - _PermAD = dr.GetInt32("PermAD"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPermission"; - cm.Parameters.AddWithValue("@PID", criteria.PID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRole != null) _MyRole.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPermission"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RID", RID); - cm.Parameters.AddWithValue("@PermLevel", _PermLevel); - cm.Parameters.AddWithValue("@VersionType", _VersionType); - cm.Parameters.AddWithValue("@PermValue", _PermValue); - cm.Parameters.AddWithValue("@PermAD", _PermAD); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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_PID = new SqlParameter("@newPID", SqlDbType.Int); - param_PID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_PID); - 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 - _PID = (int)cm.Parameters["@newPID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addPermission"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RID", myRole.RID); - cm.Parameters.AddWithValue("@PermLevel", permLevel); - cm.Parameters.AddWithValue("@VersionType", versionType); - cm.Parameters.AddWithValue("@PermValue", permValue); - cm.Parameters.AddWithValue("@PermAD", permAD); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - 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_PID = new SqlParameter("@newPID", SqlDbType.Int); - param_PID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_PID); - 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 - pid = (int)cm.Parameters["@newPID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Add", ex); - throw new DbCslaException("Permission.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Permission.SQLUpdate", GetHashCode()); - try - { - if (_MyRole != null) _MyRole.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePermission"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@PID", _PID); - cm.Parameters.AddWithValue("@RID", RID); - cm.Parameters.AddWithValue("@PermLevel", _PermLevel); - cm.Parameters.AddWithValue("@VersionType", _VersionType); - cm.Parameters.AddWithValue("@PermValue", _PermValue); - cm.Parameters.AddWithValue("@PermAD", _PermAD); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Permission.Add(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); - else - _LastChanged = Permission.Update(cn, ref _PID, _RID, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int pid, int rid, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updatePermission"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@PID", pid); - cm.Parameters.AddWithValue("@RID", rid); - cm.Parameters.AddWithValue("@PermLevel", permLevel); - cm.Parameters.AddWithValue("@VersionType", versionType); - cm.Parameters.AddWithValue("@PermValue", permValue); - cm.Parameters.AddWithValue("@PermAD", permAD); - cm.Parameters.AddWithValue("@StartDate", startDate); - cm.Parameters.AddWithValue("@EndDate", endDate); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Update", ex); - throw new DbCslaException("Permission.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_PID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePermission"; - cm.Parameters.AddWithValue("@PID", criteria.PID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int pid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deletePermission"; - // Input PK Fields - cm.Parameters.AddWithValue("@PID", pid); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Remove", ex); - throw new DbCslaException("Permission.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int pid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(pid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _PID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int pid) - { - _PID = pid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsPermission"; - cm.Parameters.AddWithValue("@PID", _PID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Execute", ex); - throw new DbCslaException("Permission.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - PermissionExtension _PermissionExtension = new PermissionExtension(); - [Serializable()] - partial class PermissionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultPermAD - { - get { return 0; } - } - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class PermissionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Permission) - { - // Return the ToString value - return ((Permission)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Permission Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PermissionConverter))] + public partial class Permission : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshPermissions = new List(); + private void AddToRefreshList(List refreshPermissions) + { + if (IsDirty) + refreshPermissions.Add(this); + } + private void ClearRefreshList() + { + _RefreshPermissions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshPermissions); + } + private void ProcessRefreshList() + { + foreach (Permission tmp in _RefreshPermissions) + { + PermissionInfo.Refresh(tmp); + if (tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Permission permission) + { + if (!_CacheList.Contains(permission)) _CacheList.Add(permission); // In AddToCache + } + protected static void RemoveFromCache(Permission permission) + { + while (_CacheList.Contains(permission)) _CacheList.Remove(permission); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Permission(s) from temporary _CacheList to _CacheByPrimaryKey + { + Permission tmp = _CacheList[0]; // Get the first Permission + string pKey = tmp.PID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Permission + } + } + protected static Permission GetCachedByPrimaryKey(int pid) + { + ConvertListToDictionary(); + string key = pid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextPID = -1; + public static int NextPID + { + get { return _nextPID--; } + } + private int _PID; + [System.ComponentModel.DataObjectField(true, true)] + public int PID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PID; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private Role _MyRole; + public Role MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); + return _MyRole; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRole != value) + { + _MyRole = value; + _RID = value.RID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _PermLevel; + /// + /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments + /// + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermLevel; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermLevel != value) + { + _PermLevel = value; + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private int _PermValue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermValue; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermValue != value) + { + _PermValue = value; + PropertyHasChanged(); + } + } + } + private int _PermAD; + /// + /// 0 - Allow, 1 - Deny + /// + public int PermAD + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermAD; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermAD != value) + { + _PermAD = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValidList(list)); + } + // CSLATODO: Replace base Permission.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Permission + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Permission.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Permission + protected override object GetIdValue() + { + return MyPermissionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRoleRequired, "MyRole"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _PermissionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _PermissionExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(Permission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(Permission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyRoleRequired(Permission target, Csla.Validation.RuleArgs e) + { + if (target._RID == 0 && target._MyRole == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(PID, ""); + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowRead(PermLevel, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowRead(PermValue, ""); + //AuthorizationRules.AllowRead(PermAD, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(RID, ""); + //AuthorizationRules.AllowWrite(PermLevel, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowWrite(PermValue, ""); + //AuthorizationRules.AllowWrite(PermAD, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _PermissionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _PermissionExtension.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; } } + private static int _PermissionUnique = 0; + protected static int PermissionUnique + { get { return ++_PermissionUnique; } } + private int _MyPermissionUnique = PermissionUnique; + public int MyPermissionUnique // Absolutely Unique ID - Editable + { get { return _MyPermissionUnique; } } + protected Permission() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Permission() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(PID.ToString())) + { + List listPermission = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items + while (listPermission.Contains(this)) listPermission.Remove(this); // Remove the item from the list + if (listPermission.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list + } + } + public static Permission New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Permission"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.New", ex); + } + } + public static Permission New(Role myRole, int permLevel, int versionType, int permValue) + { + Permission tmp = Permission.New(); + tmp.MyRole = myRole; + tmp.PermLevel = permLevel; + tmp.VersionType = versionType; + tmp.PermValue = permValue; + return tmp; + } + public static Permission New(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Permission tmp = Permission.New(); + tmp.MyRole = myRole; + tmp.PermLevel = permLevel; + tmp.VersionType = versionType; + tmp.PermValue = permValue; + tmp.PermAD = permAD; + tmp.StartDate = startDate; + tmp.EndDate = endDate; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, permAD, startDate, endDate, config, dts, usrID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Permission New(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) + { + Permission tmp = Permission.New(); + tmp.MyRole = myRole; + tmp.PermLevel = permLevel; + tmp.VersionType = versionType; + tmp.PermValue = permValue; + tmp.EndDate = endDate; + tmp.Config = config; + return tmp; + } + public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) + { + Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, endDate, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Permission Get(int pid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Permission"); + try + { + Permission tmp = GetCachedByPrimaryKey(pid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(pid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Permission + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.Get", ex); + } + } + public static Permission Get(SafeDataReader dr) + { + if (dr.Read()) return new Permission(dr); + return null; + } + internal Permission(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int pid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Permission"); + try + { + DataPortal.Delete(new PKCriteria(pid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.Delete", ex); + } + } + public override Permission Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Permission"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Permission"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Permission"); + try + { + BuildRefreshList(); + Permission permission = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(permission);//Refresh the item in AllList + ProcessRefreshList(); + return permission; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _PID; + public int PID + { get { return _PID; } } + public PKCriteria(int pid) + { + _PID = pid; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _PID = NextPID; + // Database Defaults + _PermAD = _PermissionExtension.DefaultPermAD; + _StartDate = _PermissionExtension.DefaultStartDate; + _DTS = _PermissionExtension.DefaultDTS; + _UsrID = _PermissionExtension.DefaultUsrID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.ReadData", GetHashCode()); + try + { + _PID = dr.GetInt32("PID"); + _RID = dr.GetInt32("RID"); + _PermLevel = dr.GetInt32("PermLevel"); + _VersionType = dr.GetInt32("VersionType"); + _PermValue = dr.GetInt32("PermValue"); + _PermAD = dr.GetInt32("PermAD"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermission"; + cm.Parameters.AddWithValue("@PID", criteria.PID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRole != null) _MyRole.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPermission"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RID", RID); + cm.Parameters.AddWithValue("@PermLevel", _PermLevel); + cm.Parameters.AddWithValue("@VersionType", _VersionType); + cm.Parameters.AddWithValue("@PermValue", _PermValue); + cm.Parameters.AddWithValue("@PermAD", _PermAD); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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_PID = new SqlParameter("@newPID", SqlDbType.Int); + param_PID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_PID); + 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 + _PID = (int)cm.Parameters["@newPID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addPermission"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RID", myRole.RID); + cm.Parameters.AddWithValue("@PermLevel", permLevel); + cm.Parameters.AddWithValue("@VersionType", versionType); + cm.Parameters.AddWithValue("@PermValue", permValue); + cm.Parameters.AddWithValue("@PermAD", permAD); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + 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_PID = new SqlParameter("@newPID", SqlDbType.Int); + param_PID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_PID); + 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 + pid = (int)cm.Parameters["@newPID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Add", ex); + throw new DbCslaException("Permission.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Permission.SQLUpdate", GetHashCode()); + try + { + if (_MyRole != null) _MyRole.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePermission"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@PID", _PID); + cm.Parameters.AddWithValue("@RID", RID); + cm.Parameters.AddWithValue("@PermLevel", _PermLevel); + cm.Parameters.AddWithValue("@VersionType", _VersionType); + cm.Parameters.AddWithValue("@PermValue", _PermValue); + cm.Parameters.AddWithValue("@PermAD", _PermAD); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Permission.Add(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); + else + _LastChanged = Permission.Update(cn, ref _PID, _RID, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int pid, int rid, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updatePermission"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@PID", pid); + cm.Parameters.AddWithValue("@RID", rid); + cm.Parameters.AddWithValue("@PermLevel", permLevel); + cm.Parameters.AddWithValue("@VersionType", versionType); + cm.Parameters.AddWithValue("@PermValue", permValue); + cm.Parameters.AddWithValue("@PermAD", permAD); + cm.Parameters.AddWithValue("@StartDate", startDate); + cm.Parameters.AddWithValue("@EndDate", endDate); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Update", ex); + throw new DbCslaException("Permission.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_PID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePermission"; + cm.Parameters.AddWithValue("@PID", criteria.PID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int pid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deletePermission"; + // Input PK Fields + cm.Parameters.AddWithValue("@PID", pid); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Remove", ex); + throw new DbCslaException("Permission.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int pid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(pid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _PID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int pid) + { + _PID = pid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsPermission"; + cm.Parameters.AddWithValue("@PID", _PID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Execute", ex); + throw new DbCslaException("Permission.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + PermissionExtension _PermissionExtension = new PermissionExtension(); + [Serializable()] + partial class PermissionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultPermAD + { + get { return 0; } + } + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class PermissionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Permission) + { + // Return the ToString value + return ((Permission)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs index 51c1b616..a6c7edf3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/PermissionInfo.cs @@ -19,461 +19,449 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void PermissionInfoEvent(object sender); - /// - /// PermissionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PermissionInfoConverter))] - public partial class PermissionInfo : ReadOnlyBase, IDisposable - { - public event PermissionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(PermissionInfo permissionInfo) - { - if (!_CacheList.Contains(permissionInfo)) _CacheList.Add(permissionInfo); // In AddToCache - } - protected static void RemoveFromCache(PermissionInfo permissionInfo) - { - while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move PermissionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - PermissionInfo tmp = _CacheList[0]; // Get the first PermissionInfo - string pKey = tmp.PID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first PermissionInfo - } - } - internal static void AddList(PermissionInfoList lst) - { - foreach (PermissionInfo item in lst) AddToCache(item); - } - protected static PermissionInfo GetCachedByPrimaryKey(int pid) - { - ConvertListToDictionary(); - string key = pid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Permission _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _PID; - [System.ComponentModel.DataObjectField(true, true)] - public int PID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PID", true); - return _PID; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private RoleInfo _MyRole; - public RoleInfo MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); - return _MyRole; - } - } - private int _PermLevel; - /// - /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments - /// - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermLevel", true); - return _PermLevel; - } - } - private int _VersionType; - /// - /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - } - private int _PermValue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermValue", true); - return _PermValue; - } - } - private int _PermAD; - /// - /// 0 - Allow, 1 - Deny - /// - public int PermAD - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermAD", true); - return _PermAD; - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - // CSLATODO: Replace base PermissionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PermissionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check PermissionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PermissionInfo - protected override object GetIdValue() - { - return MyPermissionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _PermissionInfoUnique = 0; - private static int PermissionInfoUnique - { get { return ++_PermissionInfoUnique; } } - private int _MyPermissionInfoUnique = PermissionInfoUnique; - public int MyPermissionInfoUnique // Absolutely Unique ID - Info - { get { return _MyPermissionInfoUnique; } } - protected PermissionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~PermissionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(PID.ToString())) return; - List listPermissionInfo = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items - while (listPermissionInfo.Contains(this)) listPermissionInfo.Remove(this); // Remove the item from the list - if (listPermissionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list - } - public virtual Permission Get() - { - return _Editable = Permission.Get(_PID); - } - public static void Refresh(Permission tmp) - { - string key = tmp.PID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Permission tmp) - { - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for new value - _PermLevel = tmp.PermLevel; - _VersionType = tmp.VersionType; - _PermValue = tmp.PermValue; - _PermAD = tmp.PermAD; - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _PermissionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RolePermission tmp) - { - string key = tmp.PID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RolePermission tmp) - { - _PermLevel = tmp.PermLevel; - _VersionType = tmp.VersionType; - _PermValue = tmp.PermValue; - _PermAD = tmp.PermAD; - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _PermissionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static PermissionInfo Get(int pid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Permission"); - try - { - PermissionInfo tmp = GetCachedByPrimaryKey(pid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(pid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up PermissionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PermissionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal PermissionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.Constructor", ex); - throw new DbCslaException("PermissionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _PID; - public int PID - { get { return _PID; } } - public PKCriteria(int pid) - { - _PID = pid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.ReadData", GetHashCode()); - try - { - _PID = dr.GetInt32("PID"); - _RID = dr.GetInt32("RID"); - _PermLevel = dr.GetInt32("PermLevel"); - _VersionType = dr.GetInt32("VersionType"); - _PermValue = dr.GetInt32("PermValue"); - _PermAD = dr.GetInt32("PermAD"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PermissionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPermission"; - cm.Parameters.AddWithValue("@PID", criteria.PID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PermissionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - PermissionInfoExtension _PermissionInfoExtension = new PermissionInfoExtension(); - [Serializable()] - partial class PermissionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(PermissionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class PermissionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PermissionInfo) - { - // Return the ToString value - return ((PermissionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void PermissionInfoEvent(object sender); + /// + /// PermissionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PermissionInfoConverter))] + public partial class PermissionInfo : ReadOnlyBase, IDisposable + { + public event PermissionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PermissionInfo permissionInfo) + { + if (!_CacheList.Contains(permissionInfo)) _CacheList.Add(permissionInfo); // In AddToCache + } + protected static void RemoveFromCache(PermissionInfo permissionInfo) + { + while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move PermissionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + PermissionInfo tmp = _CacheList[0]; // Get the first PermissionInfo + string pKey = tmp.PID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first PermissionInfo + } + } + internal static void AddList(PermissionInfoList lst) + { + foreach (PermissionInfo item in lst) AddToCache(item); + } + protected static PermissionInfo GetCachedByPrimaryKey(int pid) + { + ConvertListToDictionary(); + string key = pid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Permission _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _PID; + [System.ComponentModel.DataObjectField(true, true)] + public int PID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PID; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private RoleInfo _MyRole; + public RoleInfo MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); + return _MyRole; + } + } + private int _PermLevel; + /// + /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments + /// + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermLevel; + } + } + private int _VersionType; + /// + /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + } + private int _PermValue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermValue; + } + } + private int _PermAD; + /// + /// 0 - Allow, 1 - Deny + /// + public int PermAD + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermAD; + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + // CSLATODO: Replace base PermissionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PermissionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check PermissionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PermissionInfo + protected override object GetIdValue() + { + return MyPermissionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _PermissionInfoUnique = 0; + private static int PermissionInfoUnique + { get { return ++_PermissionInfoUnique; } } + private int _MyPermissionInfoUnique = PermissionInfoUnique; + public int MyPermissionInfoUnique // Absolutely Unique ID - Info + { get { return _MyPermissionInfoUnique; } } + protected PermissionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~PermissionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(PID.ToString())) return; + List listPermissionInfo = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items + while (listPermissionInfo.Contains(this)) listPermissionInfo.Remove(this); // Remove the item from the list + if (listPermissionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list + } + public virtual Permission Get() + { + return _Editable = Permission.Get(_PID); + } + public static void Refresh(Permission tmp) + { + string key = tmp.PID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Permission tmp) + { + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for new value + _PermLevel = tmp.PermLevel; + _VersionType = tmp.VersionType; + _PermValue = tmp.PermValue; + _PermAD = tmp.PermAD; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _PermissionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RolePermission tmp) + { + string key = tmp.PID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RolePermission tmp) + { + _PermLevel = tmp.PermLevel; + _VersionType = tmp.VersionType; + _PermValue = tmp.PermValue; + _PermAD = tmp.PermAD; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _PermissionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static PermissionInfo Get(int pid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Permission"); + try + { + PermissionInfo tmp = GetCachedByPrimaryKey(pid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(pid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PermissionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PermissionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal PermissionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.Constructor", ex); + throw new DbCslaException("PermissionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _PID; + public int PID + { get { return _PID; } } + public PKCriteria(int pid) + { + _PID = pid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.ReadData", GetHashCode()); + try + { + _PID = dr.GetInt32("PID"); + _RID = dr.GetInt32("RID"); + _PermLevel = dr.GetInt32("PermLevel"); + _VersionType = dr.GetInt32("VersionType"); + _PermValue = dr.GetInt32("PermValue"); + _PermAD = dr.GetInt32("PermAD"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PermissionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermission"; + cm.Parameters.AddWithValue("@PID", criteria.PID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PermissionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + PermissionInfoExtension _PermissionInfoExtension = new PermissionInfoExtension(); + [Serializable()] + partial class PermissionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(PermissionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class PermissionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PermissionInfo) + { + // Return the ToString value + return ((PermissionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs index 98d6cb38..5ffab757 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODb.cs @@ -20,1402 +20,1381 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODb Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbConverter))] - public partial class RODb : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshRODbs = new List(); - private List _RefreshRODbDROUsages = new List(); - private List _RefreshRODbROFsts = new List(); - private List _RefreshRODbROImages = new List(); - private List _RefreshRODbRoUsages = new List(); - private void AddToRefreshList(List refreshRODbs, List refreshRODbDROUsages, List refreshRODbROFsts, List refreshRODbROImages, List refreshRODbRoUsages) - { - if (IsDirty) - refreshRODbs.Add(this); - if (_RODbDROUsages != null && _RODbDROUsages.IsDirty) - { - foreach (RODbDROUsage tmp in _RODbDROUsages) - { - if (tmp.IsDirty) refreshRODbDROUsages.Add(tmp); - } - } - if (_RODbROFsts != null && _RODbROFsts.IsDirty) - { - foreach (RODbROFst tmp in _RODbROFsts) - { - if (tmp.IsDirty) refreshRODbROFsts.Add(tmp); - } - } - if (_RODbROImages != null && _RODbROImages.IsDirty) - { - foreach (RODbROImage tmp in _RODbROImages) - { - if (tmp.IsDirty) refreshRODbROImages.Add(tmp); - } - } - if (_RODbRoUsages != null && _RODbRoUsages.IsDirty) - { - foreach (RODbRoUsage tmp in _RODbRoUsages) - { - if (tmp.IsDirty) refreshRODbRoUsages.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshRODbs = new List(); - _RefreshRODbDROUsages = new List(); - _RefreshRODbROFsts = new List(); - _RefreshRODbROImages = new List(); - _RefreshRODbRoUsages = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshRODbs, _RefreshRODbDROUsages, _RefreshRODbROFsts, _RefreshRODbROImages, _RefreshRODbRoUsages); - } - private void ProcessRefreshList() - { - foreach (RODb tmp in _RefreshRODbs) - { - RODbInfo.Refresh(tmp); - } - foreach (RODbDROUsage tmp in _RefreshRODbDROUsages) - { - DROUsageInfo.Refresh(tmp); - } - foreach (RODbROFst tmp in _RefreshRODbROFsts) - { - ROFstInfo.Refresh(tmp); - } - foreach (RODbROImage tmp in _RefreshRODbROImages) - { - ROImageInfo.Refresh(tmp); - } - foreach (RODbRoUsage tmp in _RefreshRODbRoUsages) - { - RoUsageInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RODb rODb) - { - if (!_CacheList.Contains(rODb)) _CacheList.Add(rODb); // In AddToCache - } - protected static void RemoveFromCache(RODb rODb) - { - while (_CacheList.Contains(rODb)) _CacheList.Remove(rODb); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByFolderPath = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move RODb(s) from temporary _CacheList to _CacheByPrimaryKey - { - RODb tmp = _CacheList[0]; // Get the first RODb - string pKey = tmp.RODbID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByFolderPath[tmp.FolderPath.ToString()] = new List(); // Add new list for FolderPath - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByFolderPath[tmp.FolderPath.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first RODb - } - } - protected static RODb GetCachedByPrimaryKey(int rODbID) - { - ConvertListToDictionary(); - string key = rODbID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static RODb GetCachedByFolderPath(string folderPath) - { - ConvertListToDictionary(); - string key = folderPath.ToString(); - if (_CacheByFolderPath.ContainsKey(key)) return _CacheByFolderPath[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextRODbID = -1; - public static int NextRODbID - { - get { return _nextRODbID--; } - } - private int _RODbID; - [System.ComponentModel.DataObjectField(true, true)] - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - return _RODbID; - } - } - private string _ROName = string.Empty; - /// - /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion - /// - public string ROName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROName", true); - return _ROName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROName", true); - if (value == null) value = string.Empty; - if (_ROName != value) - { - _ROName = value; - PropertyHasChanged(); - } - } - } - private string _FolderPath = string.Empty; - /// - /// Path to the RO database - /// - public string FolderPath - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderPath", true); - return _FolderPath; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FolderPath", true); - if (value == null) value = string.Empty; - if (_FolderPath != value) - { - _FolderPath = value; - PropertyHasChanged(); - } - } - } - private string _DBConnectionString = string.Empty; - /// - /// Connection String - Default could just be the full path and name of the database - /// - public string DBConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBConnectionString", true); - return _DBConnectionString; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DBConnectionString", true); - if (value == null) value = string.Empty; - if (_DBConnectionString != value) - { - _DBConnectionString = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbDROUsageCount = 0; - /// - /// Count of RODbDROUsages for this RODb - /// - public int RODbDROUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbDROUsageCount", true); - return _RODbDROUsageCount; - } - } - private RODbDROUsages _RODbDROUsages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RODbDROUsagesConverter))] - public RODbDROUsages RODbDROUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbDROUsages", true); - if (_RODbDROUsageCount < 0 || (_RODbDROUsageCount > 0 && _RODbDROUsages == null)) - _RODbDROUsages = RODbDROUsages.GetByRODbID(RODbID); - if (_RODbDROUsageCount < 0 ) - _RODbDROUsageCount = _RODbDROUsages == null ? 0 : _RODbDROUsages.Count; - if (_RODbDROUsages == null) - _RODbDROUsages = RODbDROUsages.New(); - return _RODbDROUsages; - } - } - public void Reset_RODbDROUsages() - { - _RODbDROUsageCount = -1; - } - private int _RODbROFstCount = 0; - /// - /// Count of RODbROFsts for this RODb - /// - public int RODbROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFstCount", true); - return _RODbROFstCount; - } - } - private RODbROFsts _RODbROFsts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RODbROFstsConverter))] - public RODbROFsts RODbROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFsts", true); - if (_RODbROFstCount < 0 || (_RODbROFstCount > 0 && _RODbROFsts == null)) - _RODbROFsts = RODbROFsts.GetByRODbID(RODbID); - if (_RODbROFstCount < 0 ) - _RODbROFstCount = _RODbROFsts == null ? 0 : _RODbROFsts.Count; - if (_RODbROFsts == null) - _RODbROFsts = RODbROFsts.New(); - return _RODbROFsts; - } - } - public void Reset_RODbROFsts() - { - _RODbROFstCount = -1; - } - private int _RODbROImageCount = 0; - /// - /// Count of RODbROImages for this RODb - /// - public int RODbROImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImageCount", true); - return _RODbROImageCount; - } - } - private RODbROImages _RODbROImages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RODbROImagesConverter))] - public RODbROImages RODbROImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImages", true); - if (_RODbROImageCount < 0 || (_RODbROImageCount > 0 && _RODbROImages == null)) - _RODbROImages = RODbROImages.GetByRODbID(RODbID); - if (_RODbROImageCount < 0 ) - _RODbROImageCount = _RODbROImages == null ? 0 : _RODbROImages.Count; - if (_RODbROImages == null) - _RODbROImages = RODbROImages.New(); - return _RODbROImages; - } - } - public void Reset_RODbROImages() - { - _RODbROImageCount = -1; - } - private int _RODbRoUsageCount = 0; - /// - /// Count of RODbRoUsages for this RODb - /// - public int RODbRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsageCount", true); - return _RODbRoUsageCount; - } - } - private RODbRoUsages _RODbRoUsages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RODbRoUsagesConverter))] - public RODbRoUsages RODbRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsages", true); - if (_RODbRoUsageCount < 0 || (_RODbRoUsageCount > 0 && _RODbRoUsages == null)) - _RODbRoUsages = RODbRoUsages.GetByRODbID(RODbID); - if (_RODbRoUsageCount < 0 ) - _RODbRoUsageCount = _RODbRoUsages == null ? 0 : _RODbRoUsages.Count; - if (_RODbRoUsages == null) - _RODbRoUsages = RODbRoUsages.New(); - return _RODbRoUsages; - } - } - public void Reset_RODbRoUsages() - { - _RODbRoUsageCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_RODbDROUsages == null ? false : _RODbDROUsages.IsDirtyList(list)) || (_RODbROFsts == null ? false : _RODbROFsts.IsDirtyList(list)) || (_RODbROImages == null ? false : _RODbROImages.IsDirtyList(list)) || (_RODbRoUsages == null ? false : _RODbRoUsages.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RODbDROUsages == null ? true : _RODbDROUsages.IsValidList(list)) && (_RODbROFsts == null ? true : _RODbROFsts.IsValidList(list)) && (_RODbROImages == null ? true : _RODbROImages.IsValidList(list)) && (_RODbRoUsages == null ? true : _RODbRoUsages.IsValidList(list)); - } - // CSLATODO: Replace base RODb.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODb - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check RODb.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODb - protected override object GetIdValue() - { - return MyRODbUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_RODbRoUsages != null && (hasBrokenRules = _RODbRoUsages.HasBrokenRules) != null) return hasBrokenRules; - if (_RODbDROUsages != null && (hasBrokenRules = _RODbDROUsages.HasBrokenRules) != null) return hasBrokenRules; - if (_RODbROFsts != null && (hasBrokenRules = _RODbROFsts.HasBrokenRules) != null) return hasBrokenRules; - if (_RODbROImages != null && (hasBrokenRules = _RODbROImages.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROName", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FolderPath"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FolderPath", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "DBConnectionString"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("DBConnectionString", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _RODbExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _RODbExtension.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(RODbID, ""); - //AuthorizationRules.AllowRead(ROName, ""); - //AuthorizationRules.AllowRead(FolderPath, ""); - //AuthorizationRules.AllowRead(DBConnectionString, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ROName, ""); - //AuthorizationRules.AllowWrite(FolderPath, ""); - //AuthorizationRules.AllowWrite(DBConnectionString, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _RODbExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _RODbExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _RODbDROUsageCount; - usedByCount += _RODbROFstCount; - usedByCount += _RODbROImageCount; - usedByCount += _RODbRoUsageCount; - 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; } } - private static int _RODbUnique = 0; - protected static int RODbUnique - { get { return ++_RODbUnique; } } - private int _MyRODbUnique = RODbUnique; - public int MyRODbUnique // Absolutely Unique ID - Editable - { get { return _MyRODbUnique; } } - protected RODb() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~RODb() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) - { - List listRODb = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items - while (listRODb.Contains(this)) listRODb.Remove(this); // Remove the item from the list - if (listRODb.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByFolderPath.Keys) - if (_CacheByFolderPath[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listRODb = _CacheByFolderPath[myKey]; // Get the list of items - listRODb.Remove(this); // Remove the item from the list - if (listRODb.Count == 0) //If there are no items left in the list - _CacheByFolderPath.Remove(myKey); // remove the list - } - } - public static RODb New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RODb"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.New", ex); - } - } - public static RODb New(string rOName, string folderPath, string dBConnectionString) - { - RODb tmp = RODb.New(); - tmp.ROName = rOName; - tmp.FolderPath = folderPath; - tmp.DBConnectionString = dBConnectionString; - return tmp; - } - public static RODb New(string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID) - { - RODb tmp = RODb.New(); - tmp.ROName = rOName; - tmp.FolderPath = folderPath; - tmp.DBConnectionString = dBConnectionString; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID) - { - RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RODb New(string rOName, string folderPath, string dBConnectionString, string config) - { - RODb tmp = RODb.New(); - tmp.ROName = rOName; - tmp.FolderPath = folderPath; - tmp.DBConnectionString = dBConnectionString; - tmp.Config = config; - return tmp; - } - public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, string config) - { - RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RODb Get(int rODbID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a RODb"); - try - { - RODb tmp = GetCachedByPrimaryKey(rODbID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rODbID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RODb - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.Get", ex); - } - } - public static RODb GetByFolderPath(string folderPath) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a RODb"); - try - { - RODb tmp = GetCachedByFolderPath(folderPath); - if (tmp == null) - { - tmp = DataPortal.Fetch(new FolderPathCriteria(folderPath)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RODb - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.GetByFolderPath", ex); - } - } - public static RODb Get(SafeDataReader dr) - { - if (dr.Read()) return new RODb(dr); - return null; - } - internal RODb(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rODbID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RODb"); - try - { - DataPortal.Delete(new PKCriteria(rODbID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.Delete", ex); - } - } - public override RODb Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RODb"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RODb"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a RODb"); - try - { - BuildRefreshList(); - RODb rODb = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(rODb);//Refresh the item in AllList - ProcessRefreshList(); - return rODb; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - public PKCriteria(int rODbID) - { - _RODbID = rODbID; - } - } - [Serializable()] - private class FolderPathCriteria - { - private string _FolderPath; - public string FolderPath - { get { return _FolderPath; } } - public FolderPathCriteria(string folderPath) - { - _FolderPath = folderPath; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _RODbID = NextRODbID; - // Database Defaults - _DTS = _RODbExtension.DefaultDTS; - _UserID = _RODbExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.ReadData", GetHashCode()); - try - { - _RODbID = dr.GetInt32("RODbID"); - _ROName = dr.GetString("ROName"); - _FolderPath = dr.GetString("FolderPath"); - _DBConnectionString = dr.GetString("DBConnectionString"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbDROUsageCount = dr.GetInt32("DROUsageCount"); - _RODbROFstCount = dr.GetInt32("ROFstCount"); - _RODbROImageCount = dr.GetInt32("ROImageCount"); - _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRODb"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _RODbDROUsages = RODbDROUsages.Get(dr); - // load child objects - dr.NextResult(); - _RODbROFsts = RODbROFsts.Get(dr); - // load child objects - dr.NextResult(); - _RODbROImages = RODbROImages.Get(dr); - // load child objects - dr.NextResult(); - _RODbRoUsages = RODbRoUsages.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(FolderPathCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRODbByFolderPath"; - cm.Parameters.AddWithValue("@FolderPath", criteria.FolderPath); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRODb"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROName", _ROName); - cm.Parameters.AddWithValue("@FolderPath", _FolderPath); - cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); - 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_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); - param_RODbID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RODbID); - 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 - _RODbID = (int)cm.Parameters["@newRODbID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbDROUsages != null) _RODbDROUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRODb"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROName", rOName); - cm.Parameters.AddWithValue("@FolderPath", folderPath); - cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); - 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_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); - param_RODbID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RODbID); - 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 - rODbID = (int)cm.Parameters["@newRODbID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Add", ex); - throw new DbCslaException("RODb.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] RODb.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRODb"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RODbID", _RODbID); - cm.Parameters.AddWithValue("@ROName", _ROName); - cm.Parameters.AddWithValue("@FolderPath", _FolderPath); - cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbDROUsages != null) _RODbDROUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = RODb.Add(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID); - else - _LastChanged = RODb.Update(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbDROUsages != null) _RODbDROUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRODb"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", rODbID); - cm.Parameters.AddWithValue("@ROName", rOName); - cm.Parameters.AddWithValue("@FolderPath", folderPath); - cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Update", ex); - throw new DbCslaException("RODb.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_RODbID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRODb"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rODbID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRODb"; - // Input PK Fields - cm.Parameters.AddWithValue("@RODbID", rODbID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Remove", ex); - throw new DbCslaException("RODb.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rODbID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rODbID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _RODbID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rODbID) - { - _RODbID = rODbID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsRODb"; - cm.Parameters.AddWithValue("@RODbID", _RODbID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Execute", ex); - throw new DbCslaException("RODb.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - RODbExtension _RODbExtension = new RODbExtension(); - [Serializable()] - partial class RODbExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODb) - { - // Return the ToString value - return ((RODb)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODb Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbConverter))] + public partial class RODb : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRODbs = new List(); + private List _RefreshRODbDROUsages = new List(); + private List _RefreshRODbROFsts = new List(); + private List _RefreshRODbROImages = new List(); + private List _RefreshRODbRoUsages = new List(); + private void AddToRefreshList(List refreshRODbs, List refreshRODbDROUsages, List refreshRODbROFsts, List refreshRODbROImages, List refreshRODbRoUsages) + { + if (IsDirty) + refreshRODbs.Add(this); + if (_RODbDROUsages != null && _RODbDROUsages.IsDirty) + { + foreach (RODbDROUsage tmp in _RODbDROUsages) + { + if (tmp.IsDirty) refreshRODbDROUsages.Add(tmp); + } + } + if (_RODbROFsts != null && _RODbROFsts.IsDirty) + { + foreach (RODbROFst tmp in _RODbROFsts) + { + if (tmp.IsDirty) refreshRODbROFsts.Add(tmp); + } + } + if (_RODbROImages != null && _RODbROImages.IsDirty) + { + foreach (RODbROImage tmp in _RODbROImages) + { + if (tmp.IsDirty) refreshRODbROImages.Add(tmp); + } + } + if (_RODbRoUsages != null && _RODbRoUsages.IsDirty) + { + foreach (RODbRoUsage tmp in _RODbRoUsages) + { + if (tmp.IsDirty) refreshRODbRoUsages.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshRODbs = new List(); + _RefreshRODbDROUsages = new List(); + _RefreshRODbROFsts = new List(); + _RefreshRODbROImages = new List(); + _RefreshRODbRoUsages = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshRODbs, _RefreshRODbDROUsages, _RefreshRODbROFsts, _RefreshRODbROImages, _RefreshRODbRoUsages); + } + private void ProcessRefreshList() + { + foreach (RODb tmp in _RefreshRODbs) + { + RODbInfo.Refresh(tmp); + } + foreach (RODbDROUsage tmp in _RefreshRODbDROUsages) + { + DROUsageInfo.Refresh(tmp); + } + foreach (RODbROFst tmp in _RefreshRODbROFsts) + { + ROFstInfo.Refresh(tmp); + } + foreach (RODbROImage tmp in _RefreshRODbROImages) + { + ROImageInfo.Refresh(tmp); + } + foreach (RODbRoUsage tmp in _RefreshRODbRoUsages) + { + RoUsageInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RODb rODb) + { + if (!_CacheList.Contains(rODb)) _CacheList.Add(rODb); // In AddToCache + } + protected static void RemoveFromCache(RODb rODb) + { + while (_CacheList.Contains(rODb)) _CacheList.Remove(rODb); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByFolderPath = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move RODb(s) from temporary _CacheList to _CacheByPrimaryKey + { + RODb tmp = _CacheList[0]; // Get the first RODb + string pKey = tmp.RODbID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByFolderPath[tmp.FolderPath.ToString()] = new List(); // Add new list for FolderPath + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByFolderPath[tmp.FolderPath.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first RODb + } + } + protected static RODb GetCachedByPrimaryKey(int rODbID) + { + ConvertListToDictionary(); + string key = rODbID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static RODb GetCachedByFolderPath(string folderPath) + { + ConvertListToDictionary(); + string key = folderPath.ToString(); + if (_CacheByFolderPath.ContainsKey(key)) return _CacheByFolderPath[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextRODbID = -1; + public static int NextRODbID + { + get { return _nextRODbID--; } + } + private int _RODbID; + [System.ComponentModel.DataObjectField(true, true)] + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbID; + } + } + private string _ROName = string.Empty; + /// + /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion + /// + public string ROName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROName != value) + { + _ROName = value; + PropertyHasChanged(); + } + } + } + private string _FolderPath = string.Empty; + /// + /// Path to the RO database + /// + public string FolderPath + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderPath; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FolderPath != value) + { + _FolderPath = value; + PropertyHasChanged(); + } + } + } + private string _DBConnectionString = string.Empty; + /// + /// Connection String - Default could just be the full path and name of the database + /// + public string DBConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBConnectionString; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_DBConnectionString != value) + { + _DBConnectionString = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbDROUsageCount = 0; + /// + /// Count of RODbDROUsages for this RODb + /// + public int RODbDROUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbDROUsageCount; + } + } + private RODbDROUsages _RODbDROUsages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RODbDROUsagesConverter))] + public RODbDROUsages RODbDROUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbDROUsageCount < 0 || (_RODbDROUsageCount > 0 && _RODbDROUsages == null)) + _RODbDROUsages = RODbDROUsages.GetByRODbID(RODbID); + if (_RODbDROUsageCount < 0) + _RODbDROUsageCount = _RODbDROUsages == null ? 0 : _RODbDROUsages.Count; + if (_RODbDROUsages == null) + _RODbDROUsages = RODbDROUsages.New(); + return _RODbDROUsages; + } + } + public void Reset_RODbDROUsages() + { + _RODbDROUsageCount = -1; + } + private int _RODbROFstCount = 0; + /// + /// Count of RODbROFsts for this RODb + /// + public int RODbROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbROFstCount; + } + } + private RODbROFsts _RODbROFsts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RODbROFstsConverter))] + public RODbROFsts RODbROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROFstCount < 0 || (_RODbROFstCount > 0 && _RODbROFsts == null)) + _RODbROFsts = RODbROFsts.GetByRODbID(RODbID); + if (_RODbROFstCount < 0) + _RODbROFstCount = _RODbROFsts == null ? 0 : _RODbROFsts.Count; + if (_RODbROFsts == null) + _RODbROFsts = RODbROFsts.New(); + return _RODbROFsts; + } + } + public void Reset_RODbROFsts() + { + _RODbROFstCount = -1; + } + private int _RODbROImageCount = 0; + /// + /// Count of RODbROImages for this RODb + /// + public int RODbROImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbROImageCount; + } + } + private RODbROImages _RODbROImages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RODbROImagesConverter))] + public RODbROImages RODbROImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROImageCount < 0 || (_RODbROImageCount > 0 && _RODbROImages == null)) + _RODbROImages = RODbROImages.GetByRODbID(RODbID); + if (_RODbROImageCount < 0) + _RODbROImageCount = _RODbROImages == null ? 0 : _RODbROImages.Count; + if (_RODbROImages == null) + _RODbROImages = RODbROImages.New(); + return _RODbROImages; + } + } + public void Reset_RODbROImages() + { + _RODbROImageCount = -1; + } + private int _RODbRoUsageCount = 0; + /// + /// Count of RODbRoUsages for this RODb + /// + public int RODbRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbRoUsageCount; + } + } + private RODbRoUsages _RODbRoUsages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RODbRoUsagesConverter))] + public RODbRoUsages RODbRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbRoUsageCount < 0 || (_RODbRoUsageCount > 0 && _RODbRoUsages == null)) + _RODbRoUsages = RODbRoUsages.GetByRODbID(RODbID); + if (_RODbRoUsageCount < 0) + _RODbRoUsageCount = _RODbRoUsages == null ? 0 : _RODbRoUsages.Count; + if (_RODbRoUsages == null) + _RODbRoUsages = RODbRoUsages.New(); + return _RODbRoUsages; + } + } + public void Reset_RODbRoUsages() + { + _RODbRoUsageCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_RODbDROUsages == null ? false : _RODbDROUsages.IsDirtyList(list)) || (_RODbROFsts == null ? false : _RODbROFsts.IsDirtyList(list)) || (_RODbROImages == null ? false : _RODbROImages.IsDirtyList(list)) || (_RODbRoUsages == null ? false : _RODbRoUsages.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RODbDROUsages == null ? true : _RODbDROUsages.IsValidList(list)) && (_RODbROFsts == null ? true : _RODbROFsts.IsValidList(list)) && (_RODbROImages == null ? true : _RODbROImages.IsValidList(list)) && (_RODbRoUsages == null ? true : _RODbRoUsages.IsValidList(list)); + } + // CSLATODO: Replace base RODb.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODb + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check RODb.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODb + protected override object GetIdValue() + { + return MyRODbUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_RODbRoUsages != null && (hasBrokenRules = _RODbRoUsages.HasBrokenRules) != null) return hasBrokenRules; + if (_RODbDROUsages != null && (hasBrokenRules = _RODbDROUsages.HasBrokenRules) != null) return hasBrokenRules; + if (_RODbROFsts != null && (hasBrokenRules = _RODbROFsts.HasBrokenRules) != null) return hasBrokenRules; + if (_RODbROImages != null && (hasBrokenRules = _RODbROImages.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROName", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FolderPath"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FolderPath", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "DBConnectionString"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("DBConnectionString", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _RODbExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _RODbExtension.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(RODbID, ""); + //AuthorizationRules.AllowRead(ROName, ""); + //AuthorizationRules.AllowRead(FolderPath, ""); + //AuthorizationRules.AllowRead(DBConnectionString, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ROName, ""); + //AuthorizationRules.AllowWrite(FolderPath, ""); + //AuthorizationRules.AllowWrite(DBConnectionString, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _RODbExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _RODbExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _RODbDROUsageCount; + usedByCount += _RODbROFstCount; + usedByCount += _RODbROImageCount; + usedByCount += _RODbRoUsageCount; + 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; } } + private static int _RODbUnique = 0; + protected static int RODbUnique + { get { return ++_RODbUnique; } } + private int _MyRODbUnique = RODbUnique; + public int MyRODbUnique // Absolutely Unique ID - Editable + { get { return _MyRODbUnique; } } + protected RODb() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~RODb() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) + { + List listRODb = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items + while (listRODb.Contains(this)) listRODb.Remove(this); // Remove the item from the list + if (listRODb.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByFolderPath.Keys) + if (_CacheByFolderPath[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listRODb = _CacheByFolderPath[myKey]; // Get the list of items + listRODb.Remove(this); // Remove the item from the list + if (listRODb.Count == 0) //If there are no items left in the list + _CacheByFolderPath.Remove(myKey); // remove the list + } + } + public static RODb New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RODb"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.New", ex); + } + } + public static RODb New(string rOName, string folderPath, string dBConnectionString) + { + RODb tmp = RODb.New(); + tmp.ROName = rOName; + tmp.FolderPath = folderPath; + tmp.DBConnectionString = dBConnectionString; + return tmp; + } + public static RODb New(string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID) + { + RODb tmp = RODb.New(); + tmp.ROName = rOName; + tmp.FolderPath = folderPath; + tmp.DBConnectionString = dBConnectionString; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID) + { + RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RODb New(string rOName, string folderPath, string dBConnectionString, string config) + { + RODb tmp = RODb.New(); + tmp.ROName = rOName; + tmp.FolderPath = folderPath; + tmp.DBConnectionString = dBConnectionString; + tmp.Config = config; + return tmp; + } + public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, string config) + { + RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RODb Get(int rODbID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a RODb"); + try + { + RODb tmp = GetCachedByPrimaryKey(rODbID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rODbID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RODb + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.Get", ex); + } + } + public static RODb GetByFolderPath(string folderPath) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a RODb"); + try + { + RODb tmp = GetCachedByFolderPath(folderPath); + if (tmp == null) + { + tmp = DataPortal.Fetch(new FolderPathCriteria(folderPath)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RODb + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.GetByFolderPath", ex); + } + } + public static RODb Get(SafeDataReader dr) + { + if (dr.Read()) return new RODb(dr); + return null; + } + internal RODb(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rODbID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RODb"); + try + { + DataPortal.Delete(new PKCriteria(rODbID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.Delete", ex); + } + } + public override RODb Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RODb"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RODb"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a RODb"); + try + { + BuildRefreshList(); + RODb rODb = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(rODb);//Refresh the item in AllList + ProcessRefreshList(); + return rODb; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _RODbID; + public int RODbID + { get { return _RODbID; } } + public PKCriteria(int rODbID) + { + _RODbID = rODbID; + } + } + [Serializable()] + private class FolderPathCriteria + { + private string _FolderPath; + public string FolderPath + { get { return _FolderPath; } } + public FolderPathCriteria(string folderPath) + { + _FolderPath = folderPath; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _RODbID = NextRODbID; + // Database Defaults + _DTS = _RODbExtension.DefaultDTS; + _UserID = _RODbExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.ReadData", GetHashCode()); + try + { + _RODbID = dr.GetInt32("RODbID"); + _ROName = dr.GetString("ROName"); + _FolderPath = dr.GetString("FolderPath"); + _DBConnectionString = dr.GetString("DBConnectionString"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbDROUsageCount = dr.GetInt32("DROUsageCount"); + _RODbROFstCount = dr.GetInt32("ROFstCount"); + _RODbROImageCount = dr.GetInt32("ROImageCount"); + _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRODb"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _RODbDROUsages = RODbDROUsages.Get(dr); + // load child objects + dr.NextResult(); + _RODbROFsts = RODbROFsts.Get(dr); + // load child objects + dr.NextResult(); + _RODbROImages = RODbROImages.Get(dr); + // load child objects + dr.NextResult(); + _RODbRoUsages = RODbRoUsages.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(FolderPathCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRODbByFolderPath"; + cm.Parameters.AddWithValue("@FolderPath", criteria.FolderPath); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRODb"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROName", _ROName); + cm.Parameters.AddWithValue("@FolderPath", _FolderPath); + cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); + 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_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); + param_RODbID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RODbID); + 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 + _RODbID = (int)cm.Parameters["@newRODbID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_RODbRoUsages != null) _RODbRoUsages.Update(this); + if (_RODbDROUsages != null) _RODbDROUsages.Update(this); + if (_RODbROFsts != null) _RODbROFsts.Update(this); + if (_RODbROImages != null) _RODbROImages.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRODb"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROName", rOName); + cm.Parameters.AddWithValue("@FolderPath", folderPath); + cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); + 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_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); + param_RODbID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RODbID); + 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 + rODbID = (int)cm.Parameters["@newRODbID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Add", ex); + throw new DbCslaException("RODb.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] RODb.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRODb"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RODbID", _RODbID); + cm.Parameters.AddWithValue("@ROName", _ROName); + cm.Parameters.AddWithValue("@FolderPath", _FolderPath); + cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_RODbRoUsages != null) _RODbRoUsages.Update(this); + if (_RODbDROUsages != null) _RODbDROUsages.Update(this); + if (_RODbROFsts != null) _RODbROFsts.Update(this); + if (_RODbROImages != null) _RODbROImages.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = RODb.Add(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID); + else + _LastChanged = RODb.Update(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_RODbRoUsages != null) _RODbRoUsages.Update(this); + if (_RODbDROUsages != null) _RODbDROUsages.Update(this); + if (_RODbROFsts != null) _RODbROFsts.Update(this); + if (_RODbROImages != null) _RODbROImages.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRODb"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", rODbID); + cm.Parameters.AddWithValue("@ROName", rOName); + cm.Parameters.AddWithValue("@FolderPath", folderPath); + cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Update", ex); + throw new DbCslaException("RODb.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_RODbID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRODb"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rODbID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRODb"; + // Input PK Fields + cm.Parameters.AddWithValue("@RODbID", rODbID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Remove", ex); + throw new DbCslaException("RODb.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rODbID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rODbID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _RODbID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rODbID) + { + _RODbID = rODbID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsRODb"; + cm.Parameters.AddWithValue("@RODbID", _RODbID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Execute", ex); + throw new DbCslaException("RODb.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + RODbExtension _RODbExtension = new RODbExtension(); + [Serializable()] + partial class RODbExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODb) + { + // Return the ToString value + return ((RODb)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsage.cs index 910366af..a49b9cfe 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbDROUsage.cs @@ -20,579 +20,559 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODbDROUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbDROUsageConverter))] - public partial class RODbDROUsage : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _DROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int DROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DROUsageID", true); - if (_MyDROUsage != null) _DROUsageID = _MyDROUsage.DROUsageID; - return _DROUsageID; - } - } - private DROUsage _MyDROUsage; - [System.ComponentModel.DataObjectField(true, true)] - public DROUsage MyDROUsage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDROUsage", true); - if (_MyDROUsage == null && _DROUsageID != 0) _MyDROUsage = DROUsage.Get(_DROUsageID); - return _MyDROUsage; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private Document _MyDocument; - public Document MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); - return _MyDocument; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyDocument", true); - if (_MyDocument != value) - { - _MyDocument = value; - _DocID = value.DocID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Document_LibTitle = string.Empty; - public string Document_LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Document_LibTitle", true); - return _Document_LibTitle; - } - } - private byte[] _Document_DocContent; - /// - /// Actual content of a Word Document (RTF, DOC or XML Format) - /// - public byte[] Document_DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Document_DocContent", true); - return _Document_DocContent; - } - } - private string _Document_DocAscii = string.Empty; - /// - /// Used for searching - /// - public string Document_DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Document_DocAscii", true); - return _Document_DocAscii; - } - } - private string _Document_Config = string.Empty; - public string Document_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Document_Config", true); - return _Document_Config; - } - } - private DateTime _Document_DTS = new DateTime(); - public DateTime Document_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Document_DTS", true); - return _Document_DTS; - } - } - private string _Document_UserID = string.Empty; - public string Document_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Document_UserID", true); - return _Document_UserID; - } - } - private string _Document_FileExtension = string.Empty; - public string Document_FileExtension - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Document_FileExtension", true); - return _Document_FileExtension; - } - } - // CSLATODO: Check RODbDROUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbDROUsage - protected override object GetIdValue() - { - return MyRODbDROUsageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbDROUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbDROUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyDocumentRequired(RODbDROUsage target, Csla.Validation.RuleArgs e) - { - if (target._DocID == 0 && target._MyDocument == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _RODbDROUsageUnique = 0; - private static int RODbDROUsageUnique - { get { return ++_RODbDROUsageUnique; } } - private int _MyRODbDROUsageUnique = RODbDROUsageUnique; - public int MyRODbDROUsageUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbDROUsageUnique; } } - internal static RODbDROUsage New(string roid) - { - return new RODbDROUsage(roid); - } - internal static RODbDROUsage Get(SafeDataReader dr) - { - return new RODbDROUsage(dr); - } - public RODbDROUsage() - { - MarkAsChild(); - _DROUsageID = DROUsage.NextDROUsageID; - _DocID = _RODbDROUsageExtension.DefaultDocID; - _DTS = _RODbDROUsageExtension.DefaultDTS; - _UserID = _RODbDROUsageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RODbDROUsage(string roid) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _DROUsageID = DROUsage.NextDROUsageID; - _DocID = _RODbDROUsageExtension.DefaultDocID; - _DTS = _RODbDROUsageExtension.DefaultDTS; - _UserID = _RODbDROUsageExtension.DefaultUserID; - _ROID = roid; - ValidationRules.CheckRules(); - } - internal RODbDROUsage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RODbDROUsage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbDROUsage.FetchDR", GetHashCode()); - try - { - _DROUsageID = dr.GetInt32("DROUsageID"); - _DocID = dr.GetInt32("DocID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Document_LibTitle = dr.GetString("Document_LibTitle"); - _Document_DocContent = (byte[])dr.GetValue("Document_DocContent"); - _Document_DocAscii = dr.GetString("Document_DocAscii"); - _Document_Config = dr.GetString("Document_Config"); - _Document_DTS = dr.GetDateTime("Document_DTS"); - _Document_UserID = dr.GetString("Document_UserID"); - _Document_FileExtension = dr.GetString("Document_FileExtension"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbDROUsage.FetchDR", ex); - throw new DbCslaException("RODbDROUsage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(RODb myRODb) - { - // 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); - MarkOld(); - } - internal void Update(RODb myRODb) - { - // 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, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); - MarkOld(); - } - internal void DeleteSelf(RODb myRODb) - { - // 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"]; - DROUsage.Remove(cn, _DROUsageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RODbDROUsageExtension _RODbDROUsageExtension = new RODbDROUsageExtension(); - [Serializable()] - partial class RODbDROUsageExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbDROUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbDROUsage) - { - // Return the ToString value - return ((RODbDROUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODbDROUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbDROUsageConverter))] + public partial class RODbDROUsage : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _DROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int DROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDROUsage != null) _DROUsageID = _MyDROUsage.DROUsageID; + return _DROUsageID; + } + } + private DROUsage _MyDROUsage; + [System.ComponentModel.DataObjectField(true, true)] + public DROUsage MyDROUsage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDROUsage == null && _DROUsageID != 0) _MyDROUsage = DROUsage.Get(_DROUsageID); + return _MyDROUsage; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private Document _MyDocument; + public Document MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); + return _MyDocument; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyDocument != value) + { + _MyDocument = value; + _DocID = value.DocID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Document_LibTitle = string.Empty; + public string Document_LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Document_LibTitle; + } + } + private byte[] _Document_DocContent; + /// + /// Actual content of a Word Document (RTF, DOC or XML Format) + /// + public byte[] Document_DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Document_DocContent; + } + } + private string _Document_DocAscii = string.Empty; + /// + /// Used for searching + /// + public string Document_DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Document_DocAscii; + } + } + private string _Document_Config = string.Empty; + public string Document_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Document_Config; + } + } + private DateTime _Document_DTS = new DateTime(); + public DateTime Document_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Document_DTS; + } + } + private string _Document_UserID = string.Empty; + public string Document_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Document_UserID; + } + } + private string _Document_FileExtension = string.Empty; + public string Document_FileExtension + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Document_FileExtension; + } + } + // CSLATODO: Check RODbDROUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbDROUsage + protected override object GetIdValue() + { + return MyRODbDROUsageUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RODbDROUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbDROUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyDocumentRequired(RODbDROUsage target, Csla.Validation.RuleArgs e) + { + if (target._DocID == 0 && target._MyDocument == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _RODbDROUsageUnique = 0; + private static int RODbDROUsageUnique + { get { return ++_RODbDROUsageUnique; } } + private int _MyRODbDROUsageUnique = RODbDROUsageUnique; + public int MyRODbDROUsageUnique // Absolutely Unique ID - Editable FK + { get { return _MyRODbDROUsageUnique; } } + internal static RODbDROUsage New(string roid) + { + return new RODbDROUsage(roid); + } + internal static RODbDROUsage Get(SafeDataReader dr) + { + return new RODbDROUsage(dr); + } + public RODbDROUsage() + { + MarkAsChild(); + _DROUsageID = DROUsage.NextDROUsageID; + _DocID = _RODbDROUsageExtension.DefaultDocID; + _DTS = _RODbDROUsageExtension.DefaultDTS; + _UserID = _RODbDROUsageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RODbDROUsage(string roid) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _DROUsageID = DROUsage.NextDROUsageID; + _DocID = _RODbDROUsageExtension.DefaultDocID; + _DTS = _RODbDROUsageExtension.DefaultDTS; + _UserID = _RODbDROUsageExtension.DefaultUserID; + _ROID = roid; + ValidationRules.CheckRules(); + } + internal RODbDROUsage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RODbDROUsage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbDROUsage.FetchDR", GetHashCode()); + try + { + _DROUsageID = dr.GetInt32("DROUsageID"); + _DocID = dr.GetInt32("DocID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Document_LibTitle = dr.GetString("Document_LibTitle"); + _Document_DocContent = (byte[])dr.GetValue("Document_DocContent"); + _Document_DocAscii = dr.GetString("Document_DocAscii"); + _Document_Config = dr.GetString("Document_Config"); + _Document_DTS = dr.GetDateTime("Document_DTS"); + _Document_UserID = dr.GetString("Document_UserID"); + _Document_FileExtension = dr.GetString("Document_FileExtension"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbDROUsage.FetchDR", ex); + throw new DbCslaException("RODbDROUsage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(RODb myRODb) + { + // 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); + MarkOld(); + } + internal void Update(RODb myRODb) + { + // 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, _DocID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); + MarkOld(); + } + internal void DeleteSelf(RODb myRODb) + { + // 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"]; + DROUsage.Remove(cn, _DROUsageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RODbDROUsageExtension _RODbDROUsageExtension = new RODbDROUsageExtension(); + [Serializable()] + partial class RODbDROUsageExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbDROUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbDROUsage) + { + // Return the ToString value + return ((RODbDROUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfo.cs index bcda6de6..2f0fc1b8 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbInfo.cs @@ -19,526 +19,511 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void RODbInfoEvent(object sender); - /// - /// RODbInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbInfoConverter))] - public partial class RODbInfo : ReadOnlyBase, IDisposable - { - public event RODbInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RODbInfo rODbInfo) - { - if (!_CacheList.Contains(rODbInfo)) _CacheList.Add(rODbInfo); // In AddToCache - } - protected static void RemoveFromCache(RODbInfo rODbInfo) - { - while (_CacheList.Contains(rODbInfo)) _CacheList.Remove(rODbInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move RODbInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - RODbInfo tmp = _CacheList[0]; // Get the first RODbInfo - string pKey = tmp.RODbID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first RODbInfo - } - } - internal static void AddList(RODbInfoList lst) - { - foreach (RODbInfo item in lst) AddToCache(item); - } - protected static RODbInfo GetCachedByPrimaryKey(int rODbID) - { - ConvertListToDictionary(); - string key = rODbID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected RODb _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _RODbID; - [System.ComponentModel.DataObjectField(true, true)] - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - return _RODbID; - } - } - private string _ROName = string.Empty; - /// - /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion - /// - public string ROName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROName", true); - return _ROName; - } - } - private string _FolderPath = string.Empty; - /// - /// Path to the RO database - /// - public string FolderPath - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderPath", true); - return _FolderPath; - } - } - private string _DBConnectionString = string.Empty; - /// - /// Connection String - Default could just be the full path and name of the database - /// - public string DBConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBConnectionString", true); - return _DBConnectionString; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _RODbDROUsageCount = 0; - /// - /// Count of RODbDROUsages for this RODb - /// - public int RODbDROUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbDROUsageCount", true); - if (_RODbDROUsageCount < 0) - _RODbDROUsageCount = RODbDROUsages.Count; - return _RODbDROUsageCount; - } - } - private DROUsageInfoList _RODbDROUsages = null; - [TypeConverter(typeof(DROUsageInfoListConverter))] - public DROUsageInfoList RODbDROUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbDROUsages", true); - if (_RODbDROUsageCount < 0 || (_RODbDROUsageCount > 0 && _RODbDROUsages == null)) - _RODbDROUsages = DROUsageInfoList.GetByRODbID(_RODbID); - if (_RODbDROUsageCount < 0) - _RODbDROUsageCount = _RODbDROUsages.Count; - return _RODbDROUsages; - } - } - public void RefreshRODbDROUsages() - { - _RODbDROUsageCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) - foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) - tmp._RODbDROUsageCount = -1; // This will cause the data to be requeried - } - private int _RODbROFstCount = 0; - /// - /// Count of RODbROFsts for this RODb - /// - public int RODbROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFstCount", true); - if (_RODbROFstCount < 0) - _RODbROFstCount = RODbROFsts.Count; - return _RODbROFstCount; - } - } - private ROFstInfoList _RODbROFsts = null; - [TypeConverter(typeof(ROFstInfoListConverter))] - public ROFstInfoList RODbROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFsts", true); - if (_RODbROFstCount < 0 || (_RODbROFstCount > 0 && _RODbROFsts == null)) - _RODbROFsts = ROFstInfoList.GetByRODbID(_RODbID); - if (_RODbROFstCount < 0) - _RODbROFstCount = _RODbROFsts.Count; - return _RODbROFsts; - } - } - public void RefreshRODbROFsts() - { - _RODbROFstCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) - foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) - tmp._RODbROFstCount = -1; // This will cause the data to be requeried - } - private int _RODbROImageCount = 0; - /// - /// Count of RODbROImages for this RODb - /// - public int RODbROImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImageCount", true); - if (_RODbROImageCount < 0) - _RODbROImageCount = RODbROImages.Count; - return _RODbROImageCount; - } - } - private ROImageInfoList _RODbROImages = null; - [TypeConverter(typeof(ROImageInfoListConverter))] - public ROImageInfoList RODbROImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImages", true); - if (_RODbROImageCount < 0 || (_RODbROImageCount > 0 && _RODbROImages == null)) - _RODbROImages = ROImageInfoList.GetByRODbID(_RODbID); - if (_RODbROImageCount < 0) - _RODbROImageCount = _RODbROImages.Count; - return _RODbROImages; - } - } - public void RefreshRODbROImages() - { - _RODbROImageCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) - foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) - tmp._RODbROImageCount = -1; // This will cause the data to be requeried - } - private int _RODbRoUsageCount = 0; - /// - /// Count of RODbRoUsages for this RODb - /// - public int RODbRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsageCount", true); - if (_RODbRoUsageCount < 0) - _RODbRoUsageCount = RODbRoUsages.Count; - return _RODbRoUsageCount; - } - } - private RoUsageInfoList _RODbRoUsages = null; - [TypeConverter(typeof(RoUsageInfoListConverter))] - public RoUsageInfoList RODbRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsages", true); - if (_RODbRoUsageCount < 0 || (_RODbRoUsageCount > 0 && _RODbRoUsages == null)) - _RODbRoUsages = RoUsageInfoList.GetByRODbID(_RODbID); - if (_RODbRoUsageCount < 0) - _RODbRoUsageCount = _RODbRoUsages.Count; - return _RODbRoUsages; - } - } - public void RefreshRODbRoUsages() - { - _RODbRoUsageCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) - foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) - tmp._RODbRoUsageCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base RODbInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check RODbInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbInfo - protected override object GetIdValue() - { - return MyRODbInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _RODbInfoUnique = 0; - private static int RODbInfoUnique - { get { return ++_RODbInfoUnique; } } - private int _MyRODbInfoUnique = RODbInfoUnique; - public int MyRODbInfoUnique // Absolutely Unique ID - Info - { get { return _MyRODbInfoUnique; } } - protected RODbInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~RODbInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) return; - List listRODbInfo = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items - while (listRODbInfo.Contains(this)) listRODbInfo.Remove(this); // Remove the item from the list - if (listRODbInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list - } - public virtual RODb Get() - { - return _Editable = RODb.Get(_RODbID); - } - public static void Refresh(RODb tmp) - { - string key = tmp.RODbID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RODbInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODb tmp) - { - _ROName = tmp.ROName; - _FolderPath = tmp.FolderPath; - _DBConnectionString = tmp.DBConnectionString; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _RODbInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static RODbInfo Get(int rODbID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a RODb"); - try - { - RODbInfo tmp = GetCachedByPrimaryKey(rODbID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rODbID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RODbInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODbInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal RODbInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.Constructor", ex); - throw new DbCslaException("RODbInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - public PKCriteria(int rODbID) - { - _RODbID = rODbID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.ReadData", GetHashCode()); - try - { - _RODbID = dr.GetInt32("RODbID"); - _ROName = dr.GetString("ROName"); - _FolderPath = dr.GetString("FolderPath"); - _DBConnectionString = dr.GetString("DBConnectionString"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _RODbDROUsageCount = dr.GetInt32("DROUsageCount"); - _RODbROFstCount = dr.GetInt32("ROFstCount"); - _RODbROImageCount = dr.GetInt32("ROImageCount"); - _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODbInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRODb"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODbInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - RODbInfoExtension _RODbInfoExtension = new RODbInfoExtension(); - [Serializable()] - partial class RODbInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(RODbInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class RODbInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbInfo) - { - // Return the ToString value - return ((RODbInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void RODbInfoEvent(object sender); + /// + /// RODbInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbInfoConverter))] + public partial class RODbInfo : ReadOnlyBase, IDisposable + { + public event RODbInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RODbInfo rODbInfo) + { + if (!_CacheList.Contains(rODbInfo)) _CacheList.Add(rODbInfo); // In AddToCache + } + protected static void RemoveFromCache(RODbInfo rODbInfo) + { + while (_CacheList.Contains(rODbInfo)) _CacheList.Remove(rODbInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move RODbInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + RODbInfo tmp = _CacheList[0]; // Get the first RODbInfo + string pKey = tmp.RODbID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first RODbInfo + } + } + internal static void AddList(RODbInfoList lst) + { + foreach (RODbInfo item in lst) AddToCache(item); + } + protected static RODbInfo GetCachedByPrimaryKey(int rODbID) + { + ConvertListToDictionary(); + string key = rODbID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected RODb _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _RODbID; + [System.ComponentModel.DataObjectField(true, true)] + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbID; + } + } + private string _ROName = string.Empty; + /// + /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion + /// + public string ROName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROName; + } + } + private string _FolderPath = string.Empty; + /// + /// Path to the RO database + /// + public string FolderPath + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderPath; + } + } + private string _DBConnectionString = string.Empty; + /// + /// Connection String - Default could just be the full path and name of the database + /// + public string DBConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBConnectionString; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _RODbDROUsageCount = 0; + /// + /// Count of RODbDROUsages for this RODb + /// + public int RODbDROUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbDROUsageCount < 0) + _RODbDROUsageCount = RODbDROUsages.Count; + return _RODbDROUsageCount; + } + } + private DROUsageInfoList _RODbDROUsages = null; + [TypeConverter(typeof(DROUsageInfoListConverter))] + public DROUsageInfoList RODbDROUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbDROUsageCount < 0 || (_RODbDROUsageCount > 0 && _RODbDROUsages == null)) + _RODbDROUsages = DROUsageInfoList.GetByRODbID(_RODbID); + if (_RODbDROUsageCount < 0) + _RODbDROUsageCount = _RODbDROUsages.Count; + return _RODbDROUsages; + } + } + public void RefreshRODbDROUsages() + { + _RODbDROUsageCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) + foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) + tmp._RODbDROUsageCount = -1; // This will cause the data to be requeried + } + private int _RODbROFstCount = 0; + /// + /// Count of RODbROFsts for this RODb + /// + public int RODbROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROFstCount < 0) + _RODbROFstCount = RODbROFsts.Count; + return _RODbROFstCount; + } + } + private ROFstInfoList _RODbROFsts = null; + [TypeConverter(typeof(ROFstInfoListConverter))] + public ROFstInfoList RODbROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROFstCount < 0 || (_RODbROFstCount > 0 && _RODbROFsts == null)) + _RODbROFsts = ROFstInfoList.GetByRODbID(_RODbID); + if (_RODbROFstCount < 0) + _RODbROFstCount = _RODbROFsts.Count; + return _RODbROFsts; + } + } + public void RefreshRODbROFsts() + { + _RODbROFstCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) + foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) + tmp._RODbROFstCount = -1; // This will cause the data to be requeried + } + private int _RODbROImageCount = 0; + /// + /// Count of RODbROImages for this RODb + /// + public int RODbROImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROImageCount < 0) + _RODbROImageCount = RODbROImages.Count; + return _RODbROImageCount; + } + } + private ROImageInfoList _RODbROImages = null; + [TypeConverter(typeof(ROImageInfoListConverter))] + public ROImageInfoList RODbROImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROImageCount < 0 || (_RODbROImageCount > 0 && _RODbROImages == null)) + _RODbROImages = ROImageInfoList.GetByRODbID(_RODbID); + if (_RODbROImageCount < 0) + _RODbROImageCount = _RODbROImages.Count; + return _RODbROImages; + } + } + public void RefreshRODbROImages() + { + _RODbROImageCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) + foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) + tmp._RODbROImageCount = -1; // This will cause the data to be requeried + } + private int _RODbRoUsageCount = 0; + /// + /// Count of RODbRoUsages for this RODb + /// + public int RODbRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbRoUsageCount < 0) + _RODbRoUsageCount = RODbRoUsages.Count; + return _RODbRoUsageCount; + } + } + private RoUsageInfoList _RODbRoUsages = null; + [TypeConverter(typeof(RoUsageInfoListConverter))] + public RoUsageInfoList RODbRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbRoUsageCount < 0 || (_RODbRoUsageCount > 0 && _RODbRoUsages == null)) + _RODbRoUsages = RoUsageInfoList.GetByRODbID(_RODbID); + if (_RODbRoUsageCount < 0) + _RODbRoUsageCount = _RODbRoUsages.Count; + return _RODbRoUsages; + } + } + public void RefreshRODbRoUsages() + { + _RODbRoUsageCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) + foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) + tmp._RODbRoUsageCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base RODbInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check RODbInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbInfo + protected override object GetIdValue() + { + return MyRODbInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _RODbInfoUnique = 0; + private static int RODbInfoUnique + { get { return ++_RODbInfoUnique; } } + private int _MyRODbInfoUnique = RODbInfoUnique; + public int MyRODbInfoUnique // Absolutely Unique ID - Info + { get { return _MyRODbInfoUnique; } } + protected RODbInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~RODbInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) return; + List listRODbInfo = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items + while (listRODbInfo.Contains(this)) listRODbInfo.Remove(this); // Remove the item from the list + if (listRODbInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list + } + public virtual RODb Get() + { + return _Editable = RODb.Get(_RODbID); + } + public static void Refresh(RODb tmp) + { + string key = tmp.RODbID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RODbInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODb tmp) + { + _ROName = tmp.ROName; + _FolderPath = tmp.FolderPath; + _DBConnectionString = tmp.DBConnectionString; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RODbInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static RODbInfo Get(int rODbID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a RODb"); + try + { + RODbInfo tmp = GetCachedByPrimaryKey(rODbID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rODbID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RODbInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODbInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RODbInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.Constructor", ex); + throw new DbCslaException("RODbInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _RODbID; + public int RODbID + { get { return _RODbID; } } + public PKCriteria(int rODbID) + { + _RODbID = rODbID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.ReadData", GetHashCode()); + try + { + _RODbID = dr.GetInt32("RODbID"); + _ROName = dr.GetString("ROName"); + _FolderPath = dr.GetString("FolderPath"); + _DBConnectionString = dr.GetString("DBConnectionString"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _RODbDROUsageCount = dr.GetInt32("DROUsageCount"); + _RODbROFstCount = dr.GetInt32("ROFstCount"); + _RODbROImageCount = dr.GetInt32("ROImageCount"); + _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODbInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRODb"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODbInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RODbInfoExtension _RODbInfoExtension = new RODbInfoExtension(); + [Serializable()] + partial class RODbInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RODbInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RODbInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbInfo) + { + // Return the ToString value + return ((RODbInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.cs index 51d16011..5ab70e94 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROFst.cs @@ -20,426 +20,416 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODbROFst Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbROFstConverter))] - public partial class RODbROFst : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - } - private byte[] _ROLookup; - public byte[] ROLookup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROLookup", true); - return _ROLookup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROLookup", true); - if (_ROLookup != value) - { - _ROLookup = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check RODbROFst.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbROFst - protected override object GetIdValue() - { - return MyRODbROFstUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbROFst - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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(ROFstID, ""); - //AuthorizationRules.AllowRead(ROLookup, ""); - //AuthorizationRules.AllowWrite(ROLookup, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _RODbROFstUnique = 0; - private static int RODbROFstUnique - { get { return ++_RODbROFstUnique; } } - private int _MyRODbROFstUnique = RODbROFstUnique; - public int MyRODbROFstUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbROFstUnique; } } - internal static RODbROFst New(byte[] rOLookup) - { - return new RODbROFst(rOLookup); - } - internal static RODbROFst Get(SafeDataReader dr) - { - return new RODbROFst(dr); - } - public RODbROFst() - { - MarkAsChild(); - _ROFstID = ROFst.NextROFstID; - _DTS = _RODbROFstExtension.DefaultDTS; - _UserID = _RODbROFstExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RODbROFst(byte[] rOLookup) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _ROFstID = ROFst.NextROFstID; - _DTS = _RODbROFstExtension.DefaultDTS; - _UserID = _RODbROFstExtension.DefaultUserID; - _ROLookup = rOLookup; - ValidationRules.CheckRules(); - } - internal RODbROFst(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RODbROFst() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROFst.FetchDR", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _ROLookup = (byte[])dr.GetValue("ROLookup"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROFst.FetchDR", ex); - throw new DbCslaException("RODbROFst.Fetch", ex); - } - MarkOld(); - } - internal void Insert(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFst.Add(cn, ref _ROFstID, myRODb, _ROLookup, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFst.Update(cn, ref _ROFstID, myRODb.RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(RODb myRODb) - { - // 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"]; - ROFst.Remove(cn, _ROFstID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RODbROFstExtension _RODbROFstExtension = new RODbROFstExtension(); - [Serializable()] - partial class RODbROFstExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbROFstConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbROFst) - { - // Return the ToString value - return ((RODbROFst)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODbROFst Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbROFstConverter))] + public partial class RODbROFst : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + } + private byte[] _ROLookup; + public byte[] ROLookup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROLookup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ROLookup != value) + { + _ROLookup = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check RODbROFst.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbROFst + protected override object GetIdValue() + { + return MyRODbROFstUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RODbROFst.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbROFst + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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(ROFstID, ""); + //AuthorizationRules.AllowRead(ROLookup, ""); + //AuthorizationRules.AllowWrite(ROLookup, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _RODbROFstUnique = 0; + private static int RODbROFstUnique + { get { return ++_RODbROFstUnique; } } + private int _MyRODbROFstUnique = RODbROFstUnique; + public int MyRODbROFstUnique // Absolutely Unique ID - Editable FK + { get { return _MyRODbROFstUnique; } } + internal static RODbROFst New(byte[] rOLookup) + { + return new RODbROFst(rOLookup); + } + internal static RODbROFst Get(SafeDataReader dr) + { + return new RODbROFst(dr); + } + public RODbROFst() + { + MarkAsChild(); + _ROFstID = ROFst.NextROFstID; + _DTS = _RODbROFstExtension.DefaultDTS; + _UserID = _RODbROFstExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RODbROFst(byte[] rOLookup) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _ROFstID = ROFst.NextROFstID; + _DTS = _RODbROFstExtension.DefaultDTS; + _UserID = _RODbROFstExtension.DefaultUserID; + _ROLookup = rOLookup; + ValidationRules.CheckRules(); + } + internal RODbROFst(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RODbROFst() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROFst.FetchDR", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _ROLookup = (byte[])dr.GetValue("ROLookup"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROFst.FetchDR", ex); + throw new DbCslaException("RODbROFst.Fetch", ex); + } + MarkOld(); + } + internal void Insert(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFst.Add(cn, ref _ROFstID, myRODb, _ROLookup, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFst.Update(cn, ref _ROFstID, myRODb.RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(RODb myRODb) + { + // 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"]; + ROFst.Remove(cn, _ROFstID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RODbROFstExtension _RODbROFstExtension = new RODbROFstExtension(); + [Serializable()] + partial class RODbROFstExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbROFstConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbROFst) + { + // Return the ToString value + return ((RODbROFst)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.cs index ee686878..3107a9e3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbROImage.cs @@ -20,456 +20,444 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODbROImage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbROImageConverter))] - public partial class RODbROImage : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImage _MyROImage; - [System.ComponentModel.DataObjectField(true, true)] - public ROImage MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash - return _MyROImage; - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileName", true); - if (value == null) value = string.Empty; - if (_FileName != value) - { - _FileName = value; - PropertyHasChanged(); - } - } - } - private byte[] _Content; - public byte[] Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content", true); - return _Content; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Content", true); - if (_Content != value) - { - _Content = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check RODbROImage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbROImage - protected override object GetIdValue() - { - return MyRODbROImageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbROImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbROImage - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - 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(ImageID, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowRead(Content, ""); - //AuthorizationRules.AllowWrite(Content, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _RODbROImageUnique = 0; - private static int RODbROImageUnique - { get { return ++_RODbROImageUnique; } } - private int _MyRODbROImageUnique = RODbROImageUnique; - public int MyRODbROImageUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbROImageUnique; } } - internal static RODbROImage New(string fileName, byte[] content) - { - return new RODbROImage(fileName, content); - } - internal static RODbROImage Get(SafeDataReader dr) - { - return new RODbROImage(dr); - } - public RODbROImage() - { - MarkAsChild(); - _ImageID = ROImage.NextImageID; - _DTS = _RODbROImageExtension.DefaultDTS; - _UserID = _RODbROImageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RODbROImage(string fileName, byte[] content) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _ImageID = ROImage.NextImageID; - _DTS = _RODbROImageExtension.DefaultDTS; - _UserID = _RODbROImageExtension.DefaultUserID; - _FileName = fileName; - _Content = content; - ValidationRules.CheckRules(); - } - internal RODbROImage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RODbROImage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROImage.FetchDR", GetHashCode()); - try - { - _ImageID = dr.GetInt32("ImageID"); - _FileName = dr.GetString("FileName"); - _Content = (byte[])dr.GetValue("Content"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROImage.FetchDR", ex); - throw new DbCslaException("RODbROImage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROImage.Add(cn, ref _ImageID, myRODb, _FileName, _Content, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROImage.Update(cn, ref _ImageID, myRODb.RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(RODb myRODb) - { - // 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"]; - ROImage.Remove(cn, _ImageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RODbROImageExtension _RODbROImageExtension = new RODbROImageExtension(); - [Serializable()] - partial class RODbROImageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbROImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbROImage) - { - // Return the ToString value - return ((RODbROImage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODbROImage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbROImageConverter))] + public partial class RODbROImage : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImage _MyROImage; + [System.ComponentModel.DataObjectField(true, true)] + public ROImage MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash + return _MyROImage; + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileName != value) + { + _FileName = value; + PropertyHasChanged(); + } + } + } + private byte[] _Content; + public byte[] Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Content != value) + { + _Content = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check RODbROImage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbROImage + protected override object GetIdValue() + { + return MyRODbROImageUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RODbROImage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbROImage + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + 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(ImageID, ""); + //AuthorizationRules.AllowRead(FileName, ""); + //AuthorizationRules.AllowWrite(FileName, ""); + //AuthorizationRules.AllowRead(Content, ""); + //AuthorizationRules.AllowWrite(Content, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _RODbROImageUnique = 0; + private static int RODbROImageUnique + { get { return ++_RODbROImageUnique; } } + private int _MyRODbROImageUnique = RODbROImageUnique; + public int MyRODbROImageUnique // Absolutely Unique ID - Editable FK + { get { return _MyRODbROImageUnique; } } + internal static RODbROImage New(string fileName, byte[] content) + { + return new RODbROImage(fileName, content); + } + internal static RODbROImage Get(SafeDataReader dr) + { + return new RODbROImage(dr); + } + public RODbROImage() + { + MarkAsChild(); + _ImageID = ROImage.NextImageID; + _DTS = _RODbROImageExtension.DefaultDTS; + _UserID = _RODbROImageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RODbROImage(string fileName, byte[] content) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _ImageID = ROImage.NextImageID; + _DTS = _RODbROImageExtension.DefaultDTS; + _UserID = _RODbROImageExtension.DefaultUserID; + _FileName = fileName; + _Content = content; + ValidationRules.CheckRules(); + } + internal RODbROImage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RODbROImage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROImage.FetchDR", GetHashCode()); + try + { + _ImageID = dr.GetInt32("ImageID"); + _FileName = dr.GetString("FileName"); + _Content = (byte[])dr.GetValue("Content"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROImage.FetchDR", ex); + throw new DbCslaException("RODbROImage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROImage.Add(cn, ref _ImageID, myRODb, _FileName, _Content, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROImage.Update(cn, ref _ImageID, myRODb.RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(RODb myRODb) + { + // 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"]; + ROImage.Remove(cn, _ImageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RODbROImageExtension _RODbROImageExtension = new RODbROImageExtension(); + [Serializable()] + partial class RODbROImageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbROImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbROImage) + { + // Return the ToString value + return ((RODbROImage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.cs index a64597e9..3ea92f4e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RODbRoUsage.cs @@ -20,579 +20,559 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODbRoUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbRoUsageConverter))] - public partial class RODbRoUsage : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; - return _ROUsageID; - } - } - private RoUsage _MyRoUsage; - [System.ComponentModel.DataObjectField(true, true)] - public RoUsage MyRoUsage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRoUsage", true); - if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); - return _MyRoUsage; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - _ContentID = value.ContentID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - /// - /// Increased from 30 to 256 to support RTF symbols - /// - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // CSLATODO: Check RODbRoUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbRoUsage - protected override object GetIdValue() - { - return MyRODbRoUsageUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RODbRoUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbRoUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyContentRequired(RODbRoUsage target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(ROUsageID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _RODbRoUsageUnique = 0; - private static int RODbRoUsageUnique - { get { return ++_RODbRoUsageUnique; } } - private int _MyRODbRoUsageUnique = RODbRoUsageUnique; - public int MyRODbRoUsageUnique // Absolutely Unique ID - Editable FK - { get { return _MyRODbRoUsageUnique; } } - internal static RODbRoUsage New(string roid) - { - return new RODbRoUsage(roid); - } - internal static RODbRoUsage Get(SafeDataReader dr) - { - return new RODbRoUsage(dr); - } - public RODbRoUsage() - { - MarkAsChild(); - _ROUsageID = RoUsage.NextROUsageID; - _ContentID = _RODbRoUsageExtension.DefaultContentID; - _DTS = _RODbRoUsageExtension.DefaultDTS; - _UserID = _RODbRoUsageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RODbRoUsage(string roid) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _ROUsageID = RoUsage.NextROUsageID; - _ContentID = _RODbRoUsageExtension.DefaultContentID; - _DTS = _RODbRoUsageExtension.DefaultDTS; - _UserID = _RODbRoUsageExtension.DefaultUserID; - _ROID = roid; - ValidationRules.CheckRules(); - } - internal RODbRoUsage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RODbRoUsage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbRoUsage.FetchDR", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ContentID = dr.GetInt32("ContentID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbRoUsage.FetchDR", ex); - throw new DbCslaException("RODbRoUsage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, myRODb); - MarkOld(); - } - internal void Update(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); - MarkOld(); - } - internal void DeleteSelf(RODb myRODb) - { - // 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"]; - RoUsage.Remove(cn, _ROUsageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RODbRoUsageExtension _RODbRoUsageExtension = new RODbRoUsageExtension(); - [Serializable()] - partial class RODbRoUsageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultContentID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbRoUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbRoUsage) - { - // Return the ToString value - return ((RODbRoUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODbRoUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbRoUsageConverter))] + public partial class RODbRoUsage : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; + return _ROUsageID; + } + } + private RoUsage _MyRoUsage; + [System.ComponentModel.DataObjectField(true, true)] + public RoUsage MyRoUsage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); + return _MyRoUsage; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + _ContentID = value.ContentID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + /// + /// Increased from 30 to 256 to support RTF symbols + /// + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // CSLATODO: Check RODbRoUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbRoUsage + protected override object GetIdValue() + { + return MyRODbRoUsageUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RODbRoUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbRoUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyContentRequired(RODbRoUsage target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(ROUsageID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _RODbRoUsageUnique = 0; + private static int RODbRoUsageUnique + { get { return ++_RODbRoUsageUnique; } } + private int _MyRODbRoUsageUnique = RODbRoUsageUnique; + public int MyRODbRoUsageUnique // Absolutely Unique ID - Editable FK + { get { return _MyRODbRoUsageUnique; } } + internal static RODbRoUsage New(string roid) + { + return new RODbRoUsage(roid); + } + internal static RODbRoUsage Get(SafeDataReader dr) + { + return new RODbRoUsage(dr); + } + public RODbRoUsage() + { + MarkAsChild(); + _ROUsageID = RoUsage.NextROUsageID; + _ContentID = _RODbRoUsageExtension.DefaultContentID; + _DTS = _RODbRoUsageExtension.DefaultDTS; + _UserID = _RODbRoUsageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RODbRoUsage(string roid) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _ROUsageID = RoUsage.NextROUsageID; + _ContentID = _RODbRoUsageExtension.DefaultContentID; + _DTS = _RODbRoUsageExtension.DefaultDTS; + _UserID = _RODbRoUsageExtension.DefaultUserID; + _ROID = roid; + ValidationRules.CheckRules(); + } + internal RODbRoUsage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RODbRoUsage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbRoUsage.FetchDR", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ContentID = dr.GetInt32("ContentID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbRoUsage.FetchDR", ex); + throw new DbCslaException("RODbRoUsage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, myRODb); + MarkOld(); + } + internal void Update(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb.RODbID); + MarkOld(); + } + internal void DeleteSelf(RODb myRODb) + { + // 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"]; + RoUsage.Remove(cn, _ROUsageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RODbRoUsageExtension _RODbRoUsageExtension = new RODbRoUsageExtension(); + [Serializable()] + partial class RODbRoUsageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultContentID + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbRoUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbRoUsage) + { + // Return the ToString value + return ((RODbRoUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs index 6387278f..33713bf3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFst.cs @@ -20,1345 +20,1329 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROFst Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstConverter))] - public partial class ROFst : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshROFsts = new List(); - private List _RefreshROFstAssociations = new List(); - private List _RefreshROFstFigures = new List(); - private void AddToRefreshList(List refreshROFsts, List refreshROFstAssociations, List refreshROFstFigures) - { - if (IsDirty) - refreshROFsts.Add(this); - if (_ROFstAssociations != null && _ROFstAssociations.IsDirty) - { - foreach (ROFstAssociation tmp in _ROFstAssociations) - { - if (tmp.IsDirty) refreshROFstAssociations.Add(tmp); - } - } - if (_ROFstFigures != null && _ROFstFigures.IsDirty) - { - foreach (ROFstFigure tmp in _ROFstFigures) - { - if (tmp.IsDirty) refreshROFstFigures.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshROFsts = new List(); - _RefreshROFstAssociations = new List(); - _RefreshROFstFigures = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshROFsts, _RefreshROFstAssociations, _RefreshROFstFigures); - } - private void ProcessRefreshList() - { - foreach (ROFst tmp in _RefreshROFsts) - { - ROFstInfo.Refresh(tmp); - if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); - } - foreach (ROFstAssociation tmp in _RefreshROFstAssociations) - { - AssociationInfo.Refresh(tmp); - } - foreach (ROFstFigure tmp in _RefreshROFstFigures) - { - FigureInfo.Refresh(tmp); - } - ClearRefreshList(); - } + /// + /// ROFst Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstConverter))] + public partial class ROFst : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshROFsts = new List(); + private List _RefreshROFstAssociations = new List(); + private List _RefreshROFstFigures = new List(); + private void AddToRefreshList(List refreshROFsts, List refreshROFstAssociations, List refreshROFstFigures) + { + if (IsDirty) + refreshROFsts.Add(this); + if (_ROFstAssociations != null && _ROFstAssociations.IsDirty) + { + foreach (ROFstAssociation tmp in _ROFstAssociations) + { + if (tmp.IsDirty) refreshROFstAssociations.Add(tmp); + } + } + if (_ROFstFigures != null && _ROFstFigures.IsDirty) + { + foreach (ROFstFigure tmp in _ROFstFigures) + { + if (tmp.IsDirty) refreshROFstFigures.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshROFsts = new List(); + _RefreshROFstAssociations = new List(); + _RefreshROFstFigures = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshROFsts, _RefreshROFstAssociations, _RefreshROFstFigures); + } + private void ProcessRefreshList() + { + foreach (ROFst tmp in _RefreshROFsts) + { + ROFstInfo.Refresh(tmp); + if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); + } + foreach (ROFstAssociation tmp in _RefreshROFstAssociations) + { + AssociationInfo.Refresh(tmp); + } + foreach (ROFstFigure tmp in _RefreshROFstFigures) + { + FigureInfo.Refresh(tmp); + } + ClearRefreshList(); + } - #endregion + #endregion - #region Collection + #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROFst rOFst) - { - if (!_CacheList.Contains(rOFst)) - { - rOFst.ROLookup = null; // B2022-026 RO Memory reduction - _CacheList.Add(rOFst); // In AddToCache - } - - } - protected static void RemoveFromCache(ROFst rOFst) - { - while (_CacheList.Contains(rOFst)) _CacheList.Remove(rOFst); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByRODbID_DTS = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ROFst(s) from temporary _CacheList to _CacheByPrimaryKey - { - ROFst tmp = _CacheList[0]; // Get the first ROFst - string pKey = tmp.ROFstID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByRODbID_DTS[tmp.RODbID.ToString() + "_" + tmp.DTS.ToString()] = new List(); // Add new list for RODbID_DTS - } - tmp.ROLookup = null; // B2022-026 RO Memory reduction - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByRODbID_DTS[tmp.RODbID.ToString() + "_" + tmp.DTS.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first ROFst - } - } - protected static ROFst GetCachedByPrimaryKey(int rOFstID) - { - ConvertListToDictionary(); - string key = rOFstID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static ROFst GetCachedByRODbID_DTS(int rODbID, DateTime dts) - { - ConvertListToDictionary(); - string key = rODbID.ToString() + "_" + dts.ToString(); - if (_CacheByRODbID_DTS.ContainsKey(key)) return _CacheByRODbID_DTS[key][0]; - return null; - } + private static List _CacheList = new List(); + protected static void AddToCache(ROFst rOFst) + { + if (!_CacheList.Contains(rOFst)) + { + rOFst.ROLookup = null; // B2022-026 RO Memory reduction + _CacheList.Add(rOFst); // In AddToCache + } - #endregion + } + protected static void RemoveFromCache(ROFst rOFst) + { + while (_CacheList.Contains(rOFst)) _CacheList.Remove(rOFst); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByRODbID_DTS = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ROFst(s) from temporary _CacheList to _CacheByPrimaryKey + { + ROFst tmp = _CacheList[0]; // Get the first ROFst + string pKey = tmp.ROFstID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByRODbID_DTS[tmp.RODbID.ToString() + "_" + tmp.DTS.ToString()] = new List(); // Add new list for RODbID_DTS + } + tmp.ROLookup = null; // B2022-026 RO Memory reduction + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByRODbID_DTS[tmp.RODbID.ToString() + "_" + tmp.DTS.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first ROFst + } + } + protected static ROFst GetCachedByPrimaryKey(int rOFstID) + { + ConvertListToDictionary(); + string key = rOFstID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static ROFst GetCachedByRODbID_DTS(int rODbID, DateTime dts) + { + ConvertListToDictionary(); + string key = rODbID.ToString() + "_" + dts.ToString(); + if (_CacheByRODbID_DTS.ContainsKey(key)) return _CacheByRODbID_DTS[key][0]; + return null; + } - #region Business Methods + #endregion - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextROFstID = -1; - public static int NextROFstID - { - get { return _nextROFstID--; } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - return _ROFstID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - _RODbID = value.RODbID;// Update underlying data field - PropertyHasChanged(); - } - } - } + #region Business Methods - private byte[] _ROLookup; + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextROFstID = -1; + public static int NextROFstID + { + get { return _nextROFstID--; } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + _RODbID = value.RODbID;// Update underlying data field + PropertyHasChanged(); + } + } + } - public byte[] ROLookup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROLookup", true); - return null; // B2022-026 RO Memory reduction - //if (_ROLookup == null) - //{ - // _ROLookup = ROFSTLookup.GetRofstLookupBytes(_ROFstID); - //} - //return _ROLookup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROLookup", true); - if (_ROLookup != value) - { - _ROLookup = value; - PropertyHasChanged(); - } - } - } + private byte[] _ROLookup; - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ROFstAssociationCount = 0; - /// - /// Count of ROFstAssociations for this ROFst - /// - public int ROFstAssociationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstAssociationCount", true); - return _ROFstAssociationCount; - } - } - private ROFstAssociations _ROFstAssociations = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ROFstAssociationsConverter))] - public ROFstAssociations ROFstAssociations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstAssociations", true); - if (_ROFstAssociationCount < 0 || (_ROFstAssociationCount > 0 && _ROFstAssociations == null)) - _ROFstAssociations = ROFstAssociations.GetByROFstID(ROFstID); - if (_ROFstAssociationCount < 0 ) - _ROFstAssociationCount = _ROFstAssociations == null ? 0 : _ROFstAssociations.Count; - if (_ROFstAssociations == null) - _ROFstAssociations = ROFstAssociations.New(); - return _ROFstAssociations; - } - } - public void Reset_ROFstAssociations() - { - _ROFstAssociationCount = -1; - } - private int _ROFstFigureCount = 0; - /// - /// Count of ROFstFigures for this ROFst - /// - public int ROFstFigureCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstFigureCount", true); - return _ROFstFigureCount; - } - } - private ROFstFigures _ROFstFigures = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ROFstFiguresConverter))] - public ROFstFigures ROFstFigures - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstFigures", true); - if (_ROFstFigureCount < 0 || (_ROFstFigureCount > 0 && _ROFstFigures == null)) - _ROFstFigures = ROFstFigures.GetByROFstID(ROFstID); - if (_ROFstFigureCount < 0 ) - _ROFstFigureCount = _ROFstFigures == null ? 0 : _ROFstFigures.Count; - if (_ROFstFigures == null) - _ROFstFigures = ROFstFigures.New(); - return _ROFstFigures; - } - } - public void Reset_ROFstFigures() - { - _ROFstFigureCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_ROFstAssociations == null ? false : _ROFstAssociations.IsDirtyList(list)) || (_ROFstFigures == null ? false : _ROFstFigures.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ROFstAssociations == null ? true : _ROFstAssociations.IsValidList(list)) && (_ROFstFigures == null ? true : _ROFstFigures.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); - } - // CSLATODO: Replace base ROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFst - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ROFst.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFst - protected override object GetIdValue() - { - return MyROFstUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ROFstAssociations != null && (hasBrokenRules = _ROFstAssociations.HasBrokenRules) != null) return hasBrokenRules; - if (_ROFstFigures != null && (hasBrokenRules = _ROFstFigures.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ROFstExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ROFstExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyRODbRequired(ROFst target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(ROFstID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowRead(ROLookup, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - //AuthorizationRules.AllowWrite(ROLookup, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ROFstExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ROFstExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ROFstAssociationCount; - usedByCount += _ROFstFigureCount; - 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; } } - private static int _ROFstUnique = 0; - protected static int ROFstUnique - { get { return ++_ROFstUnique; } } - private int _MyROFstUnique = ROFstUnique; - public int MyROFstUnique // Absolutely Unique ID - Editable - { get { return _MyROFstUnique; } } - protected ROFst() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ROFst() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } + public byte[] ROLookup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return null; // B2022-026 RO Memory reduction + //if (_ROLookup == null) + //{ + // _ROLookup = ROFSTLookup.GetRofstLookupBytes(_ROFstID); + //} + //return _ROLookup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ROLookup != value) + { + _ROLookup = value; + PropertyHasChanged(); + } + } + } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) - { - List listROFst = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items - while (listROFst.Contains(this)) listROFst.Remove(this); // Remove the item from the list - if (listROFst.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByRODbID_DTS.Keys) - if (_CacheByRODbID_DTS[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listROFst = _CacheByRODbID_DTS[myKey]; // Get the list of items - listROFst.Remove(this); // Remove the item from the list - if (listROFst.Count == 0) //If there are no items left in the list - _CacheByRODbID_DTS.Remove(myKey); // remove the list - } - } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ROFstAssociationCount = 0; + /// + /// Count of ROFstAssociations for this ROFst + /// + public int ROFstAssociationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstAssociationCount; + } + } + private ROFstAssociations _ROFstAssociations = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ROFstAssociationsConverter))] + public ROFstAssociations ROFstAssociations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstAssociationCount < 0 || (_ROFstAssociationCount > 0 && _ROFstAssociations == null)) + _ROFstAssociations = ROFstAssociations.GetByROFstID(ROFstID); + if (_ROFstAssociationCount < 0) + _ROFstAssociationCount = _ROFstAssociations == null ? 0 : _ROFstAssociations.Count; + if (_ROFstAssociations == null) + _ROFstAssociations = ROFstAssociations.New(); + return _ROFstAssociations; + } + } + public void Reset_ROFstAssociations() + { + _ROFstAssociationCount = -1; + } + private int _ROFstFigureCount = 0; + /// + /// Count of ROFstFigures for this ROFst + /// + public int ROFstFigureCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstFigureCount; + } + } + private ROFstFigures _ROFstFigures = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ROFstFiguresConverter))] + public ROFstFigures ROFstFigures + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstFigureCount < 0 || (_ROFstFigureCount > 0 && _ROFstFigures == null)) + _ROFstFigures = ROFstFigures.GetByROFstID(ROFstID); + if (_ROFstFigureCount < 0) + _ROFstFigureCount = _ROFstFigures == null ? 0 : _ROFstFigures.Count; + if (_ROFstFigures == null) + _ROFstFigures = ROFstFigures.New(); + return _ROFstFigures; + } + } + public void Reset_ROFstFigures() + { + _ROFstFigureCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_ROFstAssociations == null ? false : _ROFstAssociations.IsDirtyList(list)) || (_ROFstFigures == null ? false : _ROFstFigures.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ROFstAssociations == null ? true : _ROFstAssociations.IsValidList(list)) && (_ROFstFigures == null ? true : _ROFstFigures.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + } + // CSLATODO: Replace base ROFst.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFst + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ROFst.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFst + protected override object GetIdValue() + { + return MyROFstUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ROFstAssociations != null && (hasBrokenRules = _ROFstAssociations.HasBrokenRules) != null) return hasBrokenRules; + if (_ROFstFigures != null && (hasBrokenRules = _ROFstFigures.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ROFstExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ROFstExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyRODbRequired(ROFst target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(ROFstID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowRead(ROLookup, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + //AuthorizationRules.AllowWrite(ROLookup, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ROFstExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ROFstExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ROFstAssociationCount; + usedByCount += _ROFstFigureCount; + 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; } } + private static int _ROFstUnique = 0; + protected static int ROFstUnique + { get { return ++_ROFstUnique; } } + private int _MyROFstUnique = ROFstUnique; + public int MyROFstUnique // Absolutely Unique ID - Editable + { get { return _MyROFstUnique; } } + protected ROFst() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ROFst() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } - public static ROFst New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFst"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.New", ex); - } - } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) + { + List listROFst = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items + while (listROFst.Contains(this)) listROFst.Remove(this); // Remove the item from the list + if (listROFst.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByRODbID_DTS.Keys) + if (_CacheByRODbID_DTS[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listROFst = _CacheByRODbID_DTS[myKey]; // Get the list of items + listROFst.Remove(this); // Remove the item from the list + if (listROFst.Count == 0) //If there are no items left in the list + _CacheByRODbID_DTS.Remove(myKey); // remove the list + } + } - public static ROFst New(RODb myRODb, byte[] rOLookup) - { - ROFst tmp = ROFst.New(); - tmp.MyRODb = myRODb; - tmp.ROLookup = rOLookup; - return tmp; - } + public static ROFst New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROFst"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.New", ex); + } + } - public static ROFst New(RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID) - { - ROFst tmp = ROFst.New(); - tmp.MyRODb = myRODb; - tmp.ROLookup = rOLookup; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - - public static ROFst New(RODb myRODb, byte[] rOLookup, string config) - { - ROFst tmp = ROFst.New(); - tmp.MyRODb = myRODb; - tmp.ROLookup = rOLookup; - tmp.Config = config; - return tmp; - } + public static ROFst New(RODb myRODb, byte[] rOLookup) + { + ROFst tmp = ROFst.New(); + tmp.MyRODb = myRODb; + tmp.ROLookup = rOLookup; + return tmp; + } - public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID) - { - ROFst tmp = ROFst.New(myRODb, rOLookup, config, dts, userID); + public static ROFst New(RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID) + { + ROFst tmp = ROFst.New(); + tmp.MyRODb = myRODb; + tmp.ROLookup = rOLookup; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } - if (tmp.IsSavable) - { - tmp = tmp.Save(); + public static ROFst New(RODb myRODb, byte[] rOLookup, string config) + { + ROFst tmp = ROFst.New(); + tmp.MyRODb = myRODb; + tmp.ROLookup = rOLookup; + tmp.Config = config; + return tmp; + } - // B2022-026 RO Memory reduction - if (tmp.ROLookup != null && tmp.ROFstID > 0) - { - //Force Load the new Lookup Data - var RofstLookup = new ROFSTLookup(tmp.ROFstID); - tmp.ROLookup = null; - } - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } + public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID) + { + ROFst tmp = ROFst.New(myRODb, rOLookup, config, dts, userID); - return tmp; - } - - public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config) - { - ROFst tmp = ROFst.New(myRODb, rOLookup, config); + if (tmp.IsSavable) + { + tmp = tmp.Save(); - if (tmp.IsSavable) - { - tmp = tmp.Save(); + // B2022-026 RO Memory reduction + if (tmp.ROLookup != null && tmp.ROFstID > 0) + { + //Force Load the new Lookup Data + var RofstLookup = new ROFSTLookup(tmp.ROFstID); + tmp.ROLookup = null; + } + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } - // B2022-026 RO Memory reduction - //Force Load the new Lookup Data - var RofstLookup = new ROFSTLookup(tmp.ROFstID); - tmp.ROLookup = null; - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } + return tmp; + } - return tmp; - } - - public static ROFst Get(int rOFstID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROFst"); - try - { - ROFst tmp = GetCachedByPrimaryKey(rOFstID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); - AddToCache(tmp); - } + public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config) + { + ROFst tmp = ROFst.New(myRODb, rOLookup, config); - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROFst - tmp = null; - } + if (tmp.IsSavable) + { + tmp = tmp.Save(); - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.Get", ex); - } - } + // B2022-026 RO Memory reduction + //Force Load the new Lookup Data + var RofstLookup = new ROFSTLookup(tmp.ROFstID); + tmp.ROLookup = null; + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } - public static ROFst GetByRODbID_DTS(int rODbID, DateTime dts) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROFst"); - try - { - ROFst tmp = GetCachedByRODbID_DTS(rODbID, dts); - if (tmp == null) - { - tmp = DataPortal.Fetch(new RODbID_DTSCriteria(rODbID, dts)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROFst - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.GetByRODbID_DTS", ex); - } - } - public static ROFst Get(SafeDataReader dr) - { - if (dr.Read()) return new ROFst(dr); - return null; - } - internal ROFst(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rOFstID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFst"); - try - { - DataPortal.Delete(new PKCriteria(rOFstID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.Delete", ex); - } - } - public override ROFst Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFst"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFst"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ROFst"); - try - { - BuildRefreshList(); - ROFst rOFst = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(rOFst);//Refresh the item in AllList - ProcessRefreshList(); - rOFst.ROLookup = null; // B2022-026 RO Memory reduction - return rOFst; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } - } - [Serializable()] - private class RODbID_DTSCriteria - { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - private DateTime _DTS; - public DateTime DTS - { get { return _DTS; } } - public RODbID_DTSCriteria(int rODbID, DateTime dts) - { - _RODbID = rODbID; - _DTS = dts; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ROFstID = NextROFstID; - // Database Defaults - _DTS = _ROFstExtension.DefaultDTS; - _UserID = _ROFstExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } + return tmp; + } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.ReadData", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _RODbID = dr.GetInt32("RODbID"); - //_ROLookup = (byte[])dr.GetValue("ROLookup"); - _ROLookup = null; // B2022-026 RO Memory reduction - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROFstAssociationCount = dr.GetInt32("AssociationCount"); - _ROFstFigureCount = dr.GetInt32("FigureCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.ReadData", ex); - } - } + public static ROFst Get(int rOFstID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROFst"); + try + { + ROFst tmp = GetCachedByPrimaryKey(rOFstID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); + AddToCache(tmp); + } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROFst"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ROFstAssociations = ROFstAssociations.Get(dr); - // load child objects - dr.NextResult(); - _ROFstFigures = ROFstFigures.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.DataPortal_Fetch", ex); - } - } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROFst + tmp = null; + } - private void DataPortal_Fetch(RODbID_DTSCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROFstByRODbID_DTS"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - if (criteria.DTS.Year >= 1753 && criteria.DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", criteria.DTS); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.DataPortal_Fetch", ex); - } - } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.Get", ex); + } + } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Insert", GetHashCode()); - } - } + public static ROFst GetByRODbID_DTS(int rODbID, DateTime dts) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROFst"); + try + { + ROFst tmp = GetCachedByRODbID_DTS(rODbID, dts); + if (tmp == null) + { + tmp = DataPortal.Fetch(new RODbID_DTSCriteria(rODbID, dts)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROFst + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.GetByRODbID_DTS", ex); + } + } + public static ROFst Get(SafeDataReader dr) + { + if (dr.Read()) return new ROFst(dr); + return null; + } + internal ROFst(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rOFstID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROFst"); + try + { + DataPortal.Delete(new PKCriteria(rOFstID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.Delete", ex); + } + } + public override ROFst Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROFst"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROFst"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ROFst"); + try + { + BuildRefreshList(); + ROFst rOFst = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(rOFst);//Refresh the item in AllList + ProcessRefreshList(); + rOFst.ROLookup = null; // B2022-026 RO Memory reduction + return rOFst; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + public PKCriteria(int rOFstID) + { + _ROFstID = rOFstID; + } + } + [Serializable()] + private class RODbID_DTSCriteria + { + private int _RODbID; + public int RODbID + { get { return _RODbID; } } + private DateTime _DTS; + public DateTime DTS + { get { return _DTS; } } + public RODbID_DTSCriteria(int rODbID, DateTime dts) + { + _RODbID = rODbID; + _DTS = dts; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ROFstID = NextROFstID; + // Database Defaults + _DTS = _ROFstExtension.DefaultDTS; + _UserID = _ROFstExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addROFst"; + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.ReadData", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _RODbID = dr.GetInt32("RODbID"); + //_ROLookup = (byte[])dr.GetValue("ROLookup"); + _ROLookup = null; // B2022-026 RO Memory reduction + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROFstAssociationCount = dr.GetInt32("AssociationCount"); + _ROFstFigureCount = dr.GetInt32("FigureCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.ReadData", ex); + } + } - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@ROLookup", _ROLookup); - 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_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); - param_ROFstID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROFstID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROFst"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ROFstAssociations = ROFstAssociations.Get(dr); + // load child objects + dr.NextResult(); + _ROFstFigures = ROFstFigures.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.DataPortal_Fetch", ex); + } + } - cm.ExecuteNonQuery(); + private void DataPortal_Fetch(RODbID_DTSCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROFstByRODbID_DTS"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + if (criteria.DTS.Year >= 1753 && criteria.DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", criteria.DTS); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.DataPortal_Fetch", ex); + } + } - // Save all values being returned from the Procedure - _ROFstID = (int)cm.Parameters["@newROFstID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Insert", GetHashCode()); + } + } - // Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction - _ROLookup = null; - } - MarkOld(); - // update child objects - if (_ROFstAssociations != null) _ROFstAssociations.Update(this); - if (_ROFstFigures != null) _ROFstFigures.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.SQLInsert", ex); - } - } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addROFst"; - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rOFstID, RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addROFst"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@ROLookup", _ROLookup); + cm.Parameters.AddWithValue("@Config", _Config); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); - cm.Parameters.AddWithValue("@ROLookup", rOLookup); - 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_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); + param_ROFstID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROFstID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); - // Output Calculated Columns - SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); - param_ROFstID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROFstID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); + cm.ExecuteNonQuery(); - cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _ROFstID = (int)cm.Parameters["@newROFstID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - // Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction - rOLookup = null; + // Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction + _ROLookup = null; + } + MarkOld(); + // update child objects + if (_ROFstAssociations != null) _ROFstAssociations.Update(this); + if (_ROFstFigures != null) _ROFstFigures.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.SQLInsert", ex); + } + } - // Save all values being returned from the Procedure - rOFstID = (int)cm.Parameters["@newROFstID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Add", ex); - throw new DbCslaException("ROFst.Add", ex); - } - } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rOFstID, RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addROFst"; - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); + cm.Parameters.AddWithValue("@ROLookup", rOLookup); + cm.Parameters.AddWithValue("@Config", config); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLUpdate() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLUpdate", GetHashCode()); - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateROFst"; + // Output Calculated Columns + SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); + param_ROFstID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROFstID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ROFstID", _ROFstID); - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@ROLookup", ROFSTLookup.GetRofstLookupBytes(_ROFstID)); // B2022-026 RO Memory reduction - new calls - 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.ExecuteNonQuery(); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); + // Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction + rOLookup = null; - cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + rOFstID = (int)cm.Parameters["@newROFstID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Add", ex); + throw new DbCslaException("ROFst.Add", ex); + } + } - // Save all values being returned from the Procedure - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - MarkOld(); - // use the open connection to update child objects - if (_ROFstAssociations != null) _ROFstAssociations.Update(this); - if (_ROFstFigures != null) _ROFstFigures.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ROFst.Add(cn, ref _ROFstID, _MyRODb, _ROLookup, _Config, _DTS, _UserID); - else - _LastChanged = ROFst.Update(cn, ref _ROFstID, _RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_ROFstAssociations != null) _ROFstAssociations.Update(this); - if (_ROFstFigures != null) _ROFstFigures.Update(this); - } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLUpdate() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLUpdate", GetHashCode()); + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateROFst"; - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rOFstID, int rODbID, byte[] rOLookup, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Update", 0); - try - { - // B2022-026 RO Memory reduction - check if we need to get the rOLookup - if (rOLookup == null) - rOLookup = ROFSTLookup.GetRofstLookupBytes(rOFstID); + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ROFstID", _ROFstID); + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@ROLookup", ROFSTLookup.GetRofstLookupBytes(_ROFstID)); // B2022-026 RO Memory reduction - new calls + 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); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateROFst"; + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROFstID", rOFstID); - cm.Parameters.AddWithValue("@RODbID", rODbID); - cm.Parameters.AddWithValue("@ROLookup", rOLookup); - 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.ExecuteNonQuery(); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); + // Save all values being returned from the Procedure + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + MarkOld(); + // use the open connection to update child objects + if (_ROFstAssociations != null) _ROFstAssociations.Update(this); + if (_ROFstFigures != null) _ROFstFigures.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } - cm.ExecuteNonQuery(); + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ROFst.Add(cn, ref _ROFstID, _MyRODb, _ROLookup, _Config, _DTS, _UserID); + else + _LastChanged = ROFst.Update(cn, ref _ROFstID, _RODbID, _ROLookup, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_ROFstAssociations != null) _ROFstAssociations.Update(this); + if (_ROFstFigures != null) _ROFstFigures.Update(this); + } - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Update", ex); - throw new DbCslaException("ROFst.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ROFstID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteROFst"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rOFstID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteROFst"; - // Input PK Fields - cm.Parameters.AddWithValue("@ROFstID", rOFstID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Remove", ex); - throw new DbCslaException("ROFst.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rOFstID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rOFstID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ROFstID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rOFstID) - { - _ROFstID = rOFstID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsROFst"; - cm.Parameters.AddWithValue("@ROFstID", _ROFstID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Execute", ex); - throw new DbCslaException("ROFst.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ROFstExtension _ROFstExtension = new ROFstExtension(); - [Serializable()] - partial class ROFstExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROFstConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFst) - { - // Return the ToString value - return ((ROFst)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rOFstID, int rODbID, byte[] rOLookup, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Update", 0); + try + { + // B2022-026 RO Memory reduction - check if we need to get the rOLookup + if (rOLookup == null) + rOLookup = ROFSTLookup.GetRofstLookupBytes(rOFstID); + + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateROFst"; + + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROFstID", rOFstID); + cm.Parameters.AddWithValue("@RODbID", rODbID); + cm.Parameters.AddWithValue("@ROLookup", rOLookup); + 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); + + cm.ExecuteNonQuery(); + + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Update", ex); + throw new DbCslaException("ROFst.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ROFstID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteROFst"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rOFstID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteROFst"; + // Input PK Fields + cm.Parameters.AddWithValue("@ROFstID", rOFstID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Remove", ex); + throw new DbCslaException("ROFst.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rOFstID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rOFstID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ROFstID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rOFstID) + { + _ROFstID = rOFstID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsROFst"; + cm.Parameters.AddWithValue("@ROFstID", _ROFstID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Execute", ex); + throw new DbCslaException("ROFst.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ROFstExtension _ROFstExtension = new ROFstExtension(); + [Serializable()] + partial class ROFstExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROFstConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFst) + { + // Return the ToString value + return ((ROFst)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociation.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociation.cs index a3a6b541..4f38fa08 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociation.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstAssociation.cs @@ -20,563 +20,543 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROFstAssociation Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstAssociationConverter))] - public partial class ROFstAssociation : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _AssociationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AssociationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AssociationID", true); - if (_MyAssociation != null) _AssociationID = _MyAssociation.AssociationID; - return _AssociationID; - } - } - private Association _MyAssociation; - [System.ComponentModel.DataObjectField(true, true)] - public Association MyAssociation - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssociation", true); - if (_MyAssociation == null && _AssociationID != 0) _MyAssociation = Association.Get(_AssociationID); - return _MyAssociation; - } - } - private int _VersionID; - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyDocVersion", true); - if (_MyDocVersion != value) - { - _MyDocVersion = value; - _VersionID = value.VersionID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _DocVersion_FolderID; - public int DocVersion_FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_FolderID", true); - return _DocVersion_FolderID; - } - } - private int _DocVersion_VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int DocVersion_VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_VersionType", true); - return _DocVersion_VersionType; - } - } - private string _DocVersion_Name = string.Empty; - public string DocVersion_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_Name", true); - return _DocVersion_Name; - } - } - private string _DocVersion_Title = string.Empty; - public string DocVersion_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_Title", true); - return _DocVersion_Title; - } - } - private int? _DocVersion_ItemID; - public int? DocVersion_ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_ItemID", true); - return _DocVersion_ItemID; - } - } - private int? _DocVersion_FormatID; - public int? DocVersion_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_FormatID", true); - return _DocVersion_FormatID; - } - } - private string _DocVersion_Config = string.Empty; - public string DocVersion_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_Config", true); - return _DocVersion_Config; - } - } - private DateTime _DocVersion_DTS = new DateTime(); - public DateTime DocVersion_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_DTS", true); - return _DocVersion_DTS; - } - } - private string _DocVersion_UserID = string.Empty; - public string DocVersion_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_UserID", true); - return _DocVersion_UserID; - } - } - // CSLATODO: Check ROFstAssociation.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstAssociation - protected override object GetIdValue() - { - return MyROFstAssociationUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ROFstAssociation.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstAssociation - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocVersion == null ? true : _MyDocVersion.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyDocVersion != null && (hasBrokenRules = _MyDocVersion.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyDocVersionRequired, "MyDocVersion"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyDocVersionRequired(ROFstAssociation target, Csla.Validation.RuleArgs e) - { - if (target._VersionID == 0 && target._MyDocVersion == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowWrite(VersionID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ROFstAssociationUnique = 0; - private static int ROFstAssociationUnique - { get { return ++_ROFstAssociationUnique; } } - private int _MyROFstAssociationUnique = ROFstAssociationUnique; - public int MyROFstAssociationUnique // Absolutely Unique ID - Editable FK - { get { return _MyROFstAssociationUnique; } } - internal static ROFstAssociation New(DocVersion myDocVersion) - { - return new ROFstAssociation(myDocVersion); - } - internal static ROFstAssociation Get(SafeDataReader dr) - { - return new ROFstAssociation(dr); - } - public ROFstAssociation() - { - MarkAsChild(); - _AssociationID = Association.NextAssociationID; - _DTS = _ROFstAssociationExtension.DefaultDTS; - _UserID = _ROFstAssociationExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ROFstAssociation(DocVersion myDocVersion) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _AssociationID = Association.NextAssociationID; - _DTS = _ROFstAssociationExtension.DefaultDTS; - _UserID = _ROFstAssociationExtension.DefaultUserID; - _MyDocVersion = myDocVersion; - ValidationRules.CheckRules(); - } - internal ROFstAssociation(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ROFstAssociation() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstAssociation.FetchDR", GetHashCode()); - try - { - _AssociationID = dr.GetInt32("AssociationID"); - _VersionID = dr.GetInt32("VersionID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _DocVersion_FolderID = dr.GetInt32("DocVersion_FolderID"); - _DocVersion_VersionType = dr.GetInt32("DocVersion_VersionType"); - _DocVersion_Name = dr.GetString("DocVersion_Name"); - _DocVersion_Title = dr.GetString("DocVersion_Title"); - _DocVersion_ItemID = (int?)dr.GetValue("DocVersion_ItemID"); - _DocVersion_FormatID = (int?)dr.GetValue("DocVersion_FormatID"); - _DocVersion_Config = dr.GetString("DocVersion_Config"); - _DocVersion_DTS = dr.GetDateTime("DocVersion_DTS"); - _DocVersion_UserID = dr.GetString("DocVersion_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstAssociation.FetchDR", ex); - throw new DbCslaException("ROFstAssociation.Fetch", ex); - } - MarkOld(); - } - internal void Insert(ROFst myROFst) - { - // 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); - MarkOld(); - } - internal void Update(ROFst myROFst) - { - // 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, _VersionID, myROFst.ROFstID, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(ROFst myROFst) - { - // 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ROFstAssociationExtension _ROFstAssociationExtension = new ROFstAssociationExtension(); - [Serializable()] - partial class ROFstAssociationExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROFstAssociationConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstAssociation) - { - // Return the ToString value - return ((ROFstAssociation)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ROFstAssociation Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstAssociationConverter))] + public partial class ROFstAssociation : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _AssociationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AssociationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssociation != null) _AssociationID = _MyAssociation.AssociationID; + return _AssociationID; + } + } + private Association _MyAssociation; + [System.ComponentModel.DataObjectField(true, true)] + public Association MyAssociation + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssociation == null && _AssociationID != 0) _MyAssociation = Association.Get(_AssociationID); + return _MyAssociation; + } + } + private int _VersionID; + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyDocVersion != value) + { + _MyDocVersion = value; + _VersionID = value.VersionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _DocVersion_FolderID; + public int DocVersion_FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_FolderID; + } + } + private int _DocVersion_VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int DocVersion_VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_VersionType; + } + } + private string _DocVersion_Name = string.Empty; + public string DocVersion_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_Name; + } + } + private string _DocVersion_Title = string.Empty; + public string DocVersion_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_Title; + } + } + private int? _DocVersion_ItemID; + public int? DocVersion_ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_ItemID; + } + } + private int? _DocVersion_FormatID; + public int? DocVersion_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_FormatID; + } + } + private string _DocVersion_Config = string.Empty; + public string DocVersion_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_Config; + } + } + private DateTime _DocVersion_DTS = new DateTime(); + public DateTime DocVersion_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_DTS; + } + } + private string _DocVersion_UserID = string.Empty; + public string DocVersion_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_UserID; + } + } + // CSLATODO: Check ROFstAssociation.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstAssociation + protected override object GetIdValue() + { + return MyROFstAssociationUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ROFstAssociation.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFstAssociation + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyDocVersion == null ? true : _MyDocVersion.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyDocVersion != null && (hasBrokenRules = _MyDocVersion.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyDocVersionRequired, "MyDocVersion"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyDocVersionRequired(ROFstAssociation target, Csla.Validation.RuleArgs e) + { + if (target._VersionID == 0 && target._MyDocVersion == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowWrite(VersionID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ROFstAssociationUnique = 0; + private static int ROFstAssociationUnique + { get { return ++_ROFstAssociationUnique; } } + private int _MyROFstAssociationUnique = ROFstAssociationUnique; + public int MyROFstAssociationUnique // Absolutely Unique ID - Editable FK + { get { return _MyROFstAssociationUnique; } } + internal static ROFstAssociation New(DocVersion myDocVersion) + { + return new ROFstAssociation(myDocVersion); + } + internal static ROFstAssociation Get(SafeDataReader dr) + { + return new ROFstAssociation(dr); + } + public ROFstAssociation() + { + MarkAsChild(); + _AssociationID = Association.NextAssociationID; + _DTS = _ROFstAssociationExtension.DefaultDTS; + _UserID = _ROFstAssociationExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ROFstAssociation(DocVersion myDocVersion) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _AssociationID = Association.NextAssociationID; + _DTS = _ROFstAssociationExtension.DefaultDTS; + _UserID = _ROFstAssociationExtension.DefaultUserID; + _MyDocVersion = myDocVersion; + ValidationRules.CheckRules(); + } + internal ROFstAssociation(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ROFstAssociation() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstAssociation.FetchDR", GetHashCode()); + try + { + _AssociationID = dr.GetInt32("AssociationID"); + _VersionID = dr.GetInt32("VersionID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _DocVersion_FolderID = dr.GetInt32("DocVersion_FolderID"); + _DocVersion_VersionType = dr.GetInt32("DocVersion_VersionType"); + _DocVersion_Name = dr.GetString("DocVersion_Name"); + _DocVersion_Title = dr.GetString("DocVersion_Title"); + _DocVersion_ItemID = (int?)dr.GetValue("DocVersion_ItemID"); + _DocVersion_FormatID = (int?)dr.GetValue("DocVersion_FormatID"); + _DocVersion_Config = dr.GetString("DocVersion_Config"); + _DocVersion_DTS = dr.GetDateTime("DocVersion_DTS"); + _DocVersion_UserID = dr.GetString("DocVersion_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstAssociation.FetchDR", ex); + throw new DbCslaException("ROFstAssociation.Fetch", ex); + } + MarkOld(); + } + internal void Insert(ROFst myROFst) + { + // 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); + MarkOld(); + } + internal void Update(ROFst myROFst) + { + // 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, _VersionID, myROFst.ROFstID, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(ROFst myROFst) + { + // 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ROFstAssociationExtension _ROFstAssociationExtension = new ROFstAssociationExtension(); + [Serializable()] + partial class ROFstAssociationExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROFstAssociationConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstAssociation) + { + // Return the ToString value + return ((ROFstAssociation)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigure.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigure.cs index b4342541..4f89775f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigure.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstFigure.cs @@ -20,527 +20,510 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROFstFigure Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstFigureConverter))] - public partial class ROFstFigure : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _FigureID; - [System.ComponentModel.DataObjectField(true, true)] - public int FigureID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FigureID", true); - if (_MyFigure != null) _FigureID = _MyFigure.FigureID; - return _FigureID; - } - } - private Figure _MyFigure; - [System.ComponentModel.DataObjectField(true, true)] - public Figure MyFigure - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFigure", true); - if (_MyFigure == null && _FigureID != 0) _MyFigure = Figure.Get(_FigureID); - return _MyFigure; - } - } - private int _ImageID; - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImage _MyROImage; - public ROImage MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash - return _MyROImage; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyROImage", true); - if (_MyROImage != value) - { - _MyROImage = value; - _ImageID = value.ImageID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ROImage_RODbID; - public int ROImage_RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_RODbID", true); - return _ROImage_RODbID; - } - } - private string _ROImage_FileName = string.Empty; - public string ROImage_FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_FileName", true); - return _ROImage_FileName; - } - } - private byte[] _ROImage_Content; - public byte[] ROImage_Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_Content", true); - return _ROImage_Content; - } - } - private string _ROImage_Config = string.Empty; - public string ROImage_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_Config", true); - return _ROImage_Config; - } - } - private DateTime _ROImage_DTS = new DateTime(); - public DateTime ROImage_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_DTS", true); - return _ROImage_DTS; - } - } - private string _ROImage_UserID = string.Empty; - public string ROImage_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_UserID", true); - return _ROImage_UserID; - } - } - // CSLATODO: Check ROFstFigure.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstFigure - protected override object GetIdValue() - { - return MyROFstFigureUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ROFstFigure.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstFigure - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyROImage == null ? false : _MyROImage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROImage == null ? true : _MyROImage.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyROImage != null && (hasBrokenRules = _MyROImage.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyROImageRequired, "MyROImage"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyROImageRequired(ROFstFigure target, Csla.Validation.RuleArgs e) - { - if (target._ImageID == 0 && target._MyROImage == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ImageID, ""); - //AuthorizationRules.AllowWrite(ImageID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ROFstFigureUnique = 0; - private static int ROFstFigureUnique - { get { return ++_ROFstFigureUnique; } } - private int _MyROFstFigureUnique = ROFstFigureUnique; - public int MyROFstFigureUnique // Absolutely Unique ID - Editable FK - { get { return _MyROFstFigureUnique; } } - internal static ROFstFigure New(ROImage myROImage) - { - return new ROFstFigure(myROImage); - } - internal static ROFstFigure Get(SafeDataReader dr) - { - return new ROFstFigure(dr); - } - public ROFstFigure() - { - MarkAsChild(); - _FigureID = Figure.NextFigureID; - _DTS = _ROFstFigureExtension.DefaultDTS; - _UserID = _ROFstFigureExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ROFstFigure(ROImage myROImage) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _FigureID = Figure.NextFigureID; - _DTS = _ROFstFigureExtension.DefaultDTS; - _UserID = _ROFstFigureExtension.DefaultUserID; - _MyROImage = myROImage; - ValidationRules.CheckRules(); - } - internal ROFstFigure(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ROFstFigure() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstFigure.FetchDR", GetHashCode()); - try - { - _FigureID = dr.GetInt32("FigureID"); - _ImageID = dr.GetInt32("ImageID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROImage_RODbID = dr.GetInt32("ROImage_RODbID"); - _ROImage_FileName = dr.GetString("ROImage_FileName"); - _ROImage_Content = (byte[])dr.GetValue("ROImage_Content"); - _ROImage_Config = dr.GetString("ROImage_Config"); - _ROImage_DTS = dr.GetDateTime("ROImage_DTS"); - _ROImage_UserID = dr.GetString("ROImage_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstFigure.FetchDR", ex); - throw new DbCslaException("ROFstFigure.Fetch", ex); - } - MarkOld(); - } - internal void Insert(ROFst myROFst) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Add(cn, ref _FigureID, myROFst, _MyROImage, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(ROFst myROFst) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Update(cn, ref _FigureID, myROFst.ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(ROFst myROFst) - { - // 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"]; - Figure.Remove(cn, _FigureID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ROFstFigureExtension _ROFstFigureExtension = new ROFstFigureExtension(); - [Serializable()] - partial class ROFstFigureExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROFstFigureConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstFigure) - { - // Return the ToString value - return ((ROFstFigure)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ROFstFigure Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstFigureConverter))] + public partial class ROFstFigure : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _FigureID; + [System.ComponentModel.DataObjectField(true, true)] + public int FigureID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFigure != null) _FigureID = _MyFigure.FigureID; + return _FigureID; + } + } + private Figure _MyFigure; + [System.ComponentModel.DataObjectField(true, true)] + public Figure MyFigure + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFigure == null && _FigureID != 0) _MyFigure = Figure.Get(_FigureID); + return _MyFigure; + } + } + private int _ImageID; + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImage _MyROImage; + public ROImage MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash + return _MyROImage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyROImage != value) + { + _MyROImage = value; + _ImageID = value.ImageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ROImage_RODbID; + public int ROImage_RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_RODbID; + } + } + private string _ROImage_FileName = string.Empty; + public string ROImage_FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_FileName; + } + } + private byte[] _ROImage_Content; + public byte[] ROImage_Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_Content; + } + } + private string _ROImage_Config = string.Empty; + public string ROImage_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_Config; + } + } + private DateTime _ROImage_DTS = new DateTime(); + public DateTime ROImage_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_DTS; + } + } + private string _ROImage_UserID = string.Empty; + public string ROImage_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_UserID; + } + } + // CSLATODO: Check ROFstFigure.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstFigure + protected override object GetIdValue() + { + return MyROFstFigureUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ROFstFigure.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFstFigure + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyROImage == null ? false : _MyROImage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROImage == null ? true : _MyROImage.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyROImage != null && (hasBrokenRules = _MyROImage.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyROImageRequired, "MyROImage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyROImageRequired(ROFstFigure target, Csla.Validation.RuleArgs e) + { + if (target._ImageID == 0 && target._MyROImage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ImageID, ""); + //AuthorizationRules.AllowWrite(ImageID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ROFstFigureUnique = 0; + private static int ROFstFigureUnique + { get { return ++_ROFstFigureUnique; } } + private int _MyROFstFigureUnique = ROFstFigureUnique; + public int MyROFstFigureUnique // Absolutely Unique ID - Editable FK + { get { return _MyROFstFigureUnique; } } + internal static ROFstFigure New(ROImage myROImage) + { + return new ROFstFigure(myROImage); + } + internal static ROFstFigure Get(SafeDataReader dr) + { + return new ROFstFigure(dr); + } + public ROFstFigure() + { + MarkAsChild(); + _FigureID = Figure.NextFigureID; + _DTS = _ROFstFigureExtension.DefaultDTS; + _UserID = _ROFstFigureExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ROFstFigure(ROImage myROImage) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _FigureID = Figure.NextFigureID; + _DTS = _ROFstFigureExtension.DefaultDTS; + _UserID = _ROFstFigureExtension.DefaultUserID; + _MyROImage = myROImage; + ValidationRules.CheckRules(); + } + internal ROFstFigure(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ROFstFigure() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstFigure.FetchDR", GetHashCode()); + try + { + _FigureID = dr.GetInt32("FigureID"); + _ImageID = dr.GetInt32("ImageID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROImage_RODbID = dr.GetInt32("ROImage_RODbID"); + _ROImage_FileName = dr.GetString("ROImage_FileName"); + _ROImage_Content = (byte[])dr.GetValue("ROImage_Content"); + _ROImage_Config = dr.GetString("ROImage_Config"); + _ROImage_DTS = dr.GetDateTime("ROImage_DTS"); + _ROImage_UserID = dr.GetString("ROImage_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstFigure.FetchDR", ex); + throw new DbCslaException("ROFstFigure.Fetch", ex); + } + MarkOld(); + } + internal void Insert(ROFst myROFst) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Figure.Add(cn, ref _FigureID, myROFst, _MyROImage, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(ROFst myROFst) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Figure.Update(cn, ref _FigureID, myROFst.ROFstID, _ImageID, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(ROFst myROFst) + { + // 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"]; + Figure.Remove(cn, _FigureID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ROFstFigureExtension _ROFstFigureExtension = new ROFstFigureExtension(); + [Serializable()] + partial class ROFstFigureExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROFstFigureConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstFigure) + { + // Return the ToString value + return ((ROFstFigure)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.cs index 011db645..ca54bb82 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROFstInfo.cs @@ -19,491 +19,480 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ROFstInfoEvent(object sender); - /// - /// ROFstInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstInfoConverter))] - public partial class ROFstInfo : ReadOnlyBase, IDisposable - { - public event ROFstInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROFstInfo rOFstInfo) - { - if (!_CacheList.Contains(rOFstInfo)) - { - rOFstInfo.ClearROLookupBytes(); // B2022-026 RO Memory reduction - _CacheList.Add(rOFstInfo); // In AddToCache - } - } - protected static void RemoveFromCache(ROFstInfo rOFstInfo) - { - while (_CacheList.Contains(rOFstInfo)) _CacheList.Remove(rOFstInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ROFstInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ROFstInfo tmp = _CacheList[0]; // Get the first ROFstInfo - string pKey = tmp.ROFstID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - tmp.ClearROLookupBytes(); // B2022-026 RO Memory reduction - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ROFstInfo - } - } - internal static void AddList(ROFstInfoList lst) - { - foreach (ROFstInfo item in lst) AddToCache(item); - } - protected static ROFstInfo GetCachedByPrimaryKey(int rOFstID) - { - ConvertListToDictionary(); - string key = rOFstID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ROFst _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - return _ROFstID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODbInfo _MyRODb; - public RODbInfo MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.GetJustRODB(_RODbID); - return _MyRODb; - } - } + public delegate void ROFstInfoEvent(object sender); + /// + /// ROFstInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstInfoConverter))] + public partial class ROFstInfo : ReadOnlyBase, IDisposable + { + public event ROFstInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROFstInfo rOFstInfo) + { + if (!_CacheList.Contains(rOFstInfo)) + { + rOFstInfo.ClearROLookupBytes(); // B2022-026 RO Memory reduction + _CacheList.Add(rOFstInfo); // In AddToCache + } + } + protected static void RemoveFromCache(ROFstInfo rOFstInfo) + { + while (_CacheList.Contains(rOFstInfo)) _CacheList.Remove(rOFstInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ROFstInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ROFstInfo tmp = _CacheList[0]; // Get the first ROFstInfo + string pKey = tmp.ROFstID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + tmp.ClearROLookupBytes(); // B2022-026 RO Memory reduction + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ROFstInfo + } + } + internal static void AddList(ROFstInfoList lst) + { + foreach (ROFstInfo item in lst) AddToCache(item); + } + protected static ROFstInfo GetCachedByPrimaryKey(int rOFstID) + { + ConvertListToDictionary(); + string key = rOFstID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ROFst _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODbInfo _MyRODb; + public RODbInfo MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.GetJustRODB(_RODbID); + return _MyRODb; + } + } - private byte[] _ROLookup; - public byte[] ROLookup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROLookup", true); + private byte[] _ROLookup; + public byte[] ROLookup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { - // B2022-026 RO Memory reduction - return null; - } - } + // B2022-026 RO Memory reduction + return null; + } + } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ROFstAssociationCount = 0; - /// - /// Count of ROFstAssociations for this ROFst - /// - public int ROFstAssociationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstAssociationCount", true); - if (_ROFstAssociationCount < 0) - _ROFstAssociationCount = ROFstAssociations.Count; - return _ROFstAssociationCount; - } - } - private AssociationInfoList _ROFstAssociations = null; - [TypeConverter(typeof(AssociationInfoListConverter))] - public AssociationInfoList ROFstAssociations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstAssociations", true); - if (_ROFstAssociationCount < 0 || (_ROFstAssociationCount > 0 && _ROFstAssociations == null)) - _ROFstAssociations = AssociationInfoList.GetByROFstID(_ROFstID); - if (_ROFstAssociationCount < 0) - _ROFstAssociationCount = _ROFstAssociations.Count; - return _ROFstAssociations; - } - } - public void RefreshROFstAssociations() - { - _ROFstAssociationCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) - foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) - tmp._ROFstAssociationCount = -1; // This will cause the data to be requeried - } - private int _ROFstFigureCount = 0; - /// - /// Count of ROFstFigures for this ROFst - /// - public int ROFstFigureCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstFigureCount", true); - if (_ROFstFigureCount < 0) - _ROFstFigureCount = ROFstFigures.Count; - return _ROFstFigureCount; - } - } - private FigureInfoList _ROFstFigures = null; - [TypeConverter(typeof(FigureInfoListConverter))] - public FigureInfoList ROFstFigures - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstFigures", true); - if (_ROFstFigureCount < 0 || (_ROFstFigureCount > 0 && _ROFstFigures == null)) - _ROFstFigures = FigureInfoList.GetByROFstID(_ROFstID); - if (_ROFstFigureCount < 0) - _ROFstFigureCount = _ROFstFigures.Count; - return _ROFstFigures; - } - } - public void RefreshROFstFigures() - { - _ROFstFigureCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) - foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) - tmp._ROFstFigureCount = -1; // This will cause the data to be requeried - } - - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstInfo - protected override object GetIdValue() - { - return MyROFstInfoUnique; // Absolutely Unique ID - } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ROFstAssociationCount = 0; + /// + /// Count of ROFstAssociations for this ROFst + /// + public int ROFstAssociationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstAssociationCount < 0) + _ROFstAssociationCount = ROFstAssociations.Count; + return _ROFstAssociationCount; + } + } + private AssociationInfoList _ROFstAssociations = null; + [TypeConverter(typeof(AssociationInfoListConverter))] + public AssociationInfoList ROFstAssociations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstAssociationCount < 0 || (_ROFstAssociationCount > 0 && _ROFstAssociations == null)) + _ROFstAssociations = AssociationInfoList.GetByROFstID(_ROFstID); + if (_ROFstAssociationCount < 0) + _ROFstAssociationCount = _ROFstAssociations.Count; + return _ROFstAssociations; + } + } + public void RefreshROFstAssociations() + { + _ROFstAssociationCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) + foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) + tmp._ROFstAssociationCount = -1; // This will cause the data to be requeried + } + private int _ROFstFigureCount = 0; + /// + /// Count of ROFstFigures for this ROFst + /// + public int ROFstFigureCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstFigureCount < 0) + _ROFstFigureCount = ROFstFigures.Count; + return _ROFstFigureCount; + } + } + private FigureInfoList _ROFstFigures = null; + [TypeConverter(typeof(FigureInfoListConverter))] + public FigureInfoList ROFstFigures + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstFigureCount < 0 || (_ROFstFigureCount > 0 && _ROFstFigures == null)) + _ROFstFigures = FigureInfoList.GetByROFstID(_ROFstID); + if (_ROFstFigureCount < 0) + _ROFstFigureCount = _ROFstFigures.Count; + return _ROFstFigures; + } + } + public void RefreshROFstFigures() + { + _ROFstFigureCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) + foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) + tmp._ROFstFigureCount = -1; // This will cause the data to be requeried + } - #endregion + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstInfo + protected override object GetIdValue() + { + return MyROFstInfoUnique; // Absolutely Unique ID + } - #region Factory Methods + #endregion - private static int _ROFstInfoUnique = 0; - private static int ROFstInfoUnique - { get { return ++_ROFstInfoUnique; } } - private int _MyROFstInfoUnique = ROFstInfoUnique; - public int MyROFstInfoUnique // Absolutely Unique ID - Info - { get { return _MyROFstInfoUnique; } } - protected ROFstInfo() - {/* require use of factory methods */ - AddToCache(this); - } - private bool _Disposed = false; - private static int _CountCreated = 0; - private static int _CountDisposed = 0; - private static int _CountFinalized = 0; + #region Factory Methods - 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; } } - ~ROFstInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) return; - List listROFstInfo = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items - while (listROFstInfo.Contains(this)) listROFstInfo.Remove(this); // Remove the item from the list - if (listROFstInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list - } - public virtual ROFst Get() - { - return _Editable = ROFst.Get(_ROFstID); - } - public static void Refresh(ROFst tmp) - { - string key = tmp.ROFstID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - // B2022-026 RO Memory reduction - public void ClearROLookupBytes() - { - _ROLookup = null; - } + private static int _ROFstInfoUnique = 0; + private static int ROFstInfoUnique + { get { return ++_ROFstInfoUnique; } } + private int _MyROFstInfoUnique = ROFstInfoUnique; + public int MyROFstInfoUnique // Absolutely Unique ID - Info + { get { return _MyROFstInfoUnique; } } + protected ROFstInfo() + {/* require use of factory methods */ + AddToCache(this); + } + private bool _Disposed = false; + private static int _CountCreated = 0; + private static int _CountDisposed = 0; + private static int _CountFinalized = 0; - protected virtual void RefreshFields(ROFst tmp) - { - if (_RODbID != tmp.RODbID) - { - if (MyRODb != null) MyRODb.RefreshRODbROFsts(); // 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.RefreshRODbROFsts(); // Update List for new value - //_ROLookup = tmp.ROLookup; - _ROLookup = null; // B2022-026 RO Memory reduction - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROFstInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RODbROFst tmp) - { - string key = tmp.ROFstID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODbROFst tmp) - { - //_ROLookup = tmp.ROLookup; - _ROLookup = null; // B2022-026 RO Memory reduction - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROFstInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ROFstInfo Get(int rOFstID) - { - try - { - ROFstInfo tmp = GetCachedByPrimaryKey(rOFstID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); - AddToCache(tmp); - } + 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; } } + ~ROFstInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) return; + List listROFstInfo = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items + while (listROFstInfo.Contains(this)) listROFstInfo.Remove(this); // Remove the item from the list + if (listROFstInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list + } + public virtual ROFst Get() + { + return _Editable = ROFst.Get(_ROFstID); + } + public static void Refresh(ROFst tmp) + { + string key = tmp.ROFstID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + // B2022-026 RO Memory reduction + public void ClearROLookupBytes() + { + _ROLookup = null; + } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROFstInfo - tmp = null; - } + protected virtual void RefreshFields(ROFst tmp) + { + if (_RODbID != tmp.RODbID) + { + if (MyRODb != null) MyRODb.RefreshRODbROFsts(); // 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.RefreshRODbROFsts(); // Update List for new value + //_ROLookup = tmp.ROLookup; + _ROLookup = null; // B2022-026 RO Memory reduction + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROFstInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RODbROFst tmp) + { + string key = tmp.ROFstID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODbROFst tmp) + { + //_ROLookup = tmp.ROLookup; + _ROLookup = null; // B2022-026 RO Memory reduction + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROFstInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ROFstInfo Get(int rOFstID) + { + try + { + ROFstInfo tmp = GetCachedByPrimaryKey(rOFstID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); + AddToCache(tmp); + } - if (tmp != null) - { - tmp.ClearROLookupBytes(); // B2022-026 RO Memory reduction - } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROFstInfo + tmp = null; + } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFstInfo.Get", ex); - } - } + if (tmp != null) + { + tmp.ClearROLookupBytes(); // B2022-026 RO Memory reduction + } - #endregion + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFstInfo.Get", ex); + } + } - #region Data Access Portal + #endregion - internal ROFstInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.Constructor", ex); - throw new DbCslaException("ROFstInfo.Constructor", ex); - } - } + #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } - } - - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.ReadData", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _RODbID = dr.GetInt32("RODbID"); - //_ROLookup = (byte[])dr.GetValue("ROLookup"); - _ROLookup = null; // B2022-026 RO Memory reduction - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _ROFstAssociationCount = dr.GetInt32("AssociationCount"); - _ROFstFigureCount = dr.GetInt32("FigureCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstInfo.ReadData", ex); - } - } + internal ROFstInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.Constructor", ex); + throw new DbCslaException("ROFstInfo.Constructor", ex); + } + } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROFst"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstInfo.DataPortal_Fetch", ex); - } - } + [Serializable()] + protected class PKCriteria + { + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + public PKCriteria(int rOFstID) + { + _ROFstID = rOFstID; + } + } - #endregion + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.ReadData", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _RODbID = dr.GetInt32("RODbID"); + //_ROLookup = (byte[])dr.GetValue("ROLookup"); + _ROLookup = null; // B2022-026 RO Memory reduction + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _ROFstAssociationCount = dr.GetInt32("AssociationCount"); + _ROFstFigureCount = dr.GetInt32("FigureCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstInfo.ReadData", ex); + } + } - // Standard Refresh - #region extension - ROFstInfoExtension _ROFstInfoExtension = new ROFstInfoExtension(); - [Serializable()] - partial class ROFstInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ROFstInfo tmp) { } - } - #endregion - } // Class + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROFst"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstInfo.DataPortal_Fetch", ex); + } + } - #region Converter + #endregion - internal class ROFstInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstInfo) - { - // Return the ToString value - return ((ROFstInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } + // Standard Refresh + #region extension + ROFstInfoExtension _ROFstInfoExtension = new ROFstInfoExtension(); + [Serializable()] + partial class ROFstInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ROFstInfo tmp) { } + } + #endregion + } // Class - #endregion + #region Converter + + internal class ROFstInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstInfo) + { + // Return the ToString value + return ((ROFstInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.cs index cb14fe57..5b8f58f8 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImage.cs @@ -20,1313 +20,1297 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROImage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROImageConverter))] - public partial class ROImage : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshROImages = new List(); - private List _RefreshROImageFigures = new List(); - private void AddToRefreshList(List refreshROImages, List refreshROImageFigures) - { - if (IsDirty) - refreshROImages.Add(this); - if (_ROImageFigures != null && _ROImageFigures.IsDirty) - { - foreach (ROImageFigure tmp in _ROImageFigures) - { - if (tmp.IsDirty) refreshROImageFigures.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshROImages = new List(); - _RefreshROImageFigures = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshROImages, _RefreshROImageFigures); - } - private void ProcessRefreshList() - { - foreach (ROImage tmp in _RefreshROImages) - { - ROImageInfo.Refresh(tmp); - if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); - } - foreach (ROImageFigure tmp in _RefreshROImageFigures) - { - FigureInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROImage rOImage) - { - if (!_CacheList.Contains(rOImage)) _CacheList.Add(rOImage); // In AddToCache - } - protected static void RemoveFromCache(ROImage rOImage) - { - while (_CacheList.Contains(rOImage)) _CacheList.Remove(rOImage); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByRODbID_FileName_DTS = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ROImage(s) from temporary _CacheList to _CacheByPrimaryKey - { - ROImage tmp = _CacheList[0]; // Get the first ROImage - string pKey = tmp.ImageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByRODbID_FileName_DTS[tmp.RODbID.ToString() + "_" + tmp.FileName.ToString() + "_" + tmp.DTS.ToString()] = new List(); // Add new list for RODbID_FileName_DTS - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByRODbID_FileName_DTS[tmp.RODbID.ToString() + "_" + tmp.FileName.ToString() + "_" + tmp.DTS.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first ROImage - } - } - protected static ROImage GetCachedByPrimaryKey(int imageID) - { - ConvertListToDictionary(); - string key = imageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static ROImage GetCachedByRODbID_FileName_DTS(int rODbID, string fileName, DateTime dts) - { - ConvertListToDictionary(); - string key = rODbID.ToString() + "_" + fileName.ToString() + "_" + dts.ToString(); - if (_CacheByRODbID_FileName_DTS.ContainsKey(key)) return _CacheByRODbID_FileName_DTS[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextImageID = -1; - public static int NextImageID - { - get { return _nextImageID--; } - } - private int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - return _ImageID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - _RODbID = value.RODbID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileName", true); - if (value == null) value = string.Empty; - if (_FileName != value) - { - _FileName = value; - PropertyHasChanged(); - } - } - } - private byte[] _Content; - public byte[] Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content", true); - return _Content; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Content", true); - if (_Content != value) - { - _Content = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ROImageFigureCount = 0; - /// - /// Count of ROImageFigures for this ROImage - /// - public int ROImageFigureCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageFigureCount", true); - return _ROImageFigureCount; - } - } - private ROImageFigures _ROImageFigures = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ROImageFiguresConverter))] - public ROImageFigures ROImageFigures - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageFigures", true); - if (_ROImageFigureCount < 0 || (_ROImageFigureCount > 0 && _ROImageFigures == null)) - _ROImageFigures = ROImageFigures.GetByImageID(ImageID); - if (_ROImageFigureCount < 0 ) - _ROImageFigureCount = _ROImageFigures == null ? 0 : _ROImageFigures.Count; - if (_ROImageFigures == null) - _ROImageFigures = ROImageFigures.New(); - return _ROImageFigures; - } - } - public void Reset_ROImageFigures() - { - _ROImageFigureCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_ROImageFigures == null ? false : _ROImageFigures.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ROImageFigures == null ? true : _ROImageFigures.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); - } - // CSLATODO: Replace base ROImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImage - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ROImage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROImage - protected override object GetIdValue() - { - return MyROImageUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ROImageFigures != null && (hasBrokenRules = _ROImageFigures.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ROImageExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ROImageExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyRODbRequired(ROImage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(ImageID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowRead(Content, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowWrite(Content, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ROImageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ROImageExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ROImageFigureCount; - 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; } } - private static int _ROImageUnique = 0; - protected static int ROImageUnique - { get { return ++_ROImageUnique; } } - private int _MyROImageUnique = ROImageUnique; - public int MyROImageUnique // Absolutely Unique ID - Editable - { get { return _MyROImageUnique; } } - protected ROImage() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ROImage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) - { - List listROImage = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items - while (listROImage.Contains(this)) listROImage.Remove(this); // Remove the item from the list - if (listROImage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByRODbID_FileName_DTS.Keys) - if (_CacheByRODbID_FileName_DTS[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listROImage = _CacheByRODbID_FileName_DTS[myKey]; // Get the list of items - listROImage.Remove(this); // Remove the item from the list - if (listROImage.Count == 0) //If there are no items left in the list - _CacheByRODbID_FileName_DTS.Remove(myKey); // remove the list - } - } - public static ROImage New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROImage"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.New", ex); - } - } - public static ROImage New(RODb myRODb, string fileName, byte[] content) - { - ROImage tmp = ROImage.New(); - tmp.MyRODb = myRODb; - tmp.FileName = fileName; - tmp.Content = content; - return tmp; - } - public static ROImage New(RODb myRODb, string fileName, byte[] content, string config, DateTime dts, string userID) - { - ROImage tmp = ROImage.New(); - tmp.MyRODb = myRODb; - tmp.FileName = fileName; - tmp.Content = content; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content, string config, DateTime dts, string userID) - { - ROImage tmp = ROImage.New(myRODb, fileName, content, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROImage New(RODb myRODb, string fileName, byte[] content, string config) - { - ROImage tmp = ROImage.New(); - tmp.MyRODb = myRODb; - tmp.FileName = fileName; - tmp.Content = content; - tmp.Config = config; - return tmp; - } - public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content, string config) - { - ROImage tmp = ROImage.New(myRODb, fileName, content, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROImage Get(int imageID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROImage"); - try - { - ROImage tmp = GetCachedByPrimaryKey(imageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROImage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.Get", ex); - } - } - public static ROImage GetJustROImage(int imageID)//Don't load figures or ROFST - Causing Memory Crash - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROImage"); - try - { - ROImage tmp = GetCachedByPrimaryKey(imageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteriaJustROImage(imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROImage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.Get", ex); - } - } - public static ROImage GetByRODbID_FileName_DTS(int rODbID, string fileName, DateTime dts) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROImage"); - try - { - ROImage tmp = GetCachedByRODbID_FileName_DTS(rODbID, fileName, dts); - if (tmp == null) - { - tmp = DataPortal.Fetch(new RODbID_FileName_DTSCriteria(rODbID, fileName, dts)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROImage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.GetByRODbID_FileName_DTS", ex); - } - } - public static ROImage Get(SafeDataReader dr) - { - if (dr.Read()) return new ROImage(dr); - return null; - } - internal ROImage(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int imageID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROImage"); - try - { - DataPortal.Delete(new PKCriteria(imageID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.Delete", ex); - } - } - public override ROImage Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROImage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROImage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ROImage"); - try - { - BuildRefreshList(); - ROImage rOImage = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(rOImage);//Refresh the item in AllList - ProcessRefreshList(); - return rOImage; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int imageID) - { - _ImageID = imageID; - } - } - [Serializable()] - protected class PKCriteriaJustROImage//Don't load figures or ROFST - Causing Memory Crash - { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteriaJustROImage(int imageID) - { - _ImageID = imageID; - } - } - [Serializable()] - private class RODbID_FileName_DTSCriteria - { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - private string _FileName; - public string FileName - { get { return _FileName; } } - private DateTime _DTS; - public DateTime DTS - { get { return _DTS; } } - public RODbID_FileName_DTSCriteria(int rODbID, string fileName, DateTime dts) - { - _RODbID = rODbID; - _FileName = fileName; - _DTS = dts; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ImageID = NextImageID; - // Database Defaults - _DTS = _ROImageExtension.DefaultDTS; - _UserID = _ROImageExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.ReadData", GetHashCode()); - try - { - _ImageID = dr.GetInt32("ImageID"); - _RODbID = dr.GetInt32("RODbID"); - _FileName = dr.GetString("FileName"); - _Content = (byte[])dr.GetValue("Content"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROImageFigureCount = dr.GetInt32("FigureCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROImage"; - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ROImageFigures = ROImageFigures.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(PKCriteriaJustROImage criteria)//Don't load figures or ROFST - Causing Memory Crash - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getJustROImage"; - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(RODbID_FileName_DTSCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROImageByRODbID_FileName_DTS"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - cm.Parameters.AddWithValue("@FileName", criteria.FileName); - if (criteria.DTS.Year >= 1753 && criteria.DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", criteria.DTS); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addROImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@FileName", _FileName); - cm.Parameters.AddWithValue("@Content", _Content); - 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_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); - param_ImageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ImageID); - 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 - _ImageID = (int)cm.Parameters["@newImageID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_ROImageFigures != null) _ROImageFigures.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int imageID, RODb myRODb, string fileName, byte[] content, string config, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addROImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); - cm.Parameters.AddWithValue("@FileName", fileName); - cm.Parameters.AddWithValue("@Content", content); - 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_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); - param_ImageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ImageID); - 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 - imageID = (int)cm.Parameters["@newImageID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Add", ex); - throw new DbCslaException("ROImage.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ROImage.SQLUpdate", GetHashCode()); - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateROImage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ImageID", _ImageID); - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@FileName", _FileName); - cm.Parameters.AddWithValue("@Content", _Content); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_ROImageFigures != null) _ROImageFigures.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ROImage.Add(cn, ref _ImageID, _MyRODb, _FileName, _Content, _Config, _DTS, _UserID); - else - _LastChanged = ROImage.Update(cn, ref _ImageID, _RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_ROImageFigures != null) _ROImageFigures.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int imageID, int rODbID, string fileName, byte[] content, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateROImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ImageID", imageID); - cm.Parameters.AddWithValue("@RODbID", rODbID); - cm.Parameters.AddWithValue("@FileName", fileName); - cm.Parameters.AddWithValue("@Content", content); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Update", ex); - throw new DbCslaException("ROImage.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ImageID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteROImage"; - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int imageID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteROImage"; - // Input PK Fields - cm.Parameters.AddWithValue("@ImageID", imageID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Remove", ex); - throw new DbCslaException("ROImage.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int imageID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(imageID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ImageID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int imageID) - { - _ImageID = imageID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsROImage"; - cm.Parameters.AddWithValue("@ImageID", _ImageID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Execute", ex); - throw new DbCslaException("ROImage.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ROImageExtension _ROImageExtension = new ROImageExtension(); - [Serializable()] - partial class ROImageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROImage) - { - // Return the ToString value - return ((ROImage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ROImage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROImageConverter))] + public partial class ROImage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshROImages = new List(); + private List _RefreshROImageFigures = new List(); + private void AddToRefreshList(List refreshROImages, List refreshROImageFigures) + { + if (IsDirty) + refreshROImages.Add(this); + if (_ROImageFigures != null && _ROImageFigures.IsDirty) + { + foreach (ROImageFigure tmp in _ROImageFigures) + { + if (tmp.IsDirty) refreshROImageFigures.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshROImages = new List(); + _RefreshROImageFigures = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshROImages, _RefreshROImageFigures); + } + private void ProcessRefreshList() + { + foreach (ROImage tmp in _RefreshROImages) + { + ROImageInfo.Refresh(tmp); + if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); + } + foreach (ROImageFigure tmp in _RefreshROImageFigures) + { + FigureInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROImage rOImage) + { + if (!_CacheList.Contains(rOImage)) _CacheList.Add(rOImage); // In AddToCache + } + protected static void RemoveFromCache(ROImage rOImage) + { + while (_CacheList.Contains(rOImage)) _CacheList.Remove(rOImage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByRODbID_FileName_DTS = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ROImage(s) from temporary _CacheList to _CacheByPrimaryKey + { + ROImage tmp = _CacheList[0]; // Get the first ROImage + string pKey = tmp.ImageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByRODbID_FileName_DTS[tmp.RODbID.ToString() + "_" + tmp.FileName.ToString() + "_" + tmp.DTS.ToString()] = new List(); // Add new list for RODbID_FileName_DTS + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByRODbID_FileName_DTS[tmp.RODbID.ToString() + "_" + tmp.FileName.ToString() + "_" + tmp.DTS.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first ROImage + } + } + protected static ROImage GetCachedByPrimaryKey(int imageID) + { + ConvertListToDictionary(); + string key = imageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static ROImage GetCachedByRODbID_FileName_DTS(int rODbID, string fileName, DateTime dts) + { + ConvertListToDictionary(); + string key = rODbID.ToString() + "_" + fileName.ToString() + "_" + dts.ToString(); + if (_CacheByRODbID_FileName_DTS.ContainsKey(key)) return _CacheByRODbID_FileName_DTS[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextImageID = -1; + public static int NextImageID + { + get { return _nextImageID--; } + } + private int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + _RODbID = value.RODbID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileName != value) + { + _FileName = value; + PropertyHasChanged(); + } + } + } + private byte[] _Content; + public byte[] Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Content != value) + { + _Content = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ROImageFigureCount = 0; + /// + /// Count of ROImageFigures for this ROImage + /// + public int ROImageFigureCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImageFigureCount; + } + } + private ROImageFigures _ROImageFigures = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ROImageFiguresConverter))] + public ROImageFigures ROImageFigures + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROImageFigureCount < 0 || (_ROImageFigureCount > 0 && _ROImageFigures == null)) + _ROImageFigures = ROImageFigures.GetByImageID(ImageID); + if (_ROImageFigureCount < 0) + _ROImageFigureCount = _ROImageFigures == null ? 0 : _ROImageFigures.Count; + if (_ROImageFigures == null) + _ROImageFigures = ROImageFigures.New(); + return _ROImageFigures; + } + } + public void Reset_ROImageFigures() + { + _ROImageFigureCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_ROImageFigures == null ? false : _ROImageFigures.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_ROImageFigures == null ? true : _ROImageFigures.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + } + // CSLATODO: Replace base ROImage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROImage + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ROImage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROImage + protected override object GetIdValue() + { + return MyROImageUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ROImageFigures != null && (hasBrokenRules = _ROImageFigures.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ROImageExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ROImageExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyRODbRequired(ROImage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(ImageID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowRead(FileName, ""); + //AuthorizationRules.AllowRead(Content, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + //AuthorizationRules.AllowWrite(FileName, ""); + //AuthorizationRules.AllowWrite(Content, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ROImageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ROImageExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ROImageFigureCount; + 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; } } + private static int _ROImageUnique = 0; + protected static int ROImageUnique + { get { return ++_ROImageUnique; } } + private int _MyROImageUnique = ROImageUnique; + public int MyROImageUnique // Absolutely Unique ID - Editable + { get { return _MyROImageUnique; } } + protected ROImage() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ROImage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) + { + List listROImage = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items + while (listROImage.Contains(this)) listROImage.Remove(this); // Remove the item from the list + if (listROImage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByRODbID_FileName_DTS.Keys) + if (_CacheByRODbID_FileName_DTS[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listROImage = _CacheByRODbID_FileName_DTS[myKey]; // Get the list of items + listROImage.Remove(this); // Remove the item from the list + if (listROImage.Count == 0) //If there are no items left in the list + _CacheByRODbID_FileName_DTS.Remove(myKey); // remove the list + } + } + public static ROImage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROImage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.New", ex); + } + } + public static ROImage New(RODb myRODb, string fileName, byte[] content) + { + ROImage tmp = ROImage.New(); + tmp.MyRODb = myRODb; + tmp.FileName = fileName; + tmp.Content = content; + return tmp; + } + public static ROImage New(RODb myRODb, string fileName, byte[] content, string config, DateTime dts, string userID) + { + ROImage tmp = ROImage.New(); + tmp.MyRODb = myRODb; + tmp.FileName = fileName; + tmp.Content = content; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content, string config, DateTime dts, string userID) + { + ROImage tmp = ROImage.New(myRODb, fileName, content, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROImage New(RODb myRODb, string fileName, byte[] content, string config) + { + ROImage tmp = ROImage.New(); + tmp.MyRODb = myRODb; + tmp.FileName = fileName; + tmp.Content = content; + tmp.Config = config; + return tmp; + } + public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content, string config) + { + ROImage tmp = ROImage.New(myRODb, fileName, content, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROImage Get(int imageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROImage"); + try + { + ROImage tmp = GetCachedByPrimaryKey(imageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROImage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.Get", ex); + } + } + public static ROImage GetJustROImage(int imageID)//Don't load figures or ROFST - Causing Memory Crash + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROImage"); + try + { + ROImage tmp = GetCachedByPrimaryKey(imageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteriaJustROImage(imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROImage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.Get", ex); + } + } + public static ROImage GetByRODbID_FileName_DTS(int rODbID, string fileName, DateTime dts) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROImage"); + try + { + ROImage tmp = GetCachedByRODbID_FileName_DTS(rODbID, fileName, dts); + if (tmp == null) + { + tmp = DataPortal.Fetch(new RODbID_FileName_DTSCriteria(rODbID, fileName, dts)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROImage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.GetByRODbID_FileName_DTS", ex); + } + } + public static ROImage Get(SafeDataReader dr) + { + if (dr.Read()) return new ROImage(dr); + return null; + } + internal ROImage(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int imageID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROImage"); + try + { + DataPortal.Delete(new PKCriteria(imageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.Delete", ex); + } + } + public override ROImage Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROImage"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROImage"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ROImage"); + try + { + BuildRefreshList(); + ROImage rOImage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(rOImage);//Refresh the item in AllList + ProcessRefreshList(); + return rOImage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ImageID; + public int ImageID + { get { return _ImageID; } } + public PKCriteria(int imageID) + { + _ImageID = imageID; + } + } + [Serializable()] + protected class PKCriteriaJustROImage//Don't load figures or ROFST - Causing Memory Crash + { + private int _ImageID; + public int ImageID + { get { return _ImageID; } } + public PKCriteriaJustROImage(int imageID) + { + _ImageID = imageID; + } + } + [Serializable()] + private class RODbID_FileName_DTSCriteria + { + private int _RODbID; + public int RODbID + { get { return _RODbID; } } + private string _FileName; + public string FileName + { get { return _FileName; } } + private DateTime _DTS; + public DateTime DTS + { get { return _DTS; } } + public RODbID_FileName_DTSCriteria(int rODbID, string fileName, DateTime dts) + { + _RODbID = rODbID; + _FileName = fileName; + _DTS = dts; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ImageID = NextImageID; + // Database Defaults + _DTS = _ROImageExtension.DefaultDTS; + _UserID = _ROImageExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.ReadData", GetHashCode()); + try + { + _ImageID = dr.GetInt32("ImageID"); + _RODbID = dr.GetInt32("RODbID"); + _FileName = dr.GetString("FileName"); + _Content = (byte[])dr.GetValue("Content"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROImageFigureCount = dr.GetInt32("FigureCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROImage"; + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ROImageFigures = ROImageFigures.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(PKCriteriaJustROImage criteria)//Don't load figures or ROFST - Causing Memory Crash + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getJustROImage"; + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(RODbID_FileName_DTSCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROImageByRODbID_FileName_DTS"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + cm.Parameters.AddWithValue("@FileName", criteria.FileName); + if (criteria.DTS.Year >= 1753 && criteria.DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", criteria.DTS); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addROImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Content", _Content); + 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_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); + param_ImageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ImageID); + 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 + _ImageID = (int)cm.Parameters["@newImageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_ROImageFigures != null) _ROImageFigures.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int imageID, RODb myRODb, string fileName, byte[] content, string config, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addROImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); + cm.Parameters.AddWithValue("@FileName", fileName); + cm.Parameters.AddWithValue("@Content", content); + 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_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); + param_ImageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ImageID); + 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 + imageID = (int)cm.Parameters["@newImageID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Add", ex); + throw new DbCslaException("ROImage.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ROImage.SQLUpdate", GetHashCode()); + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateROImage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ImageID", _ImageID); + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Content", _Content); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_ROImageFigures != null) _ROImageFigures.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ROImage.Add(cn, ref _ImageID, _MyRODb, _FileName, _Content, _Config, _DTS, _UserID); + else + _LastChanged = ROImage.Update(cn, ref _ImageID, _RODbID, _FileName, _Content, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_ROImageFigures != null) _ROImageFigures.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int imageID, int rODbID, string fileName, byte[] content, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateROImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ImageID", imageID); + cm.Parameters.AddWithValue("@RODbID", rODbID); + cm.Parameters.AddWithValue("@FileName", fileName); + cm.Parameters.AddWithValue("@Content", content); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Update", ex); + throw new DbCslaException("ROImage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ImageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteROImage"; + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int imageID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteROImage"; + // Input PK Fields + cm.Parameters.AddWithValue("@ImageID", imageID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Remove", ex); + throw new DbCslaException("ROImage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int imageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(imageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ImageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int imageID) + { + _ImageID = imageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsROImage"; + cm.Parameters.AddWithValue("@ImageID", _ImageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Execute", ex); + throw new DbCslaException("ROImage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ROImageExtension _ROImageExtension = new ROImageExtension(); + [Serializable()] + partial class ROImageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROImage) + { + // Return the ToString value + return ((ROImage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigure.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigure.cs index 3734a4d0..45226ad6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigure.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageFigure.cs @@ -20,516 +20,500 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROImageFigure Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROImageFigureConverter))] - public partial class ROImageFigure : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _FigureID; - [System.ComponentModel.DataObjectField(true, true)] - public int FigureID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FigureID", true); - if (_MyFigure != null) _FigureID = _MyFigure.FigureID; - return _FigureID; - } - } - private Figure _MyFigure; - [System.ComponentModel.DataObjectField(true, true)] - public Figure MyFigure - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFigure", true); - if (_MyFigure == null && _FigureID != 0) _MyFigure = Figure.Get(_FigureID); - return _MyFigure; - } - } - private int _ROFstID; - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyROFst", true); - if (_MyROFst != value) - { - _MyROFst = value; - _ROFstID = value.ROFstID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - 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 - { - CanReadProperty("ROFst_RODbID", true); - return _ROFst_RODbID; - } - } - private byte[] _ROFst_ROLookup; - public byte[] ROFst_ROLookup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_ROLookup", true); - return _ROFst_ROLookup; - } - } - private string _ROFst_Config = string.Empty; - public string ROFst_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_Config", true); - return _ROFst_Config; - } - } - private DateTime _ROFst_DTS = new DateTime(); - public DateTime ROFst_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_DTS", true); - return _ROFst_DTS; - } - } - private string _ROFst_UserID = string.Empty; - public string ROFst_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_UserID", true); - return _ROFst_UserID; - } - } - // CSLATODO: Check ROImageFigure.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROImageFigure - protected override object GetIdValue() - { - return MyROImageFigureUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base ROImageFigure.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImageFigure - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - 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()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyROFstRequired, "MyROFst"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyROFstRequired(ROImageFigure target, Csla.Validation.RuleArgs e) - { - if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowWrite(ROFstID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _ROImageFigureUnique = 0; - private static int ROImageFigureUnique - { get { return ++_ROImageFigureUnique; } } - private int _MyROImageFigureUnique = ROImageFigureUnique; - public int MyROImageFigureUnique // Absolutely Unique ID - Editable FK - { get { return _MyROImageFigureUnique; } } - internal static ROImageFigure New(ROFst myROFst) - { - return new ROImageFigure(myROFst); - } - internal static ROImageFigure Get(SafeDataReader dr) - { - return new ROImageFigure(dr); - } - public ROImageFigure() - { - MarkAsChild(); - _FigureID = Figure.NextFigureID; - _DTS = _ROImageFigureExtension.DefaultDTS; - _UserID = _ROImageFigureExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ROImageFigure(ROFst myROFst) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _FigureID = Figure.NextFigureID; - _DTS = _ROImageFigureExtension.DefaultDTS; - _UserID = _ROImageFigureExtension.DefaultUserID; - _MyROFst = myROFst; - ValidationRules.CheckRules(); - } - internal ROImageFigure(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~ROImageFigure() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageFigure.FetchDR", GetHashCode()); - try - { - _FigureID = dr.GetInt32("FigureID"); - _ROFstID = dr.GetInt32("ROFstID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROFst_RODbID = dr.GetInt32("ROFst_RODbID"); - _ROFst_ROLookup = (byte[])dr.GetValue("ROFst_ROLookup"); - _ROFst_Config = dr.GetString("ROFst_Config"); - _ROFst_DTS = dr.GetDateTime("ROFst_DTS"); - _ROFst_UserID = dr.GetString("ROFst_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageFigure.FetchDR", ex); - throw new DbCslaException("ROImageFigure.Fetch", ex); - } - MarkOld(); - } - internal void Insert(ROImage myROImage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Add(cn, ref _FigureID, _MyROFst, myROImage, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(ROImage myROImage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, myROImage.ImageID, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(ROImage myROImage) - { - // 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"]; - Figure.Remove(cn, _FigureID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ROImageFigureExtension _ROImageFigureExtension = new ROImageFigureExtension(); - [Serializable()] - partial class ROImageFigureExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROImageFigureConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROImageFigure) - { - // Return the ToString value - return ((ROImageFigure)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ROImageFigure Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROImageFigureConverter))] + public partial class ROImageFigure : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _FigureID; + [System.ComponentModel.DataObjectField(true, true)] + public int FigureID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFigure != null) _FigureID = _MyFigure.FigureID; + return _FigureID; + } + } + private Figure _MyFigure; + [System.ComponentModel.DataObjectField(true, true)] + public Figure MyFigure + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFigure == null && _FigureID != 0) _MyFigure = Figure.Get(_FigureID); + return _MyFigure; + } + } + private int _ROFstID; + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyROFst != value) + { + _MyROFst = value; + _ROFstID = value.ROFstID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + 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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_ROLookup; + } + } + private string _ROFst_Config = string.Empty; + public string ROFst_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_Config; + } + } + private DateTime _ROFst_DTS = new DateTime(); + public DateTime ROFst_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_DTS; + } + } + private string _ROFst_UserID = string.Empty; + public string ROFst_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_UserID; + } + } + // CSLATODO: Check ROImageFigure.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROImageFigure + protected override object GetIdValue() + { + return MyROImageFigureUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base ROImageFigure.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROImageFigure + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + 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()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyROFst != null && (hasBrokenRules = _MyROFst.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyROFstRequired, "MyROFst"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyROFstRequired(ROImageFigure target, Csla.Validation.RuleArgs e) + { + if (target._ROFstID == 0 && target._MyROFst == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowWrite(ROFstID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _ROImageFigureUnique = 0; + private static int ROImageFigureUnique + { get { return ++_ROImageFigureUnique; } } + private int _MyROImageFigureUnique = ROImageFigureUnique; + public int MyROImageFigureUnique // Absolutely Unique ID - Editable FK + { get { return _MyROImageFigureUnique; } } + internal static ROImageFigure New(ROFst myROFst) + { + return new ROImageFigure(myROFst); + } + internal static ROImageFigure Get(SafeDataReader dr) + { + return new ROImageFigure(dr); + } + public ROImageFigure() + { + MarkAsChild(); + _FigureID = Figure.NextFigureID; + _DTS = _ROImageFigureExtension.DefaultDTS; + _UserID = _ROImageFigureExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ROImageFigure(ROFst myROFst) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _FigureID = Figure.NextFigureID; + _DTS = _ROImageFigureExtension.DefaultDTS; + _UserID = _ROImageFigureExtension.DefaultUserID; + _MyROFst = myROFst; + ValidationRules.CheckRules(); + } + internal ROImageFigure(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~ROImageFigure() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageFigure.FetchDR", GetHashCode()); + try + { + _FigureID = dr.GetInt32("FigureID"); + _ROFstID = dr.GetInt32("ROFstID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROFst_RODbID = dr.GetInt32("ROFst_RODbID"); + _ROFst_ROLookup = (byte[])dr.GetValue("ROFst_ROLookup"); + _ROFst_Config = dr.GetString("ROFst_Config"); + _ROFst_DTS = dr.GetDateTime("ROFst_DTS"); + _ROFst_UserID = dr.GetString("ROFst_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageFigure.FetchDR", ex); + throw new DbCslaException("ROImageFigure.Fetch", ex); + } + MarkOld(); + } + internal void Insert(ROImage myROImage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Figure.Add(cn, ref _FigureID, _MyROFst, myROImage, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(ROImage myROImage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Figure.Update(cn, ref _FigureID, _ROFstID, myROImage.ImageID, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(ROImage myROImage) + { + // 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"]; + Figure.Remove(cn, _FigureID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ROImageFigureExtension _ROImageFigureExtension = new ROImageFigureExtension(); + [Serializable()] + partial class ROImageFigureExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROImageFigureConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROImageFigure) + { + // Return the ToString value + return ((ROImageFigure)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.cs index 4ad0717d..a1b5463b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ROImageInfo.cs @@ -19,438 +19,428 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ROImageInfoEvent(object sender); - /// - /// ROImageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROImageInfoConverter))] - public partial class ROImageInfo : ReadOnlyBase, IDisposable - { - public event ROImageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROImageInfo rOImageInfo) - { - if (!_CacheList.Contains(rOImageInfo)) _CacheList.Add(rOImageInfo); // In AddToCache - } - protected static void RemoveFromCache(ROImageInfo rOImageInfo) - { - while (_CacheList.Contains(rOImageInfo)) _CacheList.Remove(rOImageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ROImageInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ROImageInfo tmp = _CacheList[0]; // Get the first ROImageInfo - string pKey = tmp.ImageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ROImageInfo - } - } - internal static void AddList(ROImageInfoList lst) - { - foreach (ROImageInfo item in lst) AddToCache(item); - } - protected static ROImageInfo GetCachedByPrimaryKey(int imageID) - { - ConvertListToDictionary(); - string key = imageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ROImage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - return _ImageID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODbInfo _MyRODb; - public RODbInfo MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); - return _MyRODb; - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - } - private byte[] _Content; - public byte[] Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content", true); - return _Content; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ROImageFigureCount = 0; - /// - /// Count of ROImageFigures for this ROImage - /// - public int ROImageFigureCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageFigureCount", true); - if (_ROImageFigureCount < 0) - _ROImageFigureCount = ROImageFigures.Count; - return _ROImageFigureCount; - } - } - private FigureInfoList _ROImageFigures = null; - [TypeConverter(typeof(FigureInfoListConverter))] - public FigureInfoList ROImageFigures - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageFigures", true); - if (_ROImageFigureCount < 0 || (_ROImageFigureCount > 0 && _ROImageFigures == null)) - _ROImageFigures = FigureInfoList.GetByImageID(_ImageID); - if (_ROImageFigureCount < 0) - _ROImageFigureCount = _ROImageFigures.Count; - return _ROImageFigures; - } - } - public void RefreshROImageFigures() - { - _ROImageFigureCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ImageID.ToString())) - foreach (ROImageInfo tmp in _CacheByPrimaryKey[_ImageID.ToString()]) - tmp._ROImageFigureCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base ROImageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ROImageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROImageInfo - protected override object GetIdValue() - { - return MyROImageInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ROImageInfoUnique = 0; - private static int ROImageInfoUnique - { get { return ++_ROImageInfoUnique; } } - private int _MyROImageInfoUnique = ROImageInfoUnique; - public int MyROImageInfoUnique // Absolutely Unique ID - Info - { get { return _MyROImageInfoUnique; } } - protected ROImageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ROImageInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - _Content = null; // to clear content from memory - _Config = null; // to clear config from memory - if (!_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) return; - List listROImageInfo = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items - while (listROImageInfo.Contains(this)) listROImageInfo.Remove(this); // Remove the item from the list - if (listROImageInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list - } - public virtual ROImage Get() - { - return _Editable = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash - } - public static void Refresh(ROImage tmp) - { - string key = tmp.ImageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROImage tmp) - { - if (_RODbID != tmp.RODbID) - { - if (MyRODb != null) MyRODb.RefreshRODbROImages(); // 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.RefreshRODbROImages(); // Update List for new value - _FileName = tmp.FileName; - _Content = tmp.Content; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROImageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RODbROImage tmp) - { - string key = tmp.ImageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODbROImage tmp) - { - _FileName = tmp.FileName; - _Content = tmp.Content; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROImageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ROImageInfo Get(int imageID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ROImage"); - try - { - ROImageInfo tmp = GetCachedByPrimaryKey(imageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROImageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ROImageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.Constructor", ex); - throw new DbCslaException("ROImageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int imageID) - { - _ImageID = imageID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.ReadData", GetHashCode()); - try - { - _ImageID = dr.GetInt32("ImageID"); - _RODbID = dr.GetInt32("RODbID"); - _FileName = dr.GetString("FileName"); - _Content = (byte[])dr.GetValue("Content"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _ROImageFigureCount = dr.GetInt32("FigureCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROImage"; - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ROImageInfoExtension _ROImageInfoExtension = new ROImageInfoExtension(); - [Serializable()] - partial class ROImageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ROImageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ROImageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROImageInfo) - { - // Return the ToString value - return ((ROImageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ROImageInfoEvent(object sender); + /// + /// ROImageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROImageInfoConverter))] + public partial class ROImageInfo : ReadOnlyBase, IDisposable + { + public event ROImageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROImageInfo rOImageInfo) + { + if (!_CacheList.Contains(rOImageInfo)) _CacheList.Add(rOImageInfo); // In AddToCache + } + protected static void RemoveFromCache(ROImageInfo rOImageInfo) + { + while (_CacheList.Contains(rOImageInfo)) _CacheList.Remove(rOImageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ROImageInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ROImageInfo tmp = _CacheList[0]; // Get the first ROImageInfo + string pKey = tmp.ImageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ROImageInfo + } + } + internal static void AddList(ROImageInfoList lst) + { + foreach (ROImageInfo item in lst) AddToCache(item); + } + protected static ROImageInfo GetCachedByPrimaryKey(int imageID) + { + ConvertListToDictionary(); + string key = imageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ROImage _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODbInfo _MyRODb; + public RODbInfo MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); + return _MyRODb; + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + } + private byte[] _Content; + public byte[] Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ROImageFigureCount = 0; + /// + /// Count of ROImageFigures for this ROImage + /// + public int ROImageFigureCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROImageFigureCount < 0) + _ROImageFigureCount = ROImageFigures.Count; + return _ROImageFigureCount; + } + } + private FigureInfoList _ROImageFigures = null; + [TypeConverter(typeof(FigureInfoListConverter))] + public FigureInfoList ROImageFigures + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROImageFigureCount < 0 || (_ROImageFigureCount > 0 && _ROImageFigures == null)) + _ROImageFigures = FigureInfoList.GetByImageID(_ImageID); + if (_ROImageFigureCount < 0) + _ROImageFigureCount = _ROImageFigures.Count; + return _ROImageFigures; + } + } + public void RefreshROImageFigures() + { + _ROImageFigureCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ImageID.ToString())) + foreach (ROImageInfo tmp in _CacheByPrimaryKey[_ImageID.ToString()]) + tmp._ROImageFigureCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base ROImageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROImageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ROImageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROImageInfo + protected override object GetIdValue() + { + return MyROImageInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ROImageInfoUnique = 0; + private static int ROImageInfoUnique + { get { return ++_ROImageInfoUnique; } } + private int _MyROImageInfoUnique = ROImageInfoUnique; + public int MyROImageInfoUnique // Absolutely Unique ID - Info + { get { return _MyROImageInfoUnique; } } + protected ROImageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ROImageInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + _Content = null; // to clear content from memory + _Config = null; // to clear config from memory + if (!_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) return; + List listROImageInfo = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items + while (listROImageInfo.Contains(this)) listROImageInfo.Remove(this); // Remove the item from the list + if (listROImageInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list + } + public virtual ROImage Get() + { + return _Editable = ROImage.GetJustROImage(_ImageID);//Don't load figures or ROFST - Causing Memory Crash + } + public static void Refresh(ROImage tmp) + { + string key = tmp.ImageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROImage tmp) + { + if (_RODbID != tmp.RODbID) + { + if (MyRODb != null) MyRODb.RefreshRODbROImages(); // 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.RefreshRODbROImages(); // Update List for new value + _FileName = tmp.FileName; + _Content = tmp.Content; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROImageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RODbROImage tmp) + { + string key = tmp.ImageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODbROImage tmp) + { + _FileName = tmp.FileName; + _Content = tmp.Content; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROImageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ROImageInfo Get(int imageID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ROImage"); + try + { + ROImageInfo tmp = GetCachedByPrimaryKey(imageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROImageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ROImageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.Constructor", ex); + throw new DbCslaException("ROImageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ImageID; + public int ImageID + { get { return _ImageID; } } + public PKCriteria(int imageID) + { + _ImageID = imageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.ReadData", GetHashCode()); + try + { + _ImageID = dr.GetInt32("ImageID"); + _RODbID = dr.GetInt32("RODbID"); + _FileName = dr.GetString("FileName"); + _Content = (byte[])dr.GetValue("Content"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _ROImageFigureCount = dr.GetInt32("FigureCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROImage"; + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ROImageInfoExtension _ROImageInfoExtension = new ROImageInfoExtension(); + [Serializable()] + partial class ROImageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ROImageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ROImageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROImageInfo) + { + // Return the ToString value + return ((ROImageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs index 6569121c..72df59b0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Revision.cs @@ -20,1232 +20,1211 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Revision Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RevisionConverter))] - public partial class Revision : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshRevisions = new List(); - private List _RefreshRevisionChecks = new List(); - private List _RefreshRevisionVersions = new List(); - private void AddToRefreshList(List refreshRevisions, List refreshRevisionChecks, List refreshRevisionVersions) - { - if (IsDirty) - refreshRevisions.Add(this); - if (_RevisionChecks != null && _RevisionChecks.IsDirty) - { - foreach (RevisionCheck tmp in _RevisionChecks) - { - if (tmp.IsDirty) refreshRevisionChecks.Add(tmp); - } - } - if (_RevisionVersions != null && _RevisionVersions.IsDirty) - { - foreach (RevisionVersion tmp in _RevisionVersions) - { - if (tmp.IsDirty) refreshRevisionVersions.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshRevisions = new List(); - _RefreshRevisionChecks = new List(); - _RefreshRevisionVersions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshRevisions, _RefreshRevisionChecks, _RefreshRevisionVersions); - } - private void ProcessRefreshList() - { - foreach (Revision tmp in _RefreshRevisions) - { - RevisionInfo.Refresh(tmp); - } - foreach (RevisionCheck tmp in _RefreshRevisionChecks) - { - CheckInfo.Refresh(tmp); - } - foreach (RevisionVersion tmp in _RefreshRevisionVersions) - { - VersionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Revision revision) - { - if (!_CacheList.Contains(revision)) _CacheList.Add(revision); // In AddToCache - } - protected static void RemoveFromCache(Revision revision) - { - while (_CacheList.Contains(revision)) _CacheList.Remove(revision); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Revision(s) from temporary _CacheList to _CacheByPrimaryKey - { - Revision tmp = _CacheList[0]; // Get the first Revision - string pKey = tmp.RevisionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Revision - } - } - protected static Revision GetCachedByPrimaryKey(int revisionID) - { - ConvertListToDictionary(); - string key = revisionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextRevisionID = -1; - public static int NextRevisionID - { - get { return _nextRevisionID--; } - } - private int _RevisionID; - [System.ComponentModel.DataObjectField(true, true)] - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - return _RevisionID; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemID", true); - if (_ItemID != value) - { - _ItemID = value; - PropertyHasChanged(); - } - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - return _TypeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TypeID", true); - if (_TypeID != value) - { - _TypeID = value; - PropertyHasChanged(); - } - } - } - private string _RevisionNumber = string.Empty; - public string RevisionNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionNumber", true); - return _RevisionNumber; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("RevisionNumber", true); - if (value == null) value = string.Empty; - if (_RevisionNumber != value) - { - _RevisionNumber = value; - PropertyHasChanged(); - } - } - } - private DateTime? _RevisionDate; - public DateTime? RevisionDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionDate", true); - return _RevisionDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("RevisionDate", true); - if (_RevisionDate != value) - { - _RevisionDate = value; - PropertyHasChanged(); - } - } - } - private string _Notes = string.Empty; - public string Notes - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Notes", true); - return _Notes; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Notes", true); - if (value == null) value = string.Empty; - if (_Notes != value) - { - _Notes = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RevisionCheckCount = 0; - /// - /// Count of RevisionChecks for this Revision - /// - public int RevisionCheckCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionCheckCount", true); - return _RevisionCheckCount; - } - } - private RevisionChecks _RevisionChecks = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RevisionChecksConverter))] - public RevisionChecks RevisionChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionChecks", true); - if (_RevisionCheckCount < 0 || (_RevisionCheckCount > 0 && _RevisionChecks == null)) - _RevisionChecks = RevisionChecks.GetByRevisionID(RevisionID); - if (_RevisionCheckCount < 0 ) - _RevisionCheckCount = _RevisionChecks == null ? 0 : _RevisionChecks.Count; - if (_RevisionChecks == null) - _RevisionChecks = RevisionChecks.New(); - return _RevisionChecks; - } - } - public void Reset_RevisionChecks() - { - _RevisionCheckCount = -1; - } - private int _RevisionVersionCount = 0; - /// - /// Count of RevisionVersions for this Revision - /// - public int RevisionVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionVersionCount", true); - return _RevisionVersionCount; - } - } - private RevisionVersions _RevisionVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RevisionVersionsConverter))] - public RevisionVersions RevisionVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionVersions", true); - if (_RevisionVersionCount < 0 || (_RevisionVersionCount > 0 && _RevisionVersions == null)) - _RevisionVersions = RevisionVersions.GetByRevisionID(RevisionID); - if (_RevisionVersionCount < 0 ) - _RevisionVersionCount = _RevisionVersions == null ? 0 : _RevisionVersions.Count; - if (_RevisionVersions == null) - _RevisionVersions = RevisionVersions.New(); - return _RevisionVersions; - } - } - public void Reset_RevisionVersions() - { - _RevisionVersionCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_RevisionChecks == null ? false : _RevisionChecks.IsDirtyList(list)) || (_RevisionVersions == null ? false : _RevisionVersions.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RevisionChecks == null ? true : _RevisionChecks.IsValidList(list)) && (_RevisionVersions == null ? true : _RevisionVersions.IsValidList(list)); - } - // CSLATODO: Replace base Revision.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Revision - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Revision.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Revision - protected override object GetIdValue() - { - return MyRevisionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_RevisionChecks != null && (hasBrokenRules = _RevisionChecks.HasBrokenRules) != null) return hasBrokenRules; - if (_RevisionVersions != null && (hasBrokenRules = _RevisionVersions.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("RevisionNumber", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Notes", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _RevisionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _RevisionExtension.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(RevisionID, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(TypeID, ""); - //AuthorizationRules.AllowRead(RevisionNumber, ""); - //AuthorizationRules.AllowRead(RevisionDate, ""); - //AuthorizationRules.AllowRead(Notes, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(TypeID, ""); - //AuthorizationRules.AllowWrite(RevisionNumber, ""); - //AuthorizationRules.AllowWrite(RevisionDate, ""); - //AuthorizationRules.AllowWrite(Notes, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _RevisionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _RevisionExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _RevisionCheckCount; - usedByCount += _RevisionVersionCount; - 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; } } - private static int _RevisionUnique = 0; - protected static int RevisionUnique - { get { return ++_RevisionUnique; } } - private int _MyRevisionUnique = RevisionUnique; - public int MyRevisionUnique // Absolutely Unique ID - Editable - { get { return _MyRevisionUnique; } } - protected Revision() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Revision() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(RevisionID.ToString())) - { - List listRevision = _CacheByPrimaryKey[RevisionID.ToString()]; // Get the list of items - while (listRevision.Contains(this)) listRevision.Remove(this); // Remove the item from the list - if (listRevision.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(RevisionID.ToString()); // remove the list - } - } - public static Revision New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Revision"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Revision.New", ex); - } - } - public static Revision New(int itemID) - { - Revision tmp = Revision.New(); - tmp.ItemID = itemID; - return tmp; - } - public static Revision New(int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID) - { - Revision tmp = Revision.New(); - tmp.ItemID = itemID; - tmp.TypeID = typeID; - tmp.RevisionNumber = revisionNumber; - tmp.RevisionDate = revisionDate; - tmp.Notes = notes; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Revision MakeRevision(int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID) - { - Revision tmp = Revision.New(itemID, typeID, revisionNumber, revisionDate, notes, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Revision New(int itemID, string revisionNumber, DateTime? revisionDate, string notes, string config) - { - Revision tmp = Revision.New(); - tmp.ItemID = itemID; - tmp.RevisionNumber = revisionNumber; - tmp.RevisionDate = revisionDate; - tmp.Notes = notes; - tmp.Config = config; - return tmp; - } - public static Revision MakeRevision(int itemID, string revisionNumber, DateTime? revisionDate, string notes, string config) - { - Revision tmp = Revision.New(itemID, revisionNumber, revisionDate, notes, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Revision Get(int revisionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Revision"); - try - { - Revision tmp = GetCachedByPrimaryKey(revisionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(revisionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Revision - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Revision.Get", ex); - } - } - public static Revision Get(SafeDataReader dr) - { - if (dr.Read()) return new Revision(dr); - return null; - } - internal Revision(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int revisionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Revision"); - try - { - DataPortal.Delete(new PKCriteria(revisionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Revision.Delete", ex); - } - } - public override Revision Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Revision"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Revision"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Revision"); - try - { - BuildRefreshList(); - Revision revision = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(revision);//Refresh the item in AllList - ProcessRefreshList(); - return revision; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _RevisionID; - public int RevisionID - { get { return _RevisionID; } } - public PKCriteria(int revisionID) - { - _RevisionID = revisionID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _RevisionID = NextRevisionID; - // Database Defaults - _TypeID = _RevisionExtension.DefaultTypeID; - _DTS = _RevisionExtension.DefaultDTS; - _UserID = _RevisionExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.ReadData", GetHashCode()); - try - { - _RevisionID = dr.GetInt32("RevisionID"); - _ItemID = dr.GetInt32("ItemID"); - _TypeID = dr.GetInt32("TypeID"); - _RevisionNumber = dr.GetString("RevisionNumber"); - if (!dr.IsDBNull(dr.GetOrdinal("RevisionDate"))) _RevisionDate = dr.GetDateTime("RevisionDate"); - _Notes = dr.GetString("Notes"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RevisionCheckCount = dr.GetInt32("CheckCount"); - _RevisionVersionCount = dr.GetInt32("VersionCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Revision.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRevision"; - cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _RevisionChecks = RevisionChecks.Get(dr); - // load child objects - dr.NextResult(); - _RevisionVersions = RevisionVersions.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Revision.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Revision.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRevision"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ItemID", _ItemID); - cm.Parameters.AddWithValue("@TypeID", _TypeID); - cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); - if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); - cm.Parameters.AddWithValue("@Notes", _Notes); - 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_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int); - param_RevisionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RevisionID); - 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 - _RevisionID = (int)cm.Parameters["@newRevisionID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_RevisionChecks != null) _RevisionChecks.Update(this); - if (_RevisionVersions != null) _RevisionVersions.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Revision.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRevision"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ItemID", itemID); - cm.Parameters.AddWithValue("@TypeID", typeID); - cm.Parameters.AddWithValue("@RevisionNumber", revisionNumber); - if (revisionDate != null && ((DateTime)revisionDate).Year >= 1753 && ((DateTime)revisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", revisionDate); - cm.Parameters.AddWithValue("@Notes", notes); - 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_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int); - param_RevisionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RevisionID); - 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 - revisionID = (int)cm.Parameters["@newRevisionID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Add", ex); - throw new DbCslaException("Revision.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Revision.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRevision"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RevisionID", _RevisionID); - cm.Parameters.AddWithValue("@ItemID", _ItemID); - cm.Parameters.AddWithValue("@TypeID", _TypeID); - cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); - if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); - cm.Parameters.AddWithValue("@Notes", _Notes); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_RevisionChecks != null) _RevisionChecks.Update(this); - if (_RevisionVersions != null) _RevisionVersions.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Revision.Add(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID); - else - _LastChanged = Revision.Update(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_RevisionChecks != null) _RevisionChecks.Update(this); - if (_RevisionVersions != null) _RevisionVersions.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRevision"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RevisionID", revisionID); - cm.Parameters.AddWithValue("@ItemID", itemID); - cm.Parameters.AddWithValue("@TypeID", typeID); - cm.Parameters.AddWithValue("@RevisionNumber", revisionNumber); - if (revisionDate != null && ((DateTime)revisionDate).Year >= 1753 && ((DateTime)revisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", revisionDate); - cm.Parameters.AddWithValue("@Notes", notes); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Update", ex); - throw new DbCslaException("Revision.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_RevisionID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRevision"; - cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Revision.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int revisionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRevision"; - // Input PK Fields - cm.Parameters.AddWithValue("@RevisionID", revisionID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Remove", ex); - throw new DbCslaException("Revision.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int revisionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(revisionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Revision.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _RevisionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int revisionID) - { - _RevisionID = revisionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsRevision"; - cm.Parameters.AddWithValue("@RevisionID", _RevisionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Execute", ex); - throw new DbCslaException("Revision.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - RevisionExtension _RevisionExtension = new RevisionExtension(); - [Serializable()] - partial class RevisionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultTypeID - { - get { return 1; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RevisionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Revision) - { - // Return the ToString value - return ((Revision)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Revision Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionConverter))] + public partial class Revision : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRevisions = new List(); + private List _RefreshRevisionChecks = new List(); + private List _RefreshRevisionVersions = new List(); + private void AddToRefreshList(List refreshRevisions, List refreshRevisionChecks, List refreshRevisionVersions) + { + if (IsDirty) + refreshRevisions.Add(this); + if (_RevisionChecks != null && _RevisionChecks.IsDirty) + { + foreach (RevisionCheck tmp in _RevisionChecks) + { + if (tmp.IsDirty) refreshRevisionChecks.Add(tmp); + } + } + if (_RevisionVersions != null && _RevisionVersions.IsDirty) + { + foreach (RevisionVersion tmp in _RevisionVersions) + { + if (tmp.IsDirty) refreshRevisionVersions.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshRevisions = new List(); + _RefreshRevisionChecks = new List(); + _RefreshRevisionVersions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshRevisions, _RefreshRevisionChecks, _RefreshRevisionVersions); + } + private void ProcessRefreshList() + { + foreach (Revision tmp in _RefreshRevisions) + { + RevisionInfo.Refresh(tmp); + } + foreach (RevisionCheck tmp in _RefreshRevisionChecks) + { + CheckInfo.Refresh(tmp); + } + foreach (RevisionVersion tmp in _RefreshRevisionVersions) + { + VersionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Revision revision) + { + if (!_CacheList.Contains(revision)) _CacheList.Add(revision); // In AddToCache + } + protected static void RemoveFromCache(Revision revision) + { + while (_CacheList.Contains(revision)) _CacheList.Remove(revision); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Revision(s) from temporary _CacheList to _CacheByPrimaryKey + { + Revision tmp = _CacheList[0]; // Get the first Revision + string pKey = tmp.RevisionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Revision + } + } + protected static Revision GetCachedByPrimaryKey(int revisionID) + { + ConvertListToDictionary(); + string key = revisionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextRevisionID = -1; + public static int NextRevisionID + { + get { return _nextRevisionID--; } + } + private int _RevisionID; + [System.ComponentModel.DataObjectField(true, true)] + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemID != value) + { + _ItemID = value; + PropertyHasChanged(); + } + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TypeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TypeID != value) + { + _TypeID = value; + PropertyHasChanged(); + } + } + } + private string _RevisionNumber = string.Empty; + public string RevisionNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionNumber; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_RevisionNumber != value) + { + _RevisionNumber = value; + PropertyHasChanged(); + } + } + } + private DateTime? _RevisionDate; + public DateTime? RevisionDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_RevisionDate != value) + { + _RevisionDate = value; + PropertyHasChanged(); + } + } + } + private string _Notes = string.Empty; + public string Notes + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Notes; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Notes != value) + { + _Notes = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RevisionCheckCount = 0; + /// + /// Count of RevisionChecks for this Revision + /// + public int RevisionCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionCheckCount; + } + } + private RevisionChecks _RevisionChecks = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RevisionChecksConverter))] + public RevisionChecks RevisionChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RevisionCheckCount < 0 || (_RevisionCheckCount > 0 && _RevisionChecks == null)) + _RevisionChecks = RevisionChecks.GetByRevisionID(RevisionID); + if (_RevisionCheckCount < 0) + _RevisionCheckCount = _RevisionChecks == null ? 0 : _RevisionChecks.Count; + if (_RevisionChecks == null) + _RevisionChecks = RevisionChecks.New(); + return _RevisionChecks; + } + } + public void Reset_RevisionChecks() + { + _RevisionCheckCount = -1; + } + private int _RevisionVersionCount = 0; + /// + /// Count of RevisionVersions for this Revision + /// + public int RevisionVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionVersionCount; + } + } + private RevisionVersions _RevisionVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RevisionVersionsConverter))] + public RevisionVersions RevisionVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RevisionVersionCount < 0 || (_RevisionVersionCount > 0 && _RevisionVersions == null)) + _RevisionVersions = RevisionVersions.GetByRevisionID(RevisionID); + if (_RevisionVersionCount < 0) + _RevisionVersionCount = _RevisionVersions == null ? 0 : _RevisionVersions.Count; + if (_RevisionVersions == null) + _RevisionVersions = RevisionVersions.New(); + return _RevisionVersions; + } + } + public void Reset_RevisionVersions() + { + _RevisionVersionCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_RevisionChecks == null ? false : _RevisionChecks.IsDirtyList(list)) || (_RevisionVersions == null ? false : _RevisionVersions.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RevisionChecks == null ? true : _RevisionChecks.IsValidList(list)) && (_RevisionVersions == null ? true : _RevisionVersions.IsValidList(list)); + } + // CSLATODO: Replace base Revision.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Revision + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Revision.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Revision + protected override object GetIdValue() + { + return MyRevisionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_RevisionChecks != null && (hasBrokenRules = _RevisionChecks.HasBrokenRules) != null) return hasBrokenRules; + if (_RevisionVersions != null && (hasBrokenRules = _RevisionVersions.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("RevisionNumber", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Notes", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _RevisionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _RevisionExtension.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(RevisionID, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowRead(RevisionNumber, ""); + //AuthorizationRules.AllowRead(RevisionDate, ""); + //AuthorizationRules.AllowRead(Notes, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(TypeID, ""); + //AuthorizationRules.AllowWrite(RevisionNumber, ""); + //AuthorizationRules.AllowWrite(RevisionDate, ""); + //AuthorizationRules.AllowWrite(Notes, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _RevisionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _RevisionExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _RevisionCheckCount; + usedByCount += _RevisionVersionCount; + 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; } } + private static int _RevisionUnique = 0; + protected static int RevisionUnique + { get { return ++_RevisionUnique; } } + private int _MyRevisionUnique = RevisionUnique; + public int MyRevisionUnique // Absolutely Unique ID - Editable + { get { return _MyRevisionUnique; } } + protected Revision() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Revision() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(RevisionID.ToString())) + { + List listRevision = _CacheByPrimaryKey[RevisionID.ToString()]; // Get the list of items + while (listRevision.Contains(this)) listRevision.Remove(this); // Remove the item from the list + if (listRevision.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(RevisionID.ToString()); // remove the list + } + } + public static Revision New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Revision"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Revision.New", ex); + } + } + public static Revision New(int itemID) + { + Revision tmp = Revision.New(); + tmp.ItemID = itemID; + return tmp; + } + public static Revision New(int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID) + { + Revision tmp = Revision.New(); + tmp.ItemID = itemID; + tmp.TypeID = typeID; + tmp.RevisionNumber = revisionNumber; + tmp.RevisionDate = revisionDate; + tmp.Notes = notes; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Revision MakeRevision(int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID) + { + Revision tmp = Revision.New(itemID, typeID, revisionNumber, revisionDate, notes, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Revision New(int itemID, string revisionNumber, DateTime? revisionDate, string notes, string config) + { + Revision tmp = Revision.New(); + tmp.ItemID = itemID; + tmp.RevisionNumber = revisionNumber; + tmp.RevisionDate = revisionDate; + tmp.Notes = notes; + tmp.Config = config; + return tmp; + } + public static Revision MakeRevision(int itemID, string revisionNumber, DateTime? revisionDate, string notes, string config) + { + Revision tmp = Revision.New(itemID, revisionNumber, revisionDate, notes, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Revision Get(int revisionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Revision"); + try + { + Revision tmp = GetCachedByPrimaryKey(revisionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(revisionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Revision + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Revision.Get", ex); + } + } + public static Revision Get(SafeDataReader dr) + { + if (dr.Read()) return new Revision(dr); + return null; + } + internal Revision(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int revisionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Revision"); + try + { + DataPortal.Delete(new PKCriteria(revisionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Revision.Delete", ex); + } + } + public override Revision Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Revision"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Revision"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Revision"); + try + { + BuildRefreshList(); + Revision revision = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(revision);//Refresh the item in AllList + ProcessRefreshList(); + return revision; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _RevisionID; + public int RevisionID + { get { return _RevisionID; } } + public PKCriteria(int revisionID) + { + _RevisionID = revisionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _RevisionID = NextRevisionID; + // Database Defaults + _TypeID = _RevisionExtension.DefaultTypeID; + _DTS = _RevisionExtension.DefaultDTS; + _UserID = _RevisionExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.ReadData", GetHashCode()); + try + { + _RevisionID = dr.GetInt32("RevisionID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RevisionNumber = dr.GetString("RevisionNumber"); + if (!dr.IsDBNull(dr.GetOrdinal("RevisionDate"))) _RevisionDate = dr.GetDateTime("RevisionDate"); + _Notes = dr.GetString("Notes"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RevisionCheckCount = dr.GetInt32("CheckCount"); + _RevisionVersionCount = dr.GetInt32("VersionCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Revision.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRevision"; + cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _RevisionChecks = RevisionChecks.Get(dr); + // load child objects + dr.NextResult(); + _RevisionVersions = RevisionVersions.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Revision.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Revision.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRevision"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); + if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); + cm.Parameters.AddWithValue("@Notes", _Notes); + 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_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int); + param_RevisionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RevisionID); + 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 + _RevisionID = (int)cm.Parameters["@newRevisionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_RevisionChecks != null) _RevisionChecks.Update(this); + if (_RevisionVersions != null) _RevisionVersions.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Revision.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRevision"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@TypeID", typeID); + cm.Parameters.AddWithValue("@RevisionNumber", revisionNumber); + if (revisionDate != null && ((DateTime)revisionDate).Year >= 1753 && ((DateTime)revisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", revisionDate); + cm.Parameters.AddWithValue("@Notes", notes); + 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_RevisionID = new SqlParameter("@newRevisionID", SqlDbType.Int); + param_RevisionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RevisionID); + 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 + revisionID = (int)cm.Parameters["@newRevisionID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Add", ex); + throw new DbCslaException("Revision.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Revision.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRevision"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RevisionID", _RevisionID); + cm.Parameters.AddWithValue("@ItemID", _ItemID); + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@RevisionNumber", _RevisionNumber); + if (_RevisionDate != null && ((DateTime)_RevisionDate).Year >= 1753 && ((DateTime)_RevisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", _RevisionDate); + cm.Parameters.AddWithValue("@Notes", _Notes); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_RevisionChecks != null) _RevisionChecks.Update(this); + if (_RevisionVersions != null) _RevisionVersions.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Revision.Add(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID); + else + _LastChanged = Revision.Update(cn, ref _RevisionID, _ItemID, _TypeID, _RevisionNumber, _RevisionDate, _Notes, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_RevisionChecks != null) _RevisionChecks.Update(this); + if (_RevisionVersions != null) _RevisionVersions.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int revisionID, int itemID, int typeID, string revisionNumber, DateTime? revisionDate, string notes, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRevision"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", revisionID); + cm.Parameters.AddWithValue("@ItemID", itemID); + cm.Parameters.AddWithValue("@TypeID", typeID); + cm.Parameters.AddWithValue("@RevisionNumber", revisionNumber); + if (revisionDate != null && ((DateTime)revisionDate).Year >= 1753 && ((DateTime)revisionDate).Year <= 9999) cm.Parameters.AddWithValue("@RevisionDate", revisionDate); + cm.Parameters.AddWithValue("@Notes", notes); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Update", ex); + throw new DbCslaException("Revision.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_RevisionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRevision"; + cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Revision.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int revisionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRevision"; + // Input PK Fields + cm.Parameters.AddWithValue("@RevisionID", revisionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.Remove", ex); + throw new DbCslaException("Revision.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int revisionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(revisionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Revision.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _RevisionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int revisionID) + { + _RevisionID = revisionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Revision.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsRevision"; + cm.Parameters.AddWithValue("@RevisionID", _RevisionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Revision.DataPortal_Execute", ex); + throw new DbCslaException("Revision.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + RevisionExtension _RevisionExtension = new RevisionExtension(); + [Serializable()] + partial class RevisionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultTypeID + { + get { return 1; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RevisionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Revision) + { + // Return the ToString value + return ((Revision)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs index b2945bb7..3f229c9b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionCheck.cs @@ -20,516 +20,500 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RevisionCheck Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RevisionCheckConverter))] - public partial class RevisionCheck : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _CheckID; - [System.ComponentModel.DataObjectField(true, true)] - public int CheckID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CheckID", true); - if (_MyCheck != null) _CheckID = _MyCheck.CheckID; - return _CheckID; - } - } - private Check _MyCheck; - [System.ComponentModel.DataObjectField(true, true)] - public Check MyCheck - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyCheck", true); - if (_MyCheck == null && _CheckID != 0) _MyCheck = Check.Get(_CheckID); - return _MyCheck; - } - } - private int _StageID; - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - if (_MyStage != null) _StageID = _MyStage.StageID; - return _StageID; - } - } - private Stage _MyStage; - public Stage MyStage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyStage", true); - if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); - return _MyStage; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyStage", true); - if (_MyStage != value) - { - _MyStage = value; - _StageID = value.StageID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _ConsistencyChecks = string.Empty; - public string ConsistencyChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConsistencyChecks", true); - return _ConsistencyChecks; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ConsistencyChecks", true); - if (value == null) value = string.Empty; - if (_ConsistencyChecks != value) - { - _ConsistencyChecks = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Stage_Name = string.Empty; - public string Stage_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_Name", true); - return _Stage_Name; - } - } - private string _Stage_Description = string.Empty; - public string Stage_Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_Description", true); - return _Stage_Description; - } - } - private int _Stage_IsApproved; - public int Stage_IsApproved - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_IsApproved", true); - return _Stage_IsApproved; - } - } - private DateTime _Stage_DTS = new DateTime(); - public DateTime Stage_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_DTS", true); - return _Stage_DTS; - } - } - private string _Stage_UserID = string.Empty; - public string Stage_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_UserID", true); - return _Stage_UserID; - } - } - // CSLATODO: Check RevisionCheck.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RevisionCheck - protected override object GetIdValue() - { - return MyRevisionCheckUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RevisionCheck.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RevisionCheck - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyStage == null ? true : _MyStage.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyStageRequired, "MyStage"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyStageRequired(RevisionCheck target, Csla.Validation.RuleArgs e) - { - if (target._StageID == 0 && target._MyStage == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(CheckID, ""); - //AuthorizationRules.AllowRead(StageID, ""); - //AuthorizationRules.AllowWrite(StageID, ""); - //AuthorizationRules.AllowRead(ConsistencyChecks, ""); - //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _RevisionCheckUnique = 0; - private static int RevisionCheckUnique - { get { return ++_RevisionCheckUnique; } } - private int _MyRevisionCheckUnique = RevisionCheckUnique; - public int MyRevisionCheckUnique // Absolutely Unique ID - Editable FK - { get { return _MyRevisionCheckUnique; } } - internal static RevisionCheck New(Stage myStage) - { - return new RevisionCheck(myStage); - } - internal static RevisionCheck Get(SafeDataReader dr) - { - return new RevisionCheck(dr); - } - public RevisionCheck() - { - MarkAsChild(); - _CheckID = Check.NextCheckID; - _DTS = _RevisionCheckExtension.DefaultDTS; - _UserID = _RevisionCheckExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RevisionCheck(Stage myStage) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _CheckID = Check.NextCheckID; - _DTS = _RevisionCheckExtension.DefaultDTS; - _UserID = _RevisionCheckExtension.DefaultUserID; - _MyStage = myStage; - ValidationRules.CheckRules(); - } - internal RevisionCheck(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RevisionCheck() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionCheck.FetchDR", GetHashCode()); - try - { - _CheckID = dr.GetInt32("CheckID"); - _StageID = dr.GetInt32("StageID"); - _ConsistencyChecks = dr.GetString("ConsistencyChecks"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Stage_Name = dr.GetString("Stage_Name"); - _Stage_Description = dr.GetString("Stage_Description"); - _Stage_IsApproved = dr.GetInt32("Stage_IsApproved"); - _Stage_DTS = dr.GetDateTime("Stage_DTS"); - _Stage_UserID = dr.GetString("Stage_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionCheck.FetchDR", ex); - throw new DbCslaException("RevisionCheck.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Revision myRevision) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Check.Add(cn, ref _CheckID, myRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); - MarkOld(); - } - internal void Update(Revision myRevision) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Check.Update(cn, ref _CheckID, myRevision.RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Revision myRevision) - { - // 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"]; - Check.Remove(cn, _CheckID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RevisionCheckExtension _RevisionCheckExtension = new RevisionCheckExtension(); - [Serializable()] - partial class RevisionCheckExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RevisionCheckConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RevisionCheck) - { - // Return the ToString value - return ((RevisionCheck)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RevisionCheck Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionCheckConverter))] + public partial class RevisionCheck : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _CheckID; + [System.ComponentModel.DataObjectField(true, true)] + public int CheckID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyCheck != null) _CheckID = _MyCheck.CheckID; + return _CheckID; + } + } + private Check _MyCheck; + [System.ComponentModel.DataObjectField(true, true)] + public Check MyCheck + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyCheck == null && _CheckID != 0) _MyCheck = Check.Get(_CheckID); + return _MyCheck; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConsistencyChecks; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ConsistencyChecks != value) + { + _ConsistencyChecks = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Stage_Name = string.Empty; + public string Stage_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_Name; + } + } + private string _Stage_Description = string.Empty; + public string Stage_Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_Description; + } + } + private int _Stage_IsApproved; + public int Stage_IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_IsApproved; + } + } + private DateTime _Stage_DTS = new DateTime(); + public DateTime Stage_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_DTS; + } + } + private string _Stage_UserID = string.Empty; + public string Stage_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_UserID; + } + } + // CSLATODO: Check RevisionCheck.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RevisionCheck + protected override object GetIdValue() + { + return MyRevisionCheckUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RevisionCheck.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RevisionCheck + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyStageRequired(RevisionCheck target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(CheckID, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowRead(ConsistencyChecks, ""); + //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _RevisionCheckUnique = 0; + private static int RevisionCheckUnique + { get { return ++_RevisionCheckUnique; } } + private int _MyRevisionCheckUnique = RevisionCheckUnique; + public int MyRevisionCheckUnique // Absolutely Unique ID - Editable FK + { get { return _MyRevisionCheckUnique; } } + internal static RevisionCheck New(Stage myStage) + { + return new RevisionCheck(myStage); + } + internal static RevisionCheck Get(SafeDataReader dr) + { + return new RevisionCheck(dr); + } + public RevisionCheck() + { + MarkAsChild(); + _CheckID = Check.NextCheckID; + _DTS = _RevisionCheckExtension.DefaultDTS; + _UserID = _RevisionCheckExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RevisionCheck(Stage myStage) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _CheckID = Check.NextCheckID; + _DTS = _RevisionCheckExtension.DefaultDTS; + _UserID = _RevisionCheckExtension.DefaultUserID; + _MyStage = myStage; + ValidationRules.CheckRules(); + } + internal RevisionCheck(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RevisionCheck() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionCheck.FetchDR", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _StageID = dr.GetInt32("StageID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Stage_Name = dr.GetString("Stage_Name"); + _Stage_Description = dr.GetString("Stage_Description"); + _Stage_IsApproved = dr.GetInt32("Stage_IsApproved"); + _Stage_DTS = dr.GetDateTime("Stage_DTS"); + _Stage_UserID = dr.GetString("Stage_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionCheck.FetchDR", ex); + throw new DbCslaException("RevisionCheck.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Add(cn, ref _CheckID, myRevision, _MyStage, _ConsistencyChecks, _DTS, _UserID); + MarkOld(); + } + internal void Update(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Update(cn, ref _CheckID, myRevision.RevisionID, _StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Revision myRevision) + { + // 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"]; + Check.Remove(cn, _CheckID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RevisionCheckExtension _RevisionCheckExtension = new RevisionCheckExtension(); + [Serializable()] + partial class RevisionCheckExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RevisionCheckConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionCheck) + { + // Return the ToString value + return ((RevisionCheck)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs index 73675986..02632fb9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionInfo.cs @@ -19,481 +19,468 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void RevisionInfoEvent(object sender); - /// - /// RevisionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RevisionInfoConverter))] - public partial class RevisionInfo : ReadOnlyBase, IDisposable - { - public event RevisionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RevisionInfo revisionInfo) - { - if (!_CacheList.Contains(revisionInfo)) _CacheList.Add(revisionInfo); // In AddToCache - } - protected static void RemoveFromCache(RevisionInfo revisionInfo) - { - while (_CacheList.Contains(revisionInfo)) _CacheList.Remove(revisionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move RevisionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - RevisionInfo tmp = _CacheList[0]; // Get the first RevisionInfo - string pKey = tmp.RevisionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first RevisionInfo - } - } - internal static void AddList(RevisionInfoList lst) - { - foreach (RevisionInfo item in lst) AddToCache(item); - } - protected static RevisionInfo GetCachedByPrimaryKey(int revisionID) - { - ConvertListToDictionary(); - string key = revisionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Revision _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _RevisionID; - [System.ComponentModel.DataObjectField(true, true)] - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - return _RevisionID; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - return _TypeID; - } - } - private string _RevisionNumber = string.Empty; - public string RevisionNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionNumber", true); - return _RevisionNumber; - } - } - private DateTime? _RevisionDate; - public DateTime? RevisionDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionDate", true); - return _RevisionDate; - } - } - private string _Notes = string.Empty; - public string Notes - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Notes", true); - return _Notes; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _RevisionCheckCount = 0; - /// - /// Count of RevisionChecks for this Revision - /// - public int RevisionCheckCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionCheckCount", true); - if (_RevisionCheckCount < 0) - _RevisionCheckCount = RevisionChecks.Count; - return _RevisionCheckCount; - } - } - private CheckInfoList _RevisionChecks = null; - [TypeConverter(typeof(CheckInfoListConverter))] - public CheckInfoList RevisionChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionChecks", true); - if (_RevisionCheckCount < 0 || (_RevisionCheckCount > 0 && _RevisionChecks == null)) - _RevisionChecks = CheckInfoList.GetByRevisionID(_RevisionID); - if (_RevisionCheckCount < 0) - _RevisionCheckCount = _RevisionChecks.Count; - return _RevisionChecks; - } - } - public void RefreshRevisionChecks() - { - _RevisionCheckCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RevisionID.ToString())) - foreach (RevisionInfo tmp in _CacheByPrimaryKey[_RevisionID.ToString()]) - tmp._RevisionCheckCount = -1; // This will cause the data to be requeried - } - private int _RevisionVersionCount = 0; - /// - /// Count of RevisionVersions for this Revision - /// - public int RevisionVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionVersionCount", true); - //_MyLog.WarnFormat("RevisionVersionCount 1 - {0}", GC.GetTotalMemory(true)); - if (_RevisionVersionCount < 0) - { - _RevisionVersionCount = RevisionVersions.Count; - //_MyLog.WarnFormat("RevisionVersionCount 2 (after setting count) - {0}", GC.GetTotalMemory(true)); - } - //_MyLog.WarnFormat("RevisionVersionCount 3 (before return) - {0}", GC.GetTotalMemory(true)); - return _RevisionVersionCount; - } - } - private VersionInfoList _RevisionVersions = null; - [TypeConverter(typeof(VersionInfoListConverter))] - public VersionInfoList RevisionVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionVersions", true); - //_MyLog.WarnFormat("RevisionVersions 1 - {0}", GC.GetTotalMemory(true)); - if (_RevisionVersionCount < 0 || (_RevisionVersionCount > 0 && _RevisionVersions == null)) - { - //_MyLog.WarnFormat("RevisionVersions 2 (before using) - {0} count {1}", GC.GetTotalMemory(true),_RevisionVersionCount); - using (VersionInfoList vil = VersionInfoList.GetByRevisionID(_RevisionID)) - { - //_MyLog.WarnFormat("RevisionVersions 3 (using) - {0}", GC.GetTotalMemory(true)); - _RevisionVersions = vil; - } - } - //_MyLog.WarnFormat("RevisionVersions 4 (after using) - {0}", GC.GetTotalMemory(true)); - if (_RevisionVersionCount < 0) - { - _RevisionVersionCount = _RevisionVersions.Count; - //_MyLog.WarnFormat("RevisionVersions 4 (after setting count) - {0}", GC.GetTotalMemory(true)); - } - //_MyLog.WarnFormat("RevisionVersions 5 (before return) - {0}", GC.GetTotalMemory(true)); - return _RevisionVersions; - } - } - public void RefreshRevisionVersions() - { - _RevisionVersionCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RevisionID.ToString())) - foreach (RevisionInfo tmp in _CacheByPrimaryKey[_RevisionID.ToString()]) - tmp._RevisionVersionCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base RevisionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RevisionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check RevisionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RevisionInfo - protected override object GetIdValue() - { - return MyRevisionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _RevisionInfoUnique = 0; - private static int RevisionInfoUnique - { get { return ++_RevisionInfoUnique; } } - private int _MyRevisionInfoUnique = RevisionInfoUnique; - public int MyRevisionInfoUnique // Absolutely Unique ID - Info - { get { return _MyRevisionInfoUnique; } } - protected RevisionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~RevisionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(RevisionID.ToString())) return; - List listRevisionInfo = _CacheByPrimaryKey[RevisionID.ToString()]; // Get the list of items - while (listRevisionInfo.Contains(this)) listRevisionInfo.Remove(this); // Remove the item from the list - if (listRevisionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(RevisionID.ToString()); // remove the list - } - public virtual Revision Get() - { - return _Editable = Revision.Get(_RevisionID); - } - public static void Refresh(Revision tmp) - { - string key = tmp.RevisionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RevisionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Revision tmp) - { - _ItemID = tmp.ItemID; - _TypeID = tmp.TypeID; - _RevisionNumber = tmp.RevisionNumber; - _RevisionDate = tmp.RevisionDate; - _Notes = tmp.Notes; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _RevisionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static RevisionInfo Get(int revisionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Revision"); - try - { - RevisionInfo tmp = GetCachedByPrimaryKey(revisionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(revisionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RevisionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RevisionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal RevisionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.Constructor", ex); - throw new DbCslaException("RevisionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _RevisionID; - public int RevisionID - { get { return _RevisionID; } } - public PKCriteria(int revisionID) - { - _RevisionID = revisionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.ReadData", GetHashCode()); - try - { - _RevisionID = dr.GetInt32("RevisionID"); - _ItemID = dr.GetInt32("ItemID"); - _TypeID = dr.GetInt32("TypeID"); - _RevisionNumber = dr.GetString("RevisionNumber"); - if (!dr.IsDBNull(dr.GetOrdinal("RevisionDate"))) _RevisionDate = dr.GetDateTime("RevisionDate"); - _Notes = dr.GetString("Notes"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _RevisionCheckCount = dr.GetInt32("CheckCount"); - _RevisionVersionCount = dr.GetInt32("VersionCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RevisionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRevision"; - cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RevisionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - RevisionInfoExtension _RevisionInfoExtension = new RevisionInfoExtension(); - [Serializable()] - partial class RevisionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(RevisionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class RevisionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RevisionInfo) - { - // Return the ToString value - return ((RevisionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void RevisionInfoEvent(object sender); + /// + /// RevisionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionInfoConverter))] + public partial class RevisionInfo : ReadOnlyBase, IDisposable + { + public event RevisionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RevisionInfo revisionInfo) + { + if (!_CacheList.Contains(revisionInfo)) _CacheList.Add(revisionInfo); // In AddToCache + } + protected static void RemoveFromCache(RevisionInfo revisionInfo) + { + while (_CacheList.Contains(revisionInfo)) _CacheList.Remove(revisionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move RevisionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + RevisionInfo tmp = _CacheList[0]; // Get the first RevisionInfo + string pKey = tmp.RevisionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first RevisionInfo + } + } + internal static void AddList(RevisionInfoList lst) + { + foreach (RevisionInfo item in lst) AddToCache(item); + } + protected static RevisionInfo GetCachedByPrimaryKey(int revisionID) + { + ConvertListToDictionary(); + string key = revisionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Revision _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _RevisionID; + [System.ComponentModel.DataObjectField(true, true)] + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TypeID; + } + } + private string _RevisionNumber = string.Empty; + public string RevisionNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionNumber; + } + } + private DateTime? _RevisionDate; + public DateTime? RevisionDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RevisionDate; + } + } + private string _Notes = string.Empty; + public string Notes + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Notes; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _RevisionCheckCount = 0; + /// + /// Count of RevisionChecks for this Revision + /// + public int RevisionCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RevisionCheckCount < 0) + _RevisionCheckCount = RevisionChecks.Count; + return _RevisionCheckCount; + } + } + private CheckInfoList _RevisionChecks = null; + [TypeConverter(typeof(CheckInfoListConverter))] + public CheckInfoList RevisionChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RevisionCheckCount < 0 || (_RevisionCheckCount > 0 && _RevisionChecks == null)) + _RevisionChecks = CheckInfoList.GetByRevisionID(_RevisionID); + if (_RevisionCheckCount < 0) + _RevisionCheckCount = _RevisionChecks.Count; + return _RevisionChecks; + } + } + public void RefreshRevisionChecks() + { + _RevisionCheckCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RevisionID.ToString())) + foreach (RevisionInfo tmp in _CacheByPrimaryKey[_RevisionID.ToString()]) + tmp._RevisionCheckCount = -1; // This will cause the data to be requeried + } + private int _RevisionVersionCount = 0; + /// + /// Count of RevisionVersions for this Revision + /// + public int RevisionVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + //_MyLog.WarnFormat("RevisionVersionCount 1 - {0}", GC.GetTotalMemory(true)); + if (_RevisionVersionCount < 0) + { + _RevisionVersionCount = RevisionVersions.Count; + //_MyLog.WarnFormat("RevisionVersionCount 2 (after setting count) - {0}", GC.GetTotalMemory(true)); + } + //_MyLog.WarnFormat("RevisionVersionCount 3 (before return) - {0}", GC.GetTotalMemory(true)); + return _RevisionVersionCount; + } + } + private VersionInfoList _RevisionVersions = null; + [TypeConverter(typeof(VersionInfoListConverter))] + public VersionInfoList RevisionVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + //_MyLog.WarnFormat("RevisionVersions 1 - {0}", GC.GetTotalMemory(true)); + if (_RevisionVersionCount < 0 || (_RevisionVersionCount > 0 && _RevisionVersions == null)) + { + //_MyLog.WarnFormat("RevisionVersions 2 (before using) - {0} count {1}", GC.GetTotalMemory(true),_RevisionVersionCount); + using (VersionInfoList vil = VersionInfoList.GetByRevisionID(_RevisionID)) + { + //_MyLog.WarnFormat("RevisionVersions 3 (using) - {0}", GC.GetTotalMemory(true)); + _RevisionVersions = vil; + } + } + //_MyLog.WarnFormat("RevisionVersions 4 (after using) - {0}", GC.GetTotalMemory(true)); + if (_RevisionVersionCount < 0) + { + _RevisionVersionCount = _RevisionVersions.Count; + //_MyLog.WarnFormat("RevisionVersions 4 (after setting count) - {0}", GC.GetTotalMemory(true)); + } + //_MyLog.WarnFormat("RevisionVersions 5 (before return) - {0}", GC.GetTotalMemory(true)); + return _RevisionVersions; + } + } + public void RefreshRevisionVersions() + { + _RevisionVersionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RevisionID.ToString())) + foreach (RevisionInfo tmp in _CacheByPrimaryKey[_RevisionID.ToString()]) + tmp._RevisionVersionCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base RevisionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RevisionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check RevisionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RevisionInfo + protected override object GetIdValue() + { + return MyRevisionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _RevisionInfoUnique = 0; + private static int RevisionInfoUnique + { get { return ++_RevisionInfoUnique; } } + private int _MyRevisionInfoUnique = RevisionInfoUnique; + public int MyRevisionInfoUnique // Absolutely Unique ID - Info + { get { return _MyRevisionInfoUnique; } } + protected RevisionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~RevisionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(RevisionID.ToString())) return; + List listRevisionInfo = _CacheByPrimaryKey[RevisionID.ToString()]; // Get the list of items + while (listRevisionInfo.Contains(this)) listRevisionInfo.Remove(this); // Remove the item from the list + if (listRevisionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(RevisionID.ToString()); // remove the list + } + public virtual Revision Get() + { + return _Editable = Revision.Get(_RevisionID); + } + public static void Refresh(Revision tmp) + { + string key = tmp.RevisionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RevisionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Revision tmp) + { + _ItemID = tmp.ItemID; + _TypeID = tmp.TypeID; + _RevisionNumber = tmp.RevisionNumber; + _RevisionDate = tmp.RevisionDate; + _Notes = tmp.Notes; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RevisionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static RevisionInfo Get(int revisionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Revision"); + try + { + RevisionInfo tmp = GetCachedByPrimaryKey(revisionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(revisionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RevisionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RevisionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RevisionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.Constructor", ex); + throw new DbCslaException("RevisionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _RevisionID; + public int RevisionID + { get { return _RevisionID; } } + public PKCriteria(int revisionID) + { + _RevisionID = revisionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.ReadData", GetHashCode()); + try + { + _RevisionID = dr.GetInt32("RevisionID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RevisionNumber = dr.GetString("RevisionNumber"); + if (!dr.IsDBNull(dr.GetOrdinal("RevisionDate"))) _RevisionDate = dr.GetDateTime("RevisionDate"); + _Notes = dr.GetString("Notes"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _RevisionCheckCount = dr.GetInt32("CheckCount"); + _RevisionVersionCount = dr.GetInt32("VersionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RevisionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRevision"; + cm.Parameters.AddWithValue("@RevisionID", criteria.RevisionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RevisionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RevisionInfoExtension _RevisionInfoExtension = new RevisionInfoExtension(); + [Serializable()] + partial class RevisionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RevisionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RevisionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionInfo) + { + // Return the ToString value + return ((RevisionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs index ed942885..898f2c29 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RevisionVersion.cs @@ -20,547 +20,527 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RevisionVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RevisionVersionConverter))] - public partial class RevisionVersion : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyVersion != null) _VersionID = _MyVersion.VersionID; - return _VersionID; - } - } - private Version _MyVersion; - [System.ComponentModel.DataObjectField(true, true)] - public Version MyVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyVersion", true); - if (_MyVersion == null && _VersionID != 0) _MyVersion = Version.Get(_VersionID); - return _MyVersion; - } - } - private int _StageID; - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - if (_MyStage != null) _StageID = _MyStage.StageID; - return _StageID; - } - } - private Stage _MyStage; - public Stage MyStage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyStage", true); - if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); - return _MyStage; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyStage", true); - if (_MyStage != value) - { - _MyStage = value; - _StageID = value.StageID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private byte[] _PDF; - public byte[] PDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PDF", true); - return _PDF; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PDF", true); - if (_PDF != value) - { - _PDF = value; - PropertyHasChanged(); - } - } - } - private byte[] _SummaryPDF; - public byte[] SummaryPDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SummaryPDF", true); - return _SummaryPDF; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SummaryPDF", true); - if (_SummaryPDF != value) - { - _SummaryPDF = value; - PropertyHasChanged(); - } - } - } - private string _ApprovedXML; - public string ApprovedXML - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ApprovedXML", true); - return _ApprovedXML; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ApprovedXML", true); - if (_ApprovedXML != value) - { - _ApprovedXML = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Stage_Name = string.Empty; - public string Stage_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_Name", true); - return _Stage_Name; - } - } - private string _Stage_Description = string.Empty; - public string Stage_Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_Description", true); - return _Stage_Description; - } - } - private int _Stage_IsApproved; - public int Stage_IsApproved - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_IsApproved", true); - return _Stage_IsApproved; - } - } - private DateTime _Stage_DTS = new DateTime(); - public DateTime Stage_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_DTS", true); - return _Stage_DTS; - } - } - private string _Stage_UserID = string.Empty; - public string Stage_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Stage_UserID", true); - return _Stage_UserID; - } - } - // CSLATODO: Check RevisionVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RevisionVersion - protected override object GetIdValue() - { - return MyRevisionVersionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RevisionVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RevisionVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyStage == null ? true : _MyStage.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyStageRequired, "MyStage"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - // CSLATODO: Add other validation rules - } - private static bool MyStageRequired(RevisionVersion target, Csla.Validation.RuleArgs e) - { - if (target._StageID == 0 && target._MyStage == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(StageID, ""); - //AuthorizationRules.AllowWrite(StageID, ""); - //AuthorizationRules.AllowRead(PDF, ""); - //AuthorizationRules.AllowWrite(PDF, ""); - //AuthorizationRules.AllowRead(SummaryPDF, ""); - //AuthorizationRules.AllowWrite(SummaryPDF, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _RevisionVersionUnique = 0; - private static int RevisionVersionUnique - { get { return ++_RevisionVersionUnique; } } - private int _MyRevisionVersionUnique = RevisionVersionUnique; - public int MyRevisionVersionUnique // Absolutely Unique ID - Editable FK - { get { return _MyRevisionVersionUnique; } } - internal static RevisionVersion New(Stage myStage, DateTime dts, string userID) - { - return new RevisionVersion(myStage, dts, userID); - } - internal static RevisionVersion Get(SafeDataReader dr) - { - return new RevisionVersion(dr); - } - public RevisionVersion() - { - MarkAsChild(); - _VersionID = Version.NextVersionID; + /// + /// RevisionVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RevisionVersionConverter))] + public partial class RevisionVersion : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyVersion != null) _VersionID = _MyVersion.VersionID; + return _VersionID; + } + } + private Version _MyVersion; + [System.ComponentModel.DataObjectField(true, true)] + public Version MyVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyVersion == null && _VersionID != 0) _MyVersion = Version.Get(_VersionID); + return _MyVersion; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PDF != value) + { + _PDF = value; + PropertyHasChanged(); + } + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SummaryPDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_SummaryPDF != value) + { + _SummaryPDF = value; + PropertyHasChanged(); + } + } + } + private string _ApprovedXML; + public string ApprovedXML + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ApprovedXML; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ApprovedXML != value) + { + _ApprovedXML = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Stage_Name = string.Empty; + public string Stage_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_Name; + } + } + private string _Stage_Description = string.Empty; + public string Stage_Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_Description; + } + } + private int _Stage_IsApproved; + public int Stage_IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_IsApproved; + } + } + private DateTime _Stage_DTS = new DateTime(); + public DateTime Stage_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_DTS; + } + } + private string _Stage_UserID = string.Empty; + public string Stage_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Stage_UserID; + } + } + // CSLATODO: Check RevisionVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RevisionVersion + protected override object GetIdValue() + { + return MyRevisionVersionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RevisionVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RevisionVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + // CSLATODO: Add other validation rules + } + private static bool MyStageRequired(RevisionVersion target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowRead(PDF, ""); + //AuthorizationRules.AllowWrite(PDF, ""); + //AuthorizationRules.AllowRead(SummaryPDF, ""); + //AuthorizationRules.AllowWrite(SummaryPDF, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _RevisionVersionUnique = 0; + private static int RevisionVersionUnique + { get { return ++_RevisionVersionUnique; } } + private int _MyRevisionVersionUnique = RevisionVersionUnique; + public int MyRevisionVersionUnique // Absolutely Unique ID - Editable FK + { get { return _MyRevisionVersionUnique; } } + internal static RevisionVersion New(Stage myStage, DateTime dts, string userID) + { + return new RevisionVersion(myStage, dts, userID); + } + internal static RevisionVersion Get(SafeDataReader dr) + { + return new RevisionVersion(dr); + } + public RevisionVersion() + { + MarkAsChild(); + _VersionID = Version.NextVersionID; - ValidationRules.CheckRules(); - } - private RevisionVersion(Stage myStage, DateTime dts, string userID) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _VersionID = Version.NextVersionID; + ValidationRules.CheckRules(); + } + private RevisionVersion(Stage myStage, DateTime dts, string userID) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _VersionID = Version.NextVersionID; - _MyStage = myStage; - _DTS = dts; - _UserID = userID; - ValidationRules.CheckRules(); - } - internal RevisionVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RevisionVersion() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _StageID = dr.GetInt32("StageID"); - _PDF = (byte[])dr.GetValue("PDF"); - _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Stage_Name = dr.GetString("Stage_Name"); - _Stage_Description = dr.GetString("Stage_Description"); - _Stage_IsApproved = dr.GetInt32("Stage_IsApproved"); - _Stage_DTS = dr.GetDateTime("Stage_DTS"); - _Stage_UserID = dr.GetString("Stage_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionVersion.FetchDR", ex); - throw new DbCslaException("RevisionVersion.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Revision myRevision) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Version.Add(cn, ref _VersionID, myRevision, _MyStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); - MarkOld(); - } - internal void Update(Revision myRevision) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Version.Update(cn, ref _VersionID, myRevision.RevisionID, _StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Revision myRevision) - { - // 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"]; - Version.Remove(cn, _VersionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RevisionVersionExtension _RevisionVersionExtension = new RevisionVersionExtension(); - [Serializable()] - partial class RevisionVersionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RevisionVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RevisionVersion) - { - // Return the ToString value - return ((RevisionVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _MyStage = myStage; + _DTS = dts; + _UserID = userID; + ValidationRules.CheckRules(); + } + internal RevisionVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RevisionVersion() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RevisionVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _StageID = dr.GetInt32("StageID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Stage_Name = dr.GetString("Stage_Name"); + _Stage_Description = dr.GetString("Stage_Description"); + _Stage_IsApproved = dr.GetInt32("Stage_IsApproved"); + _Stage_DTS = dr.GetDateTime("Stage_DTS"); + _Stage_UserID = dr.GetString("Stage_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RevisionVersion.FetchDR", ex); + throw new DbCslaException("RevisionVersion.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Add(cn, ref _VersionID, myRevision, _MyStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); + MarkOld(); + } + internal void Update(Revision myRevision) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Update(cn, ref _VersionID, myRevision.RevisionID, _StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Revision myRevision) + { + // 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"]; + Version.Remove(cn, _VersionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RevisionVersionExtension _RevisionVersionExtension = new RevisionVersionExtension(); + [Serializable()] + partial class RevisionVersionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RevisionVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RevisionVersion) + { + // Return the ToString value + return ((RevisionVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs index 4f4dae59..7cb91cf6 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsage.cs @@ -20,1098 +20,1083 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RoUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoUsageConverter))] - public partial class RoUsage : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshRoUsages = new List(); - private void AddToRefreshList(List refreshRoUsages) - { - if (IsDirty) - refreshRoUsages.Add(this); - } - private void ClearRefreshList() - { - _RefreshRoUsages = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshRoUsages); - } - private void ProcessRefreshList() - { - foreach (RoUsage tmp in _RefreshRoUsages) - { - RoUsageInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RoUsage roUsage) - { - if (!_CacheList.Contains(roUsage)) _CacheList.Add(roUsage); // In AddToCache - } - protected static void RemoveFromCache(RoUsage roUsage) - { - while (_CacheList.Contains(roUsage)) _CacheList.Remove(roUsage); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move RoUsage(s) from temporary _CacheList to _CacheByPrimaryKey - { - RoUsage tmp = _CacheList[0]; // Get the first RoUsage - string pKey = tmp.ROUsageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first RoUsage - } - } - protected static RoUsage GetCachedByPrimaryKey(int rOUsageID) - { - ConvertListToDictionary(); - string key = rOUsageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextROUsageID = -1; - public static int NextROUsageID - { - get { return _nextROUsageID--; } - } - private int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - return _ROUsageID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - _ContentID = value.ContentID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - _RODbID = value.RODbID;// Update underlying data field - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); - } - // CSLATODO: Replace base RoUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check RoUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoUsage - protected override object GetIdValue() - { - return MyRoUsageUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - //ValidationRules.AddDependantProperty("x", "y"); - _RoUsageExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _RoUsageExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyContentRequired(RoUsage target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyRODbRequired(RoUsage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(ROUsageID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - _RoUsageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _RoUsageExtension.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; } } - private static int _RoUsageUnique = 0; - protected static int RoUsageUnique - { get { return ++_RoUsageUnique; } } - private int _MyRoUsageUnique = RoUsageUnique; - public int MyRoUsageUnique // Absolutely Unique ID - Editable - { get { return _MyRoUsageUnique; } } - protected RoUsage() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~RoUsage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) - { - List listRoUsage = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items - while (listRoUsage.Contains(this)) listRoUsage.Remove(this); // Remove the item from the list - if (listRoUsage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list - } - } - public static RoUsage New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RoUsage"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.New", ex); - } - } - public static RoUsage New(string roid, RODb myRODb) - { - RoUsage tmp = RoUsage.New(); - tmp.ROID = roid; - tmp.MyRODb = myRODb; - return tmp; - } - public static RoUsage New(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - RoUsage tmp = RoUsage.New(); - tmp.MyContent = myContent; - tmp.ROID = roid; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.MyRODb = myRODb; - return tmp; - } - public static RoUsage MakeRoUsage(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID, myRODb); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RoUsage New(Content myContent, string roid, string config, RODb myRODb) - { - RoUsage tmp = RoUsage.New(); - tmp.MyContent = myContent; - tmp.ROID = roid; - tmp.Config = config; - tmp.MyRODb = myRODb; - return tmp; - } - public static RoUsage MakeRoUsage(Content myContent, string roid, string config, RODb myRODb) - { - RoUsage tmp = RoUsage.New(myContent, roid, config, myRODb); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RoUsage Get(int rOUsageID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a RoUsage"); - try - { - RoUsage tmp = GetCachedByPrimaryKey(rOUsageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RoUsage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.Get", ex); - } - } - public static RoUsage Get(SafeDataReader dr) - { - if (dr.Read()) return new RoUsage(dr); - return null; - } - internal RoUsage(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rOUsageID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); - try - { - DataPortal.Delete(new PKCriteria(rOUsageID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.Delete", ex); - } - } - public override RoUsage Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RoUsage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a RoUsage"); - try - { - BuildRefreshList(); - RoUsage roUsage = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(roUsage);//Refresh the item in AllList - ProcessRefreshList(); - return roUsage; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ROUsageID; - public int ROUsageID - { get { return _ROUsageID; } } - public PKCriteria(int rOUsageID) - { - _ROUsageID = rOUsageID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ROUsageID = NextROUsageID; - // Database Defaults - _ContentID = _RoUsageExtension.DefaultContentID; - _DTS = _RoUsageExtension.DefaultDTS; - _UserID = _RoUsageExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.ReadData", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ContentID = dr.GetInt32("ContentID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbID = dr.GetInt32("RODbID"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRoUsage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", ContentID); - 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_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); - param_ROUsageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROUsageID); - 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 - _ROUsageID = (int)cm.Parameters["@newROUsageID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRoUsage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - 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", myRODb.RODbID); - // Output Calculated Columns - SqlParameter param_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); - param_ROUsageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROUsageID); - 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 - rOUsageID = (int)cm.Parameters["@newROUsageID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Add", ex); - throw new DbCslaException("RoUsage.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] RoUsage.SQLUpdate", GetHashCode()); - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRoUsage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); - cm.Parameters.AddWithValue("@ContentID", ContentID); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, _MyRODb); - else - _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rOUsageID, int contentID, string roid, string config, DateTime dts, string userID, ref byte[] lastChanged, int rODbID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRoUsage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); - cm.Parameters.AddWithValue("@ContentID", contentID); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Update", ex); - throw new DbCslaException("RoUsage.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ROUsageID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rOUsageID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRoUsage"; - // Input PK Fields - cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Remove", ex); - throw new DbCslaException("RoUsage.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rOUsageID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rOUsageID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ROUsageID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rOUsageID) - { - _ROUsageID = rOUsageID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Execute", ex); - throw new DbCslaException("RoUsage.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - RoUsageExtension _RoUsageExtension = new RoUsageExtension(); - [Serializable()] - partial class RoUsageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultContentID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RoUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoUsage) - { - // Return the ToString value - return ((RoUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RoUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoUsageConverter))] + public partial class RoUsage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRoUsages = new List(); + private void AddToRefreshList(List refreshRoUsages) + { + if (IsDirty) + refreshRoUsages.Add(this); + } + private void ClearRefreshList() + { + _RefreshRoUsages = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshRoUsages); + } + private void ProcessRefreshList() + { + foreach (RoUsage tmp in _RefreshRoUsages) + { + RoUsageInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RoUsage roUsage) + { + if (!_CacheList.Contains(roUsage)) _CacheList.Add(roUsage); // In AddToCache + } + protected static void RemoveFromCache(RoUsage roUsage) + { + while (_CacheList.Contains(roUsage)) _CacheList.Remove(roUsage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move RoUsage(s) from temporary _CacheList to _CacheByPrimaryKey + { + RoUsage tmp = _CacheList[0]; // Get the first RoUsage + string pKey = tmp.ROUsageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first RoUsage + } + } + protected static RoUsage GetCachedByPrimaryKey(int rOUsageID) + { + ConvertListToDictionary(); + string key = rOUsageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextROUsageID = -1; + public static int NextROUsageID + { + get { return _nextROUsageID--; } + } + private int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROUsageID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + _ContentID = value.ContentID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + _RODbID = value.RODbID;// Update underlying data field + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirtyList(list)) || (_MyRODb == null ? false : _MyRODb.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValidList(list)) && (_MyRODb == null ? true : _MyRODb.IsValidList(list)); + } + // CSLATODO: Replace base RoUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check RoUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoUsage + protected override object GetIdValue() + { + return MyRoUsageUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + //ValidationRules.AddDependantProperty("x", "y"); + _RoUsageExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _RoUsageExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyContentRequired(RoUsage target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyRODbRequired(RoUsage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(ROUsageID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + _RoUsageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _RoUsageExtension.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; } } + private static int _RoUsageUnique = 0; + protected static int RoUsageUnique + { get { return ++_RoUsageUnique; } } + private int _MyRoUsageUnique = RoUsageUnique; + public int MyRoUsageUnique // Absolutely Unique ID - Editable + { get { return _MyRoUsageUnique; } } + protected RoUsage() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~RoUsage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) + { + List listRoUsage = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items + while (listRoUsage.Contains(this)) listRoUsage.Remove(this); // Remove the item from the list + if (listRoUsage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list + } + } + public static RoUsage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RoUsage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.New", ex); + } + } + public static RoUsage New(string roid, RODb myRODb) + { + RoUsage tmp = RoUsage.New(); + tmp.ROID = roid; + tmp.MyRODb = myRODb; + return tmp; + } + public static RoUsage New(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + RoUsage tmp = RoUsage.New(); + tmp.MyContent = myContent; + tmp.ROID = roid; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.MyRODb = myRODb; + return tmp; + } + public static RoUsage MakeRoUsage(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID, myRODb); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RoUsage New(Content myContent, string roid, string config, RODb myRODb) + { + RoUsage tmp = RoUsage.New(); + tmp.MyContent = myContent; + tmp.ROID = roid; + tmp.Config = config; + tmp.MyRODb = myRODb; + return tmp; + } + public static RoUsage MakeRoUsage(Content myContent, string roid, string config, RODb myRODb) + { + RoUsage tmp = RoUsage.New(myContent, roid, config, myRODb); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RoUsage Get(int rOUsageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a RoUsage"); + try + { + RoUsage tmp = GetCachedByPrimaryKey(rOUsageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoUsage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.Get", ex); + } + } + public static RoUsage Get(SafeDataReader dr) + { + if (dr.Read()) return new RoUsage(dr); + return null; + } + internal RoUsage(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rOUsageID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); + try + { + DataPortal.Delete(new PKCriteria(rOUsageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.Delete", ex); + } + } + public override RoUsage Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RoUsage"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a RoUsage"); + try + { + BuildRefreshList(); + RoUsage roUsage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(roUsage);//Refresh the item in AllList + ProcessRefreshList(); + return roUsage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ROUsageID; + public int ROUsageID + { get { return _ROUsageID; } } + public PKCriteria(int rOUsageID) + { + _ROUsageID = rOUsageID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ROUsageID = NextROUsageID; + // Database Defaults + _ContentID = _RoUsageExtension.DefaultContentID; + _DTS = _RoUsageExtension.DefaultDTS; + _UserID = _RoUsageExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.ReadData", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ContentID = dr.GetInt32("ContentID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbID = dr.GetInt32("RODbID"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRoUsage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", ContentID); + 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_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); + param_ROUsageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROUsageID); + 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 + _ROUsageID = (int)cm.Parameters["@newROUsageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRoUsage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + 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", myRODb.RODbID); + // Output Calculated Columns + SqlParameter param_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); + param_ROUsageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROUsageID); + 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 + rOUsageID = (int)cm.Parameters["@newROUsageID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Add", ex); + throw new DbCslaException("RoUsage.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] RoUsage.SQLUpdate", GetHashCode()); + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRoUsage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); + cm.Parameters.AddWithValue("@ContentID", ContentID); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, _MyRODb); + else + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _ContentID, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _RODbID); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rOUsageID, int contentID, string roid, string config, DateTime dts, string userID, ref byte[] lastChanged, int rODbID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRoUsage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); + cm.Parameters.AddWithValue("@ContentID", contentID); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Update", ex); + throw new DbCslaException("RoUsage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ROUsageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rOUsageID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRoUsage"; + // Input PK Fields + cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Remove", ex); + throw new DbCslaException("RoUsage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rOUsageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rOUsageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ROUsageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rOUsageID) + { + _ROUsageID = rOUsageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Execute", ex); + throw new DbCslaException("RoUsage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + RoUsageExtension _RoUsageExtension = new RoUsageExtension(); + [Serializable()] + partial class RoUsageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultContentID + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RoUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoUsage) + { + // Return the ToString value + return ((RoUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs index 05221c40..1c141b88 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoUsageInfo.cs @@ -19,445 +19,436 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void RoUsageInfoEvent(object sender); - /// - /// RoUsageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoUsageInfoConverter))] - public partial class RoUsageInfo : ReadOnlyBase, IDisposable - { - public event RoUsageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RoUsageInfo roUsageInfo) - { - if (!_CacheList.Contains(roUsageInfo)) _CacheList.Add(roUsageInfo); // In AddToCache - } - protected static void RemoveFromCache(RoUsageInfo roUsageInfo) - { - while (_CacheList.Contains(roUsageInfo)) _CacheList.Remove(roUsageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move RoUsageInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - RoUsageInfo tmp = _CacheList[0]; // Get the first RoUsageInfo - string pKey = tmp.ROUsageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first RoUsageInfo - } - } - internal static void AddList(RoUsageInfoList lst) - { - foreach (RoUsageInfo item in lst) AddToCache(item); - } - protected static RoUsageInfo GetCachedByPrimaryKey(int rOUsageID) - { - ConvertListToDictionary(); - string key = rOUsageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected RoUsage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - return _ROUsageID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODbInfo _MyRODb; - public RODbInfo MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.GetJustRODB(_RODbID); - return _MyRODb; - } - } - // CSLATODO: Replace base RoUsageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoUsageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check RoUsageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoUsageInfo - protected override object GetIdValue() - { - return MyRoUsageInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _RoUsageInfoUnique = 0; - private static int RoUsageInfoUnique - { get { return ++_RoUsageInfoUnique; } } - private int _MyRoUsageInfoUnique = RoUsageInfoUnique; - public int MyRoUsageInfoUnique // Absolutely Unique ID - Info - { get { return _MyRoUsageInfoUnique; } } - protected RoUsageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~RoUsageInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; - List listRoUsageInfo = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items - while (listRoUsageInfo.Contains(this)) listRoUsageInfo.Remove(this); // Remove the item from the list - if (listRoUsageInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list - } - public virtual RoUsage Get() - { - return _Editable = RoUsage.Get(_ROUsageID); - } - public static void Refresh(RoUsage tmp) - { - string key = tmp.ROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RoUsage tmp) - { - if (_ContentID != tmp.ContentID) - { - if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // 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.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value - _RoUsageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(ContentRoUsage tmp) - { - string key = tmp.ROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentRoUsage tmp) - { - _ROID = tmp.ROID; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - if (_RODbID != tmp.RODbID) - { - if (MyRODb != null) MyRODb.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value - _RoUsageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RODbRoUsage tmp) - { - string key = tmp.ROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODbRoUsage tmp) - { - if (_ContentID != tmp.ContentID) - { - if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // Update List for new value - _ROID = tmp.ROID; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _RoUsageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static RoUsageInfo Get(int rOUsageID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a RoUsage"); - try - { - RoUsageInfo tmp = GetCachedByPrimaryKey(rOUsageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RoUsageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal RoUsageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.Constructor", ex); - throw new DbCslaException("RoUsageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ROUsageID; - public int ROUsageID - { get { return _ROUsageID; } } - public PKCriteria(int rOUsageID) - { - _ROUsageID = rOUsageID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.ReadData", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ContentID = dr.GetInt32("ContentID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _RODbID = dr.GetInt32("RODbID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - RoUsageInfoExtension _RoUsageInfoExtension = new RoUsageInfoExtension(); - [Serializable()] - partial class RoUsageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(RoUsageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class RoUsageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoUsageInfo) - { - // Return the ToString value - return ((RoUsageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void RoUsageInfoEvent(object sender); + /// + /// RoUsageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoUsageInfoConverter))] + public partial class RoUsageInfo : ReadOnlyBase, IDisposable + { + public event RoUsageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RoUsageInfo roUsageInfo) + { + if (!_CacheList.Contains(roUsageInfo)) _CacheList.Add(roUsageInfo); // In AddToCache + } + protected static void RemoveFromCache(RoUsageInfo roUsageInfo) + { + while (_CacheList.Contains(roUsageInfo)) _CacheList.Remove(roUsageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move RoUsageInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + RoUsageInfo tmp = _CacheList[0]; // Get the first RoUsageInfo + string pKey = tmp.ROUsageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first RoUsageInfo + } + } + internal static void AddList(RoUsageInfoList lst) + { + foreach (RoUsageInfo item in lst) AddToCache(item); + } + protected static RoUsageInfo GetCachedByPrimaryKey(int rOUsageID) + { + ConvertListToDictionary(); + string key = rOUsageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected RoUsage _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROUsageID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODbInfo _MyRODb; + public RODbInfo MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.GetJustRODB(_RODbID); + return _MyRODb; + } + } + // CSLATODO: Replace base RoUsageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoUsageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check RoUsageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoUsageInfo + protected override object GetIdValue() + { + return MyRoUsageInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _RoUsageInfoUnique = 0; + private static int RoUsageInfoUnique + { get { return ++_RoUsageInfoUnique; } } + private int _MyRoUsageInfoUnique = RoUsageInfoUnique; + public int MyRoUsageInfoUnique // Absolutely Unique ID - Info + { get { return _MyRoUsageInfoUnique; } } + protected RoUsageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~RoUsageInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; + List listRoUsageInfo = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items + while (listRoUsageInfo.Contains(this)) listRoUsageInfo.Remove(this); // Remove the item from the list + if (listRoUsageInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list + } + public virtual RoUsage Get() + { + return _Editable = RoUsage.Get(_ROUsageID); + } + public static void Refresh(RoUsage tmp) + { + string key = tmp.ROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RoUsage tmp) + { + if (_ContentID != tmp.ContentID) + { + if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // 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.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value + _RoUsageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(ContentRoUsage tmp) + { + string key = tmp.ROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentRoUsage tmp) + { + _ROID = tmp.ROID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + if (_RODbID != tmp.RODbID) + { + if (MyRODb != null) MyRODb.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value + _RoUsageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RODbRoUsage tmp) + { + string key = tmp.ROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODbRoUsage tmp) + { + if (_ContentID != tmp.ContentID) + { + if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // Update List for new value + _ROID = tmp.ROID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RoUsageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static RoUsageInfo Get(int rOUsageID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a RoUsage"); + try + { + RoUsageInfo tmp = GetCachedByPrimaryKey(rOUsageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoUsageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RoUsageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.Constructor", ex); + throw new DbCslaException("RoUsageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ROUsageID; + public int ROUsageID + { get { return _ROUsageID; } } + public PKCriteria(int rOUsageID) + { + _ROUsageID = rOUsageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.ReadData", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ContentID = dr.GetInt32("ContentID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _RODbID = dr.GetInt32("RODbID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RoUsageInfoExtension _RoUsageInfoExtension = new RoUsageInfoExtension(); + [Serializable()] + partial class RoUsageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RoUsageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RoUsageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoUsageInfo) + { + // Return the ToString value + return ((RoUsageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs index 24b54c29..1e497a4c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Role.cs @@ -20,1199 +20,1186 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Role Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoleConverter))] - public partial class Role : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshRoles = new List(); - private List _RefreshRoleAssignments = new List(); - private List _RefreshRolePermissions = new List(); - private void AddToRefreshList(List refreshRoles, List refreshRoleAssignments, List refreshRolePermissions) - { - if (IsDirty) - refreshRoles.Add(this); - if (_RoleAssignments != null && _RoleAssignments.IsDirty) - { - foreach (RoleAssignment tmp in _RoleAssignments) - { - if (tmp.IsDirty) refreshRoleAssignments.Add(tmp); - } - } - if (_RolePermissions != null && _RolePermissions.IsDirty) - { - foreach (RolePermission tmp in _RolePermissions) - { - if (tmp.IsDirty) refreshRolePermissions.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshRoles = new List(); - _RefreshRoleAssignments = new List(); - _RefreshRolePermissions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshRoles, _RefreshRoleAssignments, _RefreshRolePermissions); - } - private void ProcessRefreshList() - { - foreach (Role tmp in _RefreshRoles) - { - RoleInfo.Refresh(tmp); - } - foreach (RoleAssignment tmp in _RefreshRoleAssignments) - { - AssignmentInfo.Refresh(tmp); - } - foreach (RolePermission tmp in _RefreshRolePermissions) - { - PermissionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Role role) - { - if (!_CacheList.Contains(role)) _CacheList.Add(role); // In AddToCache - } - protected static void RemoveFromCache(Role role) - { - while (_CacheList.Contains(role)) _CacheList.Remove(role); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByName = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Role(s) from temporary _CacheList to _CacheByPrimaryKey - { - Role tmp = _CacheList[0]; // Get the first Role - string pKey = tmp.RID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index - _CacheList.RemoveAt(0); // Remove the first Role - } - } - protected static Role GetCachedByPrimaryKey(int rid) - { - ConvertListToDictionary(); - string key = rid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Role GetCachedByName(string name) - { - ConvertListToDictionary(); - string key = name.ToString(); - if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextRID = -1; - public static int NextRID - { - get { return _nextRID--; } - } - private int _RID; - [System.ComponentModel.DataObjectField(true, true)] - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - return _RID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RoleAssignmentCount = 0; - /// - /// Count of RoleAssignments for this Role - /// - public int RoleAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignmentCount", true); - return _RoleAssignmentCount; - } - } - private RoleAssignments _RoleAssignments = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RoleAssignmentsConverter))] - public RoleAssignments RoleAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignments", true); - if (_RoleAssignmentCount < 0 || (_RoleAssignmentCount > 0 && _RoleAssignments == null)) - _RoleAssignments = RoleAssignments.GetByRID(RID); - if (_RoleAssignmentCount < 0 ) - _RoleAssignmentCount = _RoleAssignments == null ? 0 : _RoleAssignments.Count; - if (_RoleAssignments == null) - _RoleAssignments = RoleAssignments.New(); - return _RoleAssignments; - } - } - public void Reset_RoleAssignments() - { - _RoleAssignmentCount = -1; - } - private int _RolePermissionCount = 0; - /// - /// Count of RolePermissions for this Role - /// - public int RolePermissionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissionCount", true); - return _RolePermissionCount; - } - } - private RolePermissions _RolePermissions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RolePermissionsConverter))] - public RolePermissions RolePermissions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissions", true); - if (_RolePermissionCount < 0 || (_RolePermissionCount > 0 && _RolePermissions == null)) - _RolePermissions = RolePermissions.GetByRID(RID); - if (_RolePermissionCount < 0 ) - _RolePermissionCount = _RolePermissions == null ? 0 : _RolePermissions.Count; - if (_RolePermissions == null) - _RolePermissions = RolePermissions.New(); - return _RolePermissions; - } - } - public void Reset_RolePermissions() - { - _RolePermissionCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_RoleAssignments == null ? false : _RoleAssignments.IsDirtyList(list)) || (_RolePermissions == null ? false : _RolePermissions.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RoleAssignments == null ? true : _RoleAssignments.IsValidList(list)) && (_RolePermissions == null ? true : _RolePermissions.IsValidList(list)); - } - // CSLATODO: Replace base Role.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Role - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Role.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Role - protected override object GetIdValue() - { - return MyRoleUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_RoleAssignments != null && (hasBrokenRules = _RoleAssignments.HasBrokenRules) != null) return hasBrokenRules; - if (_RolePermissions != null && (hasBrokenRules = _RolePermissions.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Title"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _RoleExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _RoleExtension.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(RID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _RoleExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _RoleExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _RoleAssignmentCount; - usedByCount += _RolePermissionCount; - 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; } } - private static int _RoleUnique = 0; - protected static int RoleUnique - { get { return ++_RoleUnique; } } - private int _MyRoleUnique = RoleUnique; - public int MyRoleUnique // Absolutely Unique ID - Editable - { get { return _MyRoleUnique; } } - protected Role() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Role() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(RID.ToString())) - { - List listRole = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items - while (listRole.Contains(this)) listRole.Remove(this); // Remove the item from the list - if (listRole.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByName.Keys) - if (_CacheByName[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listRole = _CacheByName[myKey]; // Get the list of items - listRole.Remove(this); // Remove the item from the list - if (listRole.Count == 0) //If there are no items left in the list - _CacheByName.Remove(myKey); // remove the list - } - } - public static Role New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.New", ex); - } - } - public static Role New(string name, string title) - { - Role tmp = Role.New(); - tmp.Name = name; - tmp.Title = title; - return tmp; - } - public static Role MakeRole(string name, string title) - { - Role tmp = Role.New(name, title); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Role New(string name, string title, DateTime dts, string usrID) - { - Role tmp = Role.New(); - tmp.Name = name; - tmp.Title = title; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Role MakeRole(string name, string title, DateTime dts, string usrID) - { - Role tmp = Role.New(name, title, dts, usrID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Role Get(int rid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Role"); - try - { - Role tmp = GetCachedByPrimaryKey(rid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Role - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.Get", ex); - } - } - public static Role GetByName(string name) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Role"); - try - { - Role tmp = GetCachedByName(name); - if (tmp == null) - { - tmp = DataPortal.Fetch(new NameCriteria(name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Role - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.GetByName", ex); - } - } - public static Role Get(SafeDataReader dr) - { - if (dr.Read()) return new Role(dr); - return null; - } - internal Role(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); - try - { - DataPortal.Delete(new PKCriteria(rid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.Delete", ex); - } - } - public override Role Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Role"); - try - { - BuildRefreshList(); - Role role = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(role);//Refresh the item in AllList - ProcessRefreshList(); - return role; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _RID; - public int RID - { get { return _RID; } } - public PKCriteria(int rid) - { - _RID = rid; - } - } - [Serializable()] - private class NameCriteria - { - private string _Name; - public string Name - { get { return _Name; } } - public NameCriteria(string name) - { - _Name = name; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _RID = NextRID; - // Database Defaults - _DTS = _RoleExtension.DefaultDTS; - _UsrID = _RoleExtension.DefaultUsrID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.ReadData", GetHashCode()); - try - { - _RID = dr.GetInt32("RID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); - _RolePermissionCount = dr.GetInt32("PermissionCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRole"; - cm.Parameters.AddWithValue("@RID", criteria.RID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _RoleAssignments = RoleAssignments.Get(dr); - // load child objects - dr.NextResult(); - _RolePermissions = RolePermissions.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRoleByName"; - cm.Parameters.AddWithValue("@Name", criteria.Name); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UsrID", _UsrID); - // Output Calculated Columns - SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); - param_RID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RID); - 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 - _RID = (int)cm.Parameters["@newRID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UsrID", usrID); - // Output Calculated Columns - SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); - param_RID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RID); - 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 - rid = (int)cm.Parameters["@newRID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Add", ex); - throw new DbCslaException("Role.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Role.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRole"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RID", _RID); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Role.Add(cn, ref _RID, _Name, _Title, _DTS, _UsrID); - else - _LastChanged = Role.Update(cn, ref _RID, _Name, _Title, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RID", rid); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Update", ex); - throw new DbCslaException("Role.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_RID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRole"; - cm.Parameters.AddWithValue("@RID", criteria.RID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteRole"; - // Input PK Fields - cm.Parameters.AddWithValue("@RID", rid); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Remove", ex); - throw new DbCslaException("Role.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _RID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rid) - { - _RID = rid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsRole"; - cm.Parameters.AddWithValue("@RID", _RID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Execute", ex); - throw new DbCslaException("Role.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - RoleExtension _RoleExtension = new RoleExtension(); - [Serializable()] - partial class RoleExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RoleConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Role) - { - // Return the ToString value - return ((Role)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Role Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleConverter))] + public partial class Role : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRoles = new List(); + private List _RefreshRoleAssignments = new List(); + private List _RefreshRolePermissions = new List(); + private void AddToRefreshList(List refreshRoles, List refreshRoleAssignments, List refreshRolePermissions) + { + if (IsDirty) + refreshRoles.Add(this); + if (_RoleAssignments != null && _RoleAssignments.IsDirty) + { + foreach (RoleAssignment tmp in _RoleAssignments) + { + if (tmp.IsDirty) refreshRoleAssignments.Add(tmp); + } + } + if (_RolePermissions != null && _RolePermissions.IsDirty) + { + foreach (RolePermission tmp in _RolePermissions) + { + if (tmp.IsDirty) refreshRolePermissions.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshRoles = new List(); + _RefreshRoleAssignments = new List(); + _RefreshRolePermissions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshRoles, _RefreshRoleAssignments, _RefreshRolePermissions); + } + private void ProcessRefreshList() + { + foreach (Role tmp in _RefreshRoles) + { + RoleInfo.Refresh(tmp); + } + foreach (RoleAssignment tmp in _RefreshRoleAssignments) + { + AssignmentInfo.Refresh(tmp); + } + foreach (RolePermission tmp in _RefreshRolePermissions) + { + PermissionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Role role) + { + if (!_CacheList.Contains(role)) _CacheList.Add(role); // In AddToCache + } + protected static void RemoveFromCache(Role role) + { + while (_CacheList.Contains(role)) _CacheList.Remove(role); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByName = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Role(s) from temporary _CacheList to _CacheByPrimaryKey + { + Role tmp = _CacheList[0]; // Get the first Role + string pKey = tmp.RID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index + _CacheList.RemoveAt(0); // Remove the first Role + } + } + protected static Role GetCachedByPrimaryKey(int rid) + { + ConvertListToDictionary(); + string key = rid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Role GetCachedByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextRID = -1; + public static int NextRID + { + get { return _nextRID--; } + } + private int _RID; + [System.ComponentModel.DataObjectField(true, true)] + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RoleAssignmentCount = 0; + /// + /// Count of RoleAssignments for this Role + /// + public int RoleAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RoleAssignmentCount; + } + } + private RoleAssignments _RoleAssignments = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RoleAssignmentsConverter))] + public RoleAssignments RoleAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RoleAssignmentCount < 0 || (_RoleAssignmentCount > 0 && _RoleAssignments == null)) + _RoleAssignments = RoleAssignments.GetByRID(RID); + if (_RoleAssignmentCount < 0) + _RoleAssignmentCount = _RoleAssignments == null ? 0 : _RoleAssignments.Count; + if (_RoleAssignments == null) + _RoleAssignments = RoleAssignments.New(); + return _RoleAssignments; + } + } + public void Reset_RoleAssignments() + { + _RoleAssignmentCount = -1; + } + private int _RolePermissionCount = 0; + /// + /// Count of RolePermissions for this Role + /// + public int RolePermissionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RolePermissionCount; + } + } + private RolePermissions _RolePermissions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RolePermissionsConverter))] + public RolePermissions RolePermissions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RolePermissionCount < 0 || (_RolePermissionCount > 0 && _RolePermissions == null)) + _RolePermissions = RolePermissions.GetByRID(RID); + if (_RolePermissionCount < 0) + _RolePermissionCount = _RolePermissions == null ? 0 : _RolePermissions.Count; + if (_RolePermissions == null) + _RolePermissions = RolePermissions.New(); + return _RolePermissions; + } + } + public void Reset_RolePermissions() + { + _RolePermissionCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_RoleAssignments == null ? false : _RoleAssignments.IsDirtyList(list)) || (_RolePermissions == null ? false : _RolePermissions.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_RoleAssignments == null ? true : _RoleAssignments.IsValidList(list)) && (_RolePermissions == null ? true : _RolePermissions.IsValidList(list)); + } + // CSLATODO: Replace base Role.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Role + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Role.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Role + protected override object GetIdValue() + { + return MyRoleUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_RoleAssignments != null && (hasBrokenRules = _RoleAssignments.HasBrokenRules) != null) return hasBrokenRules; + if (_RolePermissions != null && (hasBrokenRules = _RolePermissions.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Title"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _RoleExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _RoleExtension.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(RID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _RoleExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _RoleExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _RoleAssignmentCount; + usedByCount += _RolePermissionCount; + 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; } } + private static int _RoleUnique = 0; + protected static int RoleUnique + { get { return ++_RoleUnique; } } + private int _MyRoleUnique = RoleUnique; + public int MyRoleUnique // Absolutely Unique ID - Editable + { get { return _MyRoleUnique; } } + protected Role() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Role() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(RID.ToString())) + { + List listRole = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items + while (listRole.Contains(this)) listRole.Remove(this); // Remove the item from the list + if (listRole.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByName.Keys) + if (_CacheByName[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listRole = _CacheByName[myKey]; // Get the list of items + listRole.Remove(this); // Remove the item from the list + if (listRole.Count == 0) //If there are no items left in the list + _CacheByName.Remove(myKey); // remove the list + } + } + public static Role New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Role"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.New", ex); + } + } + public static Role New(string name, string title) + { + Role tmp = Role.New(); + tmp.Name = name; + tmp.Title = title; + return tmp; + } + public static Role MakeRole(string name, string title) + { + Role tmp = Role.New(name, title); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Role New(string name, string title, DateTime dts, string usrID) + { + Role tmp = Role.New(); + tmp.Name = name; + tmp.Title = title; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Role MakeRole(string name, string title, DateTime dts, string usrID) + { + Role tmp = Role.New(name, title, dts, usrID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Role Get(int rid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Role"); + try + { + Role tmp = GetCachedByPrimaryKey(rid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Role + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.Get", ex); + } + } + public static Role GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Role"); + try + { + Role tmp = GetCachedByName(name); + if (tmp == null) + { + tmp = DataPortal.Fetch(new NameCriteria(name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Role + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.GetByName", ex); + } + } + public static Role Get(SafeDataReader dr) + { + if (dr.Read()) return new Role(dr); + return null; + } + internal Role(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Role"); + try + { + DataPortal.Delete(new PKCriteria(rid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.Delete", ex); + } + } + public override Role Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Role"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Role"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Role"); + try + { + BuildRefreshList(); + Role role = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(role);//Refresh the item in AllList + ProcessRefreshList(); + return role; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _RID; + public int RID + { get { return _RID; } } + public PKCriteria(int rid) + { + _RID = rid; + } + } + [Serializable()] + private class NameCriteria + { + private string _Name; + public string Name + { get { return _Name; } } + public NameCriteria(string name) + { + _Name = name; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _RID = NextRID; + // Database Defaults + _DTS = _RoleExtension.DefaultDTS; + _UsrID = _RoleExtension.DefaultUsrID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.ReadData", GetHashCode()); + try + { + _RID = dr.GetInt32("RID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); + _RolePermissionCount = dr.GetInt32("PermissionCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRole"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _RoleAssignments = RoleAssignments.Get(dr); + // load child objects + dr.NextResult(); + _RolePermissions = RolePermissions.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoleByName"; + cm.Parameters.AddWithValue("@Name", criteria.Name); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UsrID", _UsrID); + // Output Calculated Columns + SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); + param_RID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RID); + 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 + _RID = (int)cm.Parameters["@newRID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_RoleAssignments != null) _RoleAssignments.Update(this); + if (_RolePermissions != null) _RolePermissions.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UsrID", usrID); + // Output Calculated Columns + SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); + param_RID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RID); + 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 + rid = (int)cm.Parameters["@newRID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Add", ex); + throw new DbCslaException("Role.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Role.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRole"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RID", _RID); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_RoleAssignments != null) _RoleAssignments.Update(this); + if (_RolePermissions != null) _RolePermissions.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Role.Add(cn, ref _RID, _Name, _Title, _DTS, _UsrID); + else + _LastChanged = Role.Update(cn, ref _RID, _Name, _Title, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + if (_RoleAssignments != null) _RoleAssignments.Update(this); + if (_RolePermissions != null) _RolePermissions.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RID", rid); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Update", ex); + throw new DbCslaException("Role.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_RID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRole"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteRole"; + // Input PK Fields + cm.Parameters.AddWithValue("@RID", rid); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Remove", ex); + throw new DbCslaException("Role.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _RID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rid) + { + _RID = rid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsRole"; + cm.Parameters.AddWithValue("@RID", _RID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Execute", ex); + throw new DbCslaException("Role.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + RoleExtension _RoleExtension = new RoleExtension(); + [Serializable()] + partial class RoleExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RoleConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Role) + { + // Return the ToString value + return ((Role)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs index 2e10d367..e1d072f9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleAssignment.cs @@ -20,749 +20,718 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RoleAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoleAssignmentConverter))] - public partial class RoleAssignment : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - if (_MyAssignment != null) _AID = _MyAssignment.AID; - return _AID; - } - } - private Assignment _MyAssignment; - [System.ComponentModel.DataObjectField(true, true)] - public Assignment MyAssignment - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssignment", true); - if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); - return _MyAssignment; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - _GID = value.GID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - _FolderID = value.FolderID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - private string _Group_GroupName = string.Empty; - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupName", true); - return _Group_GroupName; - } - } - private int? _Group_GroupType; - public int? Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupType", true); - return _Group_GroupType; - } - } - private string _Group_Config = string.Empty; - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_Config", true); - return _Group_Config; - } - } - private DateTime _Group_DTS = new DateTime(); - public DateTime Group_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_DTS", true); - return _Group_DTS; - } - } - private string _Group_UsrID = string.Empty; - public string Group_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_UsrID", true); - return _Group_UsrID; - } - } - // CSLATODO: Check RoleAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoleAssignment - protected override object GetIdValue() - { - return MyRoleAssignmentUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RoleAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoleAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyGroupRequired(RoleAssignment target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyFolderRequired(RoleAssignment target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - private static int _RoleAssignmentUnique = 0; - private static int RoleAssignmentUnique - { get { return ++_RoleAssignmentUnique; } } - private int _MyRoleAssignmentUnique = RoleAssignmentUnique; - public int MyRoleAssignmentUnique // Absolutely Unique ID - Editable FK - { get { return _MyRoleAssignmentUnique; } } - internal static RoleAssignment New(Group myGroup, Folder myFolder) - { - return new RoleAssignment(myGroup, myFolder); - } - internal static RoleAssignment Get(SafeDataReader dr) - { - return new RoleAssignment(dr); - } - public RoleAssignment() - { - MarkAsChild(); - _AID = Assignment.NextAID; - _StartDate = _RoleAssignmentExtension.DefaultStartDate; - _DTS = _RoleAssignmentExtension.DefaultDTS; - _UsrID = _RoleAssignmentExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private RoleAssignment(Group myGroup, Folder myFolder) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _AID = Assignment.NextAID; - _StartDate = _RoleAssignmentExtension.DefaultStartDate; - _DTS = _RoleAssignmentExtension.DefaultDTS; - _UsrID = _RoleAssignmentExtension.DefaultUsrID; - _MyGroup = myGroup; - _MyFolder = myFolder; - ValidationRules.CheckRules(); - } - internal RoleAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RoleAssignment() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleAssignment.FetchDR", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _GID = dr.GetInt32("GID"); - _FolderID = dr.GetInt32("FolderID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - _Group_GroupName = dr.GetString("Group_GroupName"); - _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); - _Group_Config = dr.GetString("Group_Config"); - _Group_DTS = dr.GetDateTime("Group_DTS"); - _Group_UsrID = dr.GetString("Group_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleAssignment.FetchDR", ex); - throw new DbCslaException("RoleAssignment.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Role myRole) - { - // 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); - MarkOld(); - } - internal void Update(Role myRole) - { - // 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, myRole.RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Role myRole) - { - // 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RoleAssignmentExtension _RoleAssignmentExtension = new RoleAssignmentExtension(); - [Serializable()] - partial class RoleAssignmentExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RoleAssignmentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoleAssignment) - { - // Return the ToString value - return ((RoleAssignment)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RoleAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleAssignmentConverter))] + public partial class RoleAssignment : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment != null) _AID = _MyAssignment.AID; + return _AID; + } + } + private Assignment _MyAssignment; + [System.ComponentModel.DataObjectField(true, true)] + public Assignment MyAssignment + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); + return _MyAssignment; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + _GID = value.GID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + _FolderID = value.FolderID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + private string _Group_GroupName = string.Empty; + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupName; + } + } + private int? _Group_GroupType; + public int? Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupType; + } + } + private string _Group_Config = string.Empty; + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_Config; + } + } + private DateTime _Group_DTS = new DateTime(); + public DateTime Group_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_DTS; + } + } + private string _Group_UsrID = string.Empty; + public string Group_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_UsrID; + } + } + // CSLATODO: Check RoleAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoleAssignment + protected override object GetIdValue() + { + return MyRoleAssignmentUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RoleAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoleAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)) || (_MyFolder == null ? false : _MyFolder.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)) && (_MyFolder == null ? true : _MyFolder.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyGroupRequired(RoleAssignment target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyFolderRequired(RoleAssignment target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + private static int _RoleAssignmentUnique = 0; + private static int RoleAssignmentUnique + { get { return ++_RoleAssignmentUnique; } } + private int _MyRoleAssignmentUnique = RoleAssignmentUnique; + public int MyRoleAssignmentUnique // Absolutely Unique ID - Editable FK + { get { return _MyRoleAssignmentUnique; } } + internal static RoleAssignment New(Group myGroup, Folder myFolder) + { + return new RoleAssignment(myGroup, myFolder); + } + internal static RoleAssignment Get(SafeDataReader dr) + { + return new RoleAssignment(dr); + } + public RoleAssignment() + { + MarkAsChild(); + _AID = Assignment.NextAID; + _StartDate = _RoleAssignmentExtension.DefaultStartDate; + _DTS = _RoleAssignmentExtension.DefaultDTS; + _UsrID = _RoleAssignmentExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private RoleAssignment(Group myGroup, Folder myFolder) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _AID = Assignment.NextAID; + _StartDate = _RoleAssignmentExtension.DefaultStartDate; + _DTS = _RoleAssignmentExtension.DefaultDTS; + _UsrID = _RoleAssignmentExtension.DefaultUsrID; + _MyGroup = myGroup; + _MyFolder = myFolder; + ValidationRules.CheckRules(); + } + internal RoleAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RoleAssignment() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleAssignment.FetchDR", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _GID = dr.GetInt32("GID"); + _FolderID = dr.GetInt32("FolderID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + _Group_GroupName = dr.GetString("Group_GroupName"); + _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); + _Group_Config = dr.GetString("Group_Config"); + _Group_DTS = dr.GetDateTime("Group_DTS"); + _Group_UsrID = dr.GetString("Group_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleAssignment.FetchDR", ex); + throw new DbCslaException("RoleAssignment.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Role myRole) + { + // 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); + MarkOld(); + } + internal void Update(Role myRole) + { + // 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, myRole.RID, _FolderID, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Role myRole) + { + // 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RoleAssignmentExtension _RoleAssignmentExtension = new RoleAssignmentExtension(); + [Serializable()] + partial class RoleAssignmentExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RoleAssignmentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoleAssignment) + { + // Return the ToString value + return ((RoleAssignment)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs index 0d60507c..efcc37ea 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RoleInfo.cs @@ -19,415 +19,406 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void RoleInfoEvent(object sender); - /// - /// RoleInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoleInfoConverter))] - public partial class RoleInfo : ReadOnlyBase, IDisposable - { - public event RoleInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RoleInfo roleInfo) - { - if (!_CacheList.Contains(roleInfo)) _CacheList.Add(roleInfo); // In AddToCache - } - protected static void RemoveFromCache(RoleInfo roleInfo) - { - while (_CacheList.Contains(roleInfo)) _CacheList.Remove(roleInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move RoleInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - RoleInfo tmp = _CacheList[0]; // Get the first RoleInfo - string pKey = tmp.RID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first RoleInfo - } - } - internal static void AddList(RoleInfoList lst) - { - foreach (RoleInfo item in lst) AddToCache(item); - } - protected static RoleInfo GetCachedByPrimaryKey(int rid) - { - ConvertListToDictionary(); - string key = rid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Role _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _RID; - [System.ComponentModel.DataObjectField(true, true)] - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - return _RID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _RoleAssignmentCount = 0; - /// - /// Count of RoleAssignments for this Role - /// - public int RoleAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignmentCount", true); - if (_RoleAssignmentCount < 0) - _RoleAssignmentCount = RoleAssignments.Count; - return _RoleAssignmentCount; - } - } - private AssignmentInfoList _RoleAssignments = null; - [TypeConverter(typeof(AssignmentInfoListConverter))] - public AssignmentInfoList RoleAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignments", true); - if (_RoleAssignmentCount < 0 || (_RoleAssignmentCount > 0 && _RoleAssignments == null)) - _RoleAssignments = AssignmentInfoList.GetByRID(_RID); - if (_RoleAssignmentCount < 0) - _RoleAssignmentCount = _RoleAssignments.Count; - return _RoleAssignments; - } - } - public void RefreshRoleAssignments() - { - _RoleAssignmentCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) - foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) - tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried - } - private int _RolePermissionCount = 0; - /// - /// Count of RolePermissions for this Role - /// - public int RolePermissionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissionCount", true); - if (_RolePermissionCount < 0) - _RolePermissionCount = RolePermissions.Count; - return _RolePermissionCount; - } - } - private PermissionInfoList _RolePermissions = null; - [TypeConverter(typeof(PermissionInfoListConverter))] - public PermissionInfoList RolePermissions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissions", true); - if (_RolePermissionCount < 0 || (_RolePermissionCount > 0 && _RolePermissions == null)) - _RolePermissions = PermissionInfoList.GetByRID(_RID); - if (_RolePermissionCount < 0) - _RolePermissionCount = _RolePermissions.Count; - return _RolePermissions; - } - } - public void RefreshRolePermissions() - { - _RolePermissionCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) - foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) - tmp._RolePermissionCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base RoleInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoleInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check RoleInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoleInfo - protected override object GetIdValue() - { - return MyRoleInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _RoleInfoUnique = 0; - private static int RoleInfoUnique - { get { return ++_RoleInfoUnique; } } - private int _MyRoleInfoUnique = RoleInfoUnique; - public int MyRoleInfoUnique // Absolutely Unique ID - Info - { get { return _MyRoleInfoUnique; } } - protected RoleInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~RoleInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(RID.ToString())) return; - List listRoleInfo = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items - while (listRoleInfo.Contains(this)) listRoleInfo.Remove(this); // Remove the item from the list - if (listRoleInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list - } - public virtual Role Get() - { - return _Editable = Role.Get(_RID); - } - public static void Refresh(Role tmp) - { - string key = tmp.RID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoleInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Role tmp) - { - _Name = tmp.Name; - _Title = tmp.Title; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _RoleInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static RoleInfo Get(int rid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Role"); - try - { - RoleInfo tmp = GetCachedByPrimaryKey(rid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RoleInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoleInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal RoleInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.Constructor", ex); - throw new DbCslaException("RoleInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _RID; - public int RID - { get { return _RID; } } - public PKCriteria(int rid) - { - _RID = rid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.ReadData", GetHashCode()); - try - { - _RID = dr.GetInt32("RID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); - _RolePermissionCount = dr.GetInt32("PermissionCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoleInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRole"; - cm.Parameters.AddWithValue("@RID", criteria.RID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoleInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - RoleInfoExtension _RoleInfoExtension = new RoleInfoExtension(); - [Serializable()] - partial class RoleInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(RoleInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class RoleInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoleInfo) - { - // Return the ToString value - return ((RoleInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void RoleInfoEvent(object sender); + /// + /// RoleInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleInfoConverter))] + public partial class RoleInfo : ReadOnlyBase, IDisposable + { + public event RoleInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RoleInfo roleInfo) + { + if (!_CacheList.Contains(roleInfo)) _CacheList.Add(roleInfo); // In AddToCache + } + protected static void RemoveFromCache(RoleInfo roleInfo) + { + while (_CacheList.Contains(roleInfo)) _CacheList.Remove(roleInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move RoleInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + RoleInfo tmp = _CacheList[0]; // Get the first RoleInfo + string pKey = tmp.RID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first RoleInfo + } + } + internal static void AddList(RoleInfoList lst) + { + foreach (RoleInfo item in lst) AddToCache(item); + } + protected static RoleInfo GetCachedByPrimaryKey(int rid) + { + ConvertListToDictionary(); + string key = rid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Role _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _RID; + [System.ComponentModel.DataObjectField(true, true)] + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _RoleAssignmentCount = 0; + /// + /// Count of RoleAssignments for this Role + /// + public int RoleAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RoleAssignmentCount < 0) + _RoleAssignmentCount = RoleAssignments.Count; + return _RoleAssignmentCount; + } + } + private AssignmentInfoList _RoleAssignments = null; + [TypeConverter(typeof(AssignmentInfoListConverter))] + public AssignmentInfoList RoleAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RoleAssignmentCount < 0 || (_RoleAssignmentCount > 0 && _RoleAssignments == null)) + _RoleAssignments = AssignmentInfoList.GetByRID(_RID); + if (_RoleAssignmentCount < 0) + _RoleAssignmentCount = _RoleAssignments.Count; + return _RoleAssignments; + } + } + public void RefreshRoleAssignments() + { + _RoleAssignmentCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) + foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) + tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried + } + private int _RolePermissionCount = 0; + /// + /// Count of RolePermissions for this Role + /// + public int RolePermissionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RolePermissionCount < 0) + _RolePermissionCount = RolePermissions.Count; + return _RolePermissionCount; + } + } + private PermissionInfoList _RolePermissions = null; + [TypeConverter(typeof(PermissionInfoListConverter))] + public PermissionInfoList RolePermissions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RolePermissionCount < 0 || (_RolePermissionCount > 0 && _RolePermissions == null)) + _RolePermissions = PermissionInfoList.GetByRID(_RID); + if (_RolePermissionCount < 0) + _RolePermissionCount = _RolePermissions.Count; + return _RolePermissions; + } + } + public void RefreshRolePermissions() + { + _RolePermissionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) + foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) + tmp._RolePermissionCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base RoleInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoleInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check RoleInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoleInfo + protected override object GetIdValue() + { + return MyRoleInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _RoleInfoUnique = 0; + private static int RoleInfoUnique + { get { return ++_RoleInfoUnique; } } + private int _MyRoleInfoUnique = RoleInfoUnique; + public int MyRoleInfoUnique // Absolutely Unique ID - Info + { get { return _MyRoleInfoUnique; } } + protected RoleInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~RoleInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(RID.ToString())) return; + List listRoleInfo = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items + while (listRoleInfo.Contains(this)) listRoleInfo.Remove(this); // Remove the item from the list + if (listRoleInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list + } + public virtual Role Get() + { + return _Editable = Role.Get(_RID); + } + public static void Refresh(Role tmp) + { + string key = tmp.RID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoleInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Role tmp) + { + _Name = tmp.Name; + _Title = tmp.Title; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _RoleInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static RoleInfo Get(int rid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Role"); + try + { + RoleInfo tmp = GetCachedByPrimaryKey(rid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoleInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoleInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RoleInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.Constructor", ex); + throw new DbCslaException("RoleInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _RID; + public int RID + { get { return _RID; } } + public PKCriteria(int rid) + { + _RID = rid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.ReadData", GetHashCode()); + try + { + _RID = dr.GetInt32("RID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); + _RolePermissionCount = dr.GetInt32("PermissionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoleInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRole"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoleInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RoleInfoExtension _RoleInfoExtension = new RoleInfoExtension(); + [Serializable()] + partial class RoleInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RoleInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RoleInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoleInfo) + { + // Return the ToString value + return ((RoleInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/RolePermission.cs b/PROMS/VEPROMS.CSLA.Library/Generated/RolePermission.cs index df3889fa..d48fff75 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/RolePermission.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/RolePermission.cs @@ -20,617 +20,597 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RolePermission Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RolePermissionConverter))] - public partial class RolePermission : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _PID; - [System.ComponentModel.DataObjectField(true, true)] - public int PID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PID", true); - if (_MyPermission != null) _PID = _MyPermission.PID; - return _PID; - } - } - private Permission _MyPermission; - [System.ComponentModel.DataObjectField(true, true)] - public Permission MyPermission - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPermission", true); - if (_MyPermission == null && _PID != 0) _MyPermission = Permission.Get(_PID); - return _MyPermission; - } - } - private int _PermLevel; - /// - /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments - /// - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermLevel", true); - return _PermLevel; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermLevel", true); - if (_PermLevel != value) - { - _PermLevel = value; - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private int _PermValue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermValue", true); - return _PermValue; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermValue", true); - if (_PermValue != value) - { - _PermValue = value; - PropertyHasChanged(); - } - } - } - private int _PermAD; - /// - /// 0 - Allow, 1 - Deny - /// - public int PermAD - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermAD", true); - return _PermAD; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermAD", true); - if (_PermAD != value) - { - _PermAD = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // CSLATODO: Check RolePermission.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RolePermission - protected override object GetIdValue() - { - return MyRolePermissionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base RolePermission.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RolePermission - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(RolePermission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(RolePermission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - 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(PID, ""); - //AuthorizationRules.AllowRead(PermLevel, ""); - //AuthorizationRules.AllowWrite(PermLevel, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(PermValue, ""); - //AuthorizationRules.AllowWrite(PermValue, ""); - //AuthorizationRules.AllowRead(PermAD, ""); - //AuthorizationRules.AllowWrite(PermAD, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - private static int _RolePermissionUnique = 0; - private static int RolePermissionUnique - { get { return ++_RolePermissionUnique; } } - private int _MyRolePermissionUnique = RolePermissionUnique; - public int MyRolePermissionUnique // Absolutely Unique ID - Editable FK - { get { return _MyRolePermissionUnique; } } - internal static RolePermission New(int permLevel, int versionType, int permValue) - { - return new RolePermission(permLevel, versionType, permValue); - } - internal static RolePermission Get(SafeDataReader dr) - { - return new RolePermission(dr); - } - public RolePermission() - { - MarkAsChild(); - _PID = Permission.NextPID; - _PermAD = _RolePermissionExtension.DefaultPermAD; - _StartDate = _RolePermissionExtension.DefaultStartDate; - _DTS = _RolePermissionExtension.DefaultDTS; - _UsrID = _RolePermissionExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private RolePermission(int permLevel, int versionType, int permValue) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _PID = Permission.NextPID; - _PermAD = _RolePermissionExtension.DefaultPermAD; - _StartDate = _RolePermissionExtension.DefaultStartDate; - _DTS = _RolePermissionExtension.DefaultDTS; - _UsrID = _RolePermissionExtension.DefaultUsrID; - _PermLevel = permLevel; - _VersionType = versionType; - _PermValue = permValue; - ValidationRules.CheckRules(); - } - internal RolePermission(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~RolePermission() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RolePermission.FetchDR", GetHashCode()); - try - { - _PID = dr.GetInt32("PID"); - _PermLevel = dr.GetInt32("PermLevel"); - _VersionType = dr.GetInt32("VersionType"); - _PermValue = dr.GetInt32("PermValue"); - _PermAD = dr.GetInt32("PermAD"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RolePermission.FetchDR", ex); - throw new DbCslaException("RolePermission.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Role myRole) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Permission.Add(cn, ref _PID, myRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); - MarkOld(); - } - internal void Update(Role myRole) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Permission.Update(cn, ref _PID, myRole.RID, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Role myRole) - { - // 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"]; - Permission.Remove(cn, _PID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RolePermissionExtension _RolePermissionExtension = new RolePermissionExtension(); - [Serializable()] - partial class RolePermissionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultPermAD - { - get { return 0; } - } - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RolePermissionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RolePermission) - { - // Return the ToString value - return ((RolePermission)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RolePermission Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RolePermissionConverter))] + public partial class RolePermission : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _PID; + [System.ComponentModel.DataObjectField(true, true)] + public int PID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPermission != null) _PID = _MyPermission.PID; + return _PID; + } + } + private Permission _MyPermission; + [System.ComponentModel.DataObjectField(true, true)] + public Permission MyPermission + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPermission == null && _PID != 0) _MyPermission = Permission.Get(_PID); + return _MyPermission; + } + } + private int _PermLevel; + /// + /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments + /// + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermLevel; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermLevel != value) + { + _PermLevel = value; + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private int _PermValue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermValue; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermValue != value) + { + _PermValue = value; + PropertyHasChanged(); + } + } + } + private int _PermAD; + /// + /// 0 - Allow, 1 - Deny + /// + public int PermAD + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermAD; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermAD != value) + { + _PermAD = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // CSLATODO: Check RolePermission.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RolePermission + protected override object GetIdValue() + { + return MyRolePermissionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base RolePermission.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RolePermission + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(RolePermission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(RolePermission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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(PID, ""); + //AuthorizationRules.AllowRead(PermLevel, ""); + //AuthorizationRules.AllowWrite(PermLevel, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(PermValue, ""); + //AuthorizationRules.AllowWrite(PermValue, ""); + //AuthorizationRules.AllowRead(PermAD, ""); + //AuthorizationRules.AllowWrite(PermAD, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + private static int _RolePermissionUnique = 0; + private static int RolePermissionUnique + { get { return ++_RolePermissionUnique; } } + private int _MyRolePermissionUnique = RolePermissionUnique; + public int MyRolePermissionUnique // Absolutely Unique ID - Editable FK + { get { return _MyRolePermissionUnique; } } + internal static RolePermission New(int permLevel, int versionType, int permValue) + { + return new RolePermission(permLevel, versionType, permValue); + } + internal static RolePermission Get(SafeDataReader dr) + { + return new RolePermission(dr); + } + public RolePermission() + { + MarkAsChild(); + _PID = Permission.NextPID; + _PermAD = _RolePermissionExtension.DefaultPermAD; + _StartDate = _RolePermissionExtension.DefaultStartDate; + _DTS = _RolePermissionExtension.DefaultDTS; + _UsrID = _RolePermissionExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private RolePermission(int permLevel, int versionType, int permValue) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _PID = Permission.NextPID; + _PermAD = _RolePermissionExtension.DefaultPermAD; + _StartDate = _RolePermissionExtension.DefaultStartDate; + _DTS = _RolePermissionExtension.DefaultDTS; + _UsrID = _RolePermissionExtension.DefaultUsrID; + _PermLevel = permLevel; + _VersionType = versionType; + _PermValue = permValue; + ValidationRules.CheckRules(); + } + internal RolePermission(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~RolePermission() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RolePermission.FetchDR", GetHashCode()); + try + { + _PID = dr.GetInt32("PID"); + _PermLevel = dr.GetInt32("PermLevel"); + _VersionType = dr.GetInt32("VersionType"); + _PermValue = dr.GetInt32("PermValue"); + _PermAD = dr.GetInt32("PermAD"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RolePermission.FetchDR", ex); + throw new DbCslaException("RolePermission.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Role myRole) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Permission.Add(cn, ref _PID, myRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); + MarkOld(); + } + internal void Update(Role myRole) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Permission.Update(cn, ref _PID, myRole.RID, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Role myRole) + { + // 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"]; + Permission.Remove(cn, _PID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RolePermissionExtension _RolePermissionExtension = new RolePermissionExtension(); + [Serializable()] + partial class RolePermissionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultPermAD + { + get { return 0; } + } + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RolePermissionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RolePermission) + { + // Return the ToString value + return ((RolePermission)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Session.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Session.cs index 03e7f44c..713d67e5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Session.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Session.cs @@ -20,1028 +20,1015 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Session Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(SessionConverter))] - public partial class Session : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshSessions = new List(); - private void AddToRefreshList(List refreshSessions) - { - if (IsDirty) - refreshSessions.Add(this); - } - private void ClearRefreshList() - { - _RefreshSessions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshSessions); - } - private void ProcessRefreshList() - { - foreach (Session tmp in _RefreshSessions) - { - SessionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Session session) - { - if (!_CacheList.Contains(session)) _CacheList.Add(session); // In AddToCache - } - protected static void RemoveFromCache(Session session) - { - while (_CacheList.Contains(session)) _CacheList.Remove(session); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Session(s) from temporary _CacheList to _CacheByPrimaryKey - { - Session tmp = _CacheList[0]; // Get the first Session - string pKey = tmp.SessionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Session - } - } - protected static Session GetCachedByPrimaryKey(int sessionID) - { - ConvertListToDictionary(); - string key = sessionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextSessionID = -1; - public static int NextSessionID - { - get { return _nextSessionID--; } - } - private int _SessionID; - [System.ComponentModel.DataObjectField(true, true)] - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTSDtart = new DateTime(); - public DateTime DTSDtart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSDtart", true); - return _DTSDtart; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSDtart", true); - if (_DTSDtart != value) - { - _DTSDtart = value; - PropertyHasChanged(); - } - } - } - private DateTime? _DTSEnd; - public DateTime? DTSEnd - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSEnd", true); - return _DTSEnd; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSEnd", true); - if (_DTSEnd != value) - { - _DTSEnd = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTSActivity = new DateTime(); - public DateTime DTSActivity - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSActivity", true); - return _DTSActivity; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSActivity", true); - if (_DTSActivity != value) - { - _DTSActivity = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _MachineName = string.Empty; - public string MachineName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MachineName", true); - return _MachineName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MachineName", true); - if (value == null) value = string.Empty; - if (_MachineName != value) - { - _MachineName = value; - PropertyHasChanged(); - } - } - } - private int _ProcessID; - public int ProcessID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ProcessID", true); - return _ProcessID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ProcessID", true); - if (_ProcessID != value) - { - _ProcessID = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base Session.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Session - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Session.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Session - protected override object GetIdValue() - { - return MySessionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "MachineName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("MachineName", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _SessionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _SessionExtension.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(SessionID, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DTSDtart, ""); - //AuthorizationRules.AllowRead(DTSEnd, ""); - //AuthorizationRules.AllowRead(DTSActivity, ""); - //AuthorizationRules.AllowRead(MachineName, ""); - //AuthorizationRules.AllowRead(ProcessID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DTSDtart, ""); - //AuthorizationRules.AllowWrite(DTSEnd, ""); - //AuthorizationRules.AllowWrite(DTSActivity, ""); - //AuthorizationRules.AllowWrite(MachineName, ""); - //AuthorizationRules.AllowWrite(ProcessID, ""); - _SessionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _SessionExtension.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; } } - private static int _SessionUnique = 0; - protected static int SessionUnique - { get { return ++_SessionUnique; } } - private int _MySessionUnique = SessionUnique; - public int MySessionUnique // Absolutely Unique ID - Editable - { get { return _MySessionUnique; } } - protected Session() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Session() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) - { - List listSession = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items - while (listSession.Contains(this)) listSession.Remove(this); // Remove the item from the list - if (listSession.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list - } - } - public static Session New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Session"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.New", ex); - } - } - public static Session New(string machineName, int processID) - { - Session tmp = Session.New(); - tmp.MachineName = machineName; - tmp.ProcessID = processID; - return tmp; - } - public static Session New(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) - { - Session tmp = Session.New(); - tmp.UserID = userID; - tmp.DTSDtart = dTSDtart; - tmp.DTSEnd = dTSEnd; - tmp.DTSActivity = dTSActivity; - tmp.MachineName = machineName; - tmp.ProcessID = processID; - return tmp; - } - public static Session MakeSession(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) - { - Session tmp = Session.New(userID, dTSDtart, dTSEnd, dTSActivity, machineName, processID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Session New(DateTime? dTSEnd, string machineName, int processID) - { - Session tmp = Session.New(); - tmp.DTSEnd = dTSEnd; - tmp.MachineName = machineName; - tmp.ProcessID = processID; - return tmp; - } - public static Session MakeSession(DateTime? dTSEnd, string machineName, int processID) - { - Session tmp = Session.New(dTSEnd, machineName, processID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Session Get(int sessionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Session"); - try - { - Session tmp = GetCachedByPrimaryKey(sessionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(sessionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Session - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.Get", ex); - } - } - public static Session Get(SafeDataReader dr) - { - if (dr.Read()) return new Session(dr); - return null; - } - internal Session(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int sessionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Session"); - try - { - DataPortal.Delete(new PKCriteria(sessionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.Delete", ex); - } - } - public override Session Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Session"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Session"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Session"); - try - { - BuildRefreshList(); - Session session = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(session);//Refresh the item in AllList - ProcessRefreshList(); - return session; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _SessionID; - public int SessionID - { get { return _SessionID; } } - public PKCriteria(int sessionID) - { - _SessionID = sessionID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _SessionID = NextSessionID; - // Database Defaults - _UserID = _SessionExtension.DefaultUserID; - _DTSDtart = _SessionExtension.DefaultDTSDtart; - _DTSActivity = _SessionExtension.DefaultDTSActivity; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.ReadData", GetHashCode()); - try - { - _SessionID = dr.GetInt32("SessionID"); - _UserID = dr.GetString("UserID"); - _DTSDtart = dr.GetDateTime("DTSDtart"); - if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); - _DTSActivity = dr.GetDateTime("DTSActivity"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _MachineName = dr.GetString("MachineName"); - _ProcessID = dr.GetInt32("ProcessID"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "getSession"; - cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addSession"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", _UserID); - if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); - if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); - if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); - cm.Parameters.AddWithValue("@MachineName", _MachineName); - cm.Parameters.AddWithValue("@ProcessID", _ProcessID); - // Output Calculated Columns - SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); - param_SessionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_SessionID); - 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 - _SessionID = (int)cm.Parameters["@newSessionID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addSession"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", userID); - if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); - if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); - if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); - cm.Parameters.AddWithValue("@MachineName", machineName); - cm.Parameters.AddWithValue("@ProcessID", processID); - // Output Calculated Columns - SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); - param_SessionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_SessionID); - 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 - sessionID = (int)cm.Parameters["@newSessionID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Add", ex); - throw new DbCslaException("Session.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Session.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateSession"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@SessionID", _SessionID); - cm.Parameters.AddWithValue("@UserID", _UserID); - if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); - if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); - if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); - cm.Parameters.AddWithValue("@LastChanged", _LastChanged); - cm.Parameters.AddWithValue("@MachineName", _MachineName); - cm.Parameters.AddWithValue("@ProcessID", _ProcessID); - // 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Session.Add(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, _MachineName, _ProcessID); - else - _LastChanged = Session.Update(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, ref _LastChanged, _MachineName, _ProcessID); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, ref byte[] lastChanged, string machineName, int processID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateSession"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@SessionID", sessionID); - cm.Parameters.AddWithValue("@UserID", userID); - if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); - if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); - if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); - cm.Parameters.AddWithValue("@LastChanged", lastChanged); - cm.Parameters.AddWithValue("@MachineName", machineName); - cm.Parameters.AddWithValue("@ProcessID", processID); - // 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Update", ex); - throw new DbCslaException("Session.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_SessionID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteSession"; - cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int sessionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteSession"; - // Input PK Fields - cm.Parameters.AddWithValue("@SessionID", sessionID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Remove", ex); - throw new DbCslaException("Session.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int sessionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(sessionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _SessionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int sessionID) - { - _SessionID = sessionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsSession"; - cm.Parameters.AddWithValue("@SessionID", _SessionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Execute", ex); - throw new DbCslaException("Session.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - SessionExtension _SessionExtension = new SessionExtension(); - [Serializable()] - partial class SessionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - public virtual DateTime DefaultDTSDtart - { - get { return DateTime.Now; } - } - public virtual DateTime DefaultDTSActivity - { - get { return DateTime.Now; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class SessionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Session) - { - // Return the ToString value - return ((Session)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Session Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(SessionConverter))] + public partial class Session : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshSessions = new List(); + private void AddToRefreshList(List refreshSessions) + { + if (IsDirty) + refreshSessions.Add(this); + } + private void ClearRefreshList() + { + _RefreshSessions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshSessions); + } + private void ProcessRefreshList() + { + foreach (Session tmp in _RefreshSessions) + { + SessionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Session session) + { + if (!_CacheList.Contains(session)) _CacheList.Add(session); // In AddToCache + } + protected static void RemoveFromCache(Session session) + { + while (_CacheList.Contains(session)) _CacheList.Remove(session); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Session(s) from temporary _CacheList to _CacheByPrimaryKey + { + Session tmp = _CacheList[0]; // Get the first Session + string pKey = tmp.SessionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Session + } + } + protected static Session GetCachedByPrimaryKey(int sessionID) + { + ConvertListToDictionary(); + string key = sessionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextSessionID = -1; + public static int NextSessionID + { + get { return _nextSessionID--; } + } + private int _SessionID; + [System.ComponentModel.DataObjectField(true, true)] + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTSDtart = new DateTime(); + public DateTime DTSDtart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSDtart; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSDtart != value) + { + _DTSDtart = value; + PropertyHasChanged(); + } + } + } + private DateTime? _DTSEnd; + public DateTime? DTSEnd + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSEnd; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSEnd != value) + { + _DTSEnd = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTSActivity = new DateTime(); + public DateTime DTSActivity + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSActivity; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSActivity != value) + { + _DTSActivity = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _MachineName = string.Empty; + public string MachineName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MachineName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_MachineName != value) + { + _MachineName = value; + PropertyHasChanged(); + } + } + } + private int _ProcessID; + public int ProcessID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ProcessID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ProcessID != value) + { + _ProcessID = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base Session.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Session + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Session.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Session + protected override object GetIdValue() + { + return MySessionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "MachineName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("MachineName", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _SessionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _SessionExtension.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(SessionID, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DTSDtart, ""); + //AuthorizationRules.AllowRead(DTSEnd, ""); + //AuthorizationRules.AllowRead(DTSActivity, ""); + //AuthorizationRules.AllowRead(MachineName, ""); + //AuthorizationRules.AllowRead(ProcessID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DTSDtart, ""); + //AuthorizationRules.AllowWrite(DTSEnd, ""); + //AuthorizationRules.AllowWrite(DTSActivity, ""); + //AuthorizationRules.AllowWrite(MachineName, ""); + //AuthorizationRules.AllowWrite(ProcessID, ""); + _SessionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _SessionExtension.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; } } + private static int _SessionUnique = 0; + protected static int SessionUnique + { get { return ++_SessionUnique; } } + private int _MySessionUnique = SessionUnique; + public int MySessionUnique // Absolutely Unique ID - Editable + { get { return _MySessionUnique; } } + protected Session() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Session() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) + { + List listSession = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items + while (listSession.Contains(this)) listSession.Remove(this); // Remove the item from the list + if (listSession.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list + } + } + public static Session New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Session"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.New", ex); + } + } + public static Session New(string machineName, int processID) + { + Session tmp = Session.New(); + tmp.MachineName = machineName; + tmp.ProcessID = processID; + return tmp; + } + public static Session New(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) + { + Session tmp = Session.New(); + tmp.UserID = userID; + tmp.DTSDtart = dTSDtart; + tmp.DTSEnd = dTSEnd; + tmp.DTSActivity = dTSActivity; + tmp.MachineName = machineName; + tmp.ProcessID = processID; + return tmp; + } + public static Session MakeSession(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) + { + Session tmp = Session.New(userID, dTSDtart, dTSEnd, dTSActivity, machineName, processID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Session New(DateTime? dTSEnd, string machineName, int processID) + { + Session tmp = Session.New(); + tmp.DTSEnd = dTSEnd; + tmp.MachineName = machineName; + tmp.ProcessID = processID; + return tmp; + } + public static Session MakeSession(DateTime? dTSEnd, string machineName, int processID) + { + Session tmp = Session.New(dTSEnd, machineName, processID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Session Get(int sessionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Session"); + try + { + Session tmp = GetCachedByPrimaryKey(sessionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(sessionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Session + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.Get", ex); + } + } + public static Session Get(SafeDataReader dr) + { + if (dr.Read()) return new Session(dr); + return null; + } + internal Session(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int sessionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Session"); + try + { + DataPortal.Delete(new PKCriteria(sessionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.Delete", ex); + } + } + public override Session Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Session"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Session"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Session"); + try + { + BuildRefreshList(); + Session session = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(session);//Refresh the item in AllList + ProcessRefreshList(); + return session; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _SessionID; + public int SessionID + { get { return _SessionID; } } + public PKCriteria(int sessionID) + { + _SessionID = sessionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _SessionID = NextSessionID; + // Database Defaults + _UserID = _SessionExtension.DefaultUserID; + _DTSDtart = _SessionExtension.DefaultDTSDtart; + _DTSActivity = _SessionExtension.DefaultDTSActivity; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.ReadData", GetHashCode()); + try + { + _SessionID = dr.GetInt32("SessionID"); + _UserID = dr.GetString("UserID"); + _DTSDtart = dr.GetDateTime("DTSDtart"); + if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); + _DTSActivity = dr.GetDateTime("DTSActivity"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _MachineName = dr.GetString("MachineName"); + _ProcessID = dr.GetInt32("ProcessID"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "getSession"; + cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addSession"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", _UserID); + if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); + if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); + if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); + cm.Parameters.AddWithValue("@MachineName", _MachineName); + cm.Parameters.AddWithValue("@ProcessID", _ProcessID); + // Output Calculated Columns + SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); + param_SessionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_SessionID); + 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 + _SessionID = (int)cm.Parameters["@newSessionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addSession"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", userID); + if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); + if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); + if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); + cm.Parameters.AddWithValue("@MachineName", machineName); + cm.Parameters.AddWithValue("@ProcessID", processID); + // Output Calculated Columns + SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); + param_SessionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_SessionID); + 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 + sessionID = (int)cm.Parameters["@newSessionID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Add", ex); + throw new DbCslaException("Session.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Session.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateSession"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@SessionID", _SessionID); + cm.Parameters.AddWithValue("@UserID", _UserID); + if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); + if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); + if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); + cm.Parameters.AddWithValue("@LastChanged", _LastChanged); + cm.Parameters.AddWithValue("@MachineName", _MachineName); + cm.Parameters.AddWithValue("@ProcessID", _ProcessID); + // 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Session.Add(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, _MachineName, _ProcessID); + else + _LastChanged = Session.Update(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, ref _LastChanged, _MachineName, _ProcessID); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, ref byte[] lastChanged, string machineName, int processID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateSession"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@SessionID", sessionID); + cm.Parameters.AddWithValue("@UserID", userID); + if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); + if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); + if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); + cm.Parameters.AddWithValue("@LastChanged", lastChanged); + cm.Parameters.AddWithValue("@MachineName", machineName); + cm.Parameters.AddWithValue("@ProcessID", processID); + // 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Update", ex); + throw new DbCslaException("Session.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_SessionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteSession"; + cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int sessionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteSession"; + // Input PK Fields + cm.Parameters.AddWithValue("@SessionID", sessionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Remove", ex); + throw new DbCslaException("Session.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int sessionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(sessionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _SessionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int sessionID) + { + _SessionID = sessionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsSession"; + cm.Parameters.AddWithValue("@SessionID", _SessionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Execute", ex); + throw new DbCslaException("Session.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + SessionExtension _SessionExtension = new SessionExtension(); + [Serializable()] + partial class SessionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + public virtual DateTime DefaultDTSDtart + { + get { return DateTime.Now; } + } + public virtual DateTime DefaultDTSActivity + { + get { return DateTime.Now; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class SessionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Session) + { + // Return the ToString value + return ((Session)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/SessionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/SessionInfo.cs index 60f12eb1..01dd67ff 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/SessionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/SessionInfo.cs @@ -19,363 +19,356 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void SessionInfoEvent(object sender); - /// - /// SessionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(SessionInfoConverter))] - public partial class SessionInfo : ReadOnlyBase, IDisposable - { - public event SessionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(SessionInfo sessionInfo) - { - if (!_CacheList.Contains(sessionInfo)) _CacheList.Add(sessionInfo); // In AddToCache - } - protected static void RemoveFromCache(SessionInfo sessionInfo) - { - while (_CacheList.Contains(sessionInfo)) _CacheList.Remove(sessionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move SessionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - SessionInfo tmp = _CacheList[0]; // Get the first SessionInfo - string pKey = tmp.SessionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first SessionInfo - } - } - internal static void AddList(SessionInfoList lst) - { - foreach (SessionInfo item in lst) AddToCache(item); - } - protected static SessionInfo GetCachedByPrimaryKey(int sessionID) - { - ConvertListToDictionary(); - string key = sessionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Session _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _SessionID; - [System.ComponentModel.DataObjectField(true, true)] - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private DateTime _DTSDtart = new DateTime(); - public DateTime DTSDtart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSDtart", true); - return _DTSDtart; - } - } - private DateTime? _DTSEnd; - public DateTime? DTSEnd - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSEnd", true); - return _DTSEnd; - } - } - private DateTime _DTSActivity = new DateTime(); - public DateTime DTSActivity - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSActivity", true); - return _DTSActivity; - } - } - private string _MachineName = string.Empty; - public string MachineName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MachineName", true); - return _MachineName; - } - } - private int _ProcessID; - public int ProcessID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ProcessID", true); - return _ProcessID; - } - } - // CSLATODO: Replace base SessionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current SessionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check SessionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current SessionInfo - protected override object GetIdValue() - { - return MySessionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _SessionInfoUnique = 0; - private static int SessionInfoUnique - { get { return ++_SessionInfoUnique; } } - private int _MySessionInfoUnique = SessionInfoUnique; - public int MySessionInfoUnique // Absolutely Unique ID - Info - { get { return _MySessionInfoUnique; } } - protected SessionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~SessionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) return; - List listSessionInfo = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items - while (listSessionInfo.Contains(this)) listSessionInfo.Remove(this); // Remove the item from the list - if (listSessionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list - } - public virtual Session Get() - { - return _Editable = Session.Get(_SessionID); - } - public static void Refresh(Session tmp) - { - string key = tmp.SessionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (SessionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Session tmp) - { - _UserID = tmp.UserID; - _DTSDtart = tmp.DTSDtart; - _DTSEnd = tmp.DTSEnd; - _DTSActivity = tmp.DTSActivity; - _MachineName = tmp.MachineName; - _ProcessID = tmp.ProcessID; - _SessionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static SessionInfo Get(int sessionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Session"); - try - { - SessionInfo tmp = GetCachedByPrimaryKey(sessionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(sessionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up SessionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on SessionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal SessionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.Constructor", ex); - throw new DbCslaException("SessionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _SessionID; - public int SessionID - { get { return _SessionID; } } - public PKCriteria(int sessionID) - { - _SessionID = sessionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.ReadData", GetHashCode()); - try - { - _SessionID = dr.GetInt32("SessionID"); - _UserID = dr.GetString("UserID"); - _DTSDtart = dr.GetDateTime("DTSDtart"); - if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); - _DTSActivity = dr.GetDateTime("DTSActivity"); - _MachineName = dr.GetString("MachineName"); - _ProcessID = dr.GetInt32("ProcessID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _LastContentChange = dr.GetInt64("LastContentChange"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("SessionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "getSession"; - cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("SessionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - SessionInfoExtension _SessionInfoExtension = new SessionInfoExtension(); - [Serializable()] - partial class SessionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(SessionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class SessionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is SessionInfo) - { - // Return the ToString value - return ((SessionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void SessionInfoEvent(object sender); + /// + /// SessionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(SessionInfoConverter))] + public partial class SessionInfo : ReadOnlyBase, IDisposable + { + public event SessionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(SessionInfo sessionInfo) + { + if (!_CacheList.Contains(sessionInfo)) _CacheList.Add(sessionInfo); // In AddToCache + } + protected static void RemoveFromCache(SessionInfo sessionInfo) + { + while (_CacheList.Contains(sessionInfo)) _CacheList.Remove(sessionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move SessionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + SessionInfo tmp = _CacheList[0]; // Get the first SessionInfo + string pKey = tmp.SessionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first SessionInfo + } + } + internal static void AddList(SessionInfoList lst) + { + foreach (SessionInfo item in lst) AddToCache(item); + } + protected static SessionInfo GetCachedByPrimaryKey(int sessionID) + { + ConvertListToDictionary(); + string key = sessionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Session _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _SessionID; + [System.ComponentModel.DataObjectField(true, true)] + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private DateTime _DTSDtart = new DateTime(); + public DateTime DTSDtart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSDtart; + } + } + private DateTime? _DTSEnd; + public DateTime? DTSEnd + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSEnd; + } + } + private DateTime _DTSActivity = new DateTime(); + public DateTime DTSActivity + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSActivity; + } + } + private string _MachineName = string.Empty; + public string MachineName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MachineName; + } + } + private int _ProcessID; + public int ProcessID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ProcessID; + } + } + // CSLATODO: Replace base SessionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current SessionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check SessionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current SessionInfo + protected override object GetIdValue() + { + return MySessionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _SessionInfoUnique = 0; + private static int SessionInfoUnique + { get { return ++_SessionInfoUnique; } } + private int _MySessionInfoUnique = SessionInfoUnique; + public int MySessionInfoUnique // Absolutely Unique ID - Info + { get { return _MySessionInfoUnique; } } + protected SessionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~SessionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) return; + List listSessionInfo = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items + while (listSessionInfo.Contains(this)) listSessionInfo.Remove(this); // Remove the item from the list + if (listSessionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list + } + public virtual Session Get() + { + return _Editable = Session.Get(_SessionID); + } + public static void Refresh(Session tmp) + { + string key = tmp.SessionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (SessionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Session tmp) + { + _UserID = tmp.UserID; + _DTSDtart = tmp.DTSDtart; + _DTSEnd = tmp.DTSEnd; + _DTSActivity = tmp.DTSActivity; + _MachineName = tmp.MachineName; + _ProcessID = tmp.ProcessID; + _SessionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static SessionInfo Get(int sessionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Session"); + try + { + SessionInfo tmp = GetCachedByPrimaryKey(sessionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(sessionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up SessionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on SessionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal SessionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.Constructor", ex); + throw new DbCslaException("SessionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _SessionID; + public int SessionID + { get { return _SessionID; } } + public PKCriteria(int sessionID) + { + _SessionID = sessionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.ReadData", GetHashCode()); + try + { + _SessionID = dr.GetInt32("SessionID"); + _UserID = dr.GetString("UserID"); + _DTSDtart = dr.GetDateTime("DTSDtart"); + if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); + _DTSActivity = dr.GetDateTime("DTSActivity"); + _MachineName = dr.GetString("MachineName"); + _ProcessID = dr.GetInt32("ProcessID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _LastContentChange = dr.GetInt64("LastContentChange"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("SessionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "getSession"; + cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("SessionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + SessionInfoExtension _SessionInfoExtension = new SessionInfoExtension(); + [Serializable()] + partial class SessionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(SessionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class SessionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is SessionInfo) + { + // Return the ToString value + return ((SessionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs index 21a10f63..05dcf71e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Stage.cs @@ -20,1143 +20,1128 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Stage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(StageConverter))] - public partial class Stage : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshStages = new List(); - private List _RefreshStageChecks = new List(); - private List _RefreshStageVersions = new List(); - private void AddToRefreshList(List refreshStages, List refreshStageChecks, List refreshStageVersions) - { - if (IsDirty) - refreshStages.Add(this); - if (_StageChecks != null && _StageChecks.IsDirty) - { - foreach (StageCheck tmp in _StageChecks) - { - if (tmp.IsDirty) refreshStageChecks.Add(tmp); - } - } - if (_StageVersions != null && _StageVersions.IsDirty) - { - foreach (StageVersion tmp in _StageVersions) - { - if (tmp.IsDirty) refreshStageVersions.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshStages = new List(); - _RefreshStageChecks = new List(); - _RefreshStageVersions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshStages, _RefreshStageChecks, _RefreshStageVersions); - } - private void ProcessRefreshList() - { - foreach (Stage tmp in _RefreshStages) - { - StageInfo.Refresh(tmp); - } - foreach (StageCheck tmp in _RefreshStageChecks) - { - CheckInfo.Refresh(tmp); - } - foreach (StageVersion tmp in _RefreshStageVersions) - { - VersionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Stage stage) - { - if (!_CacheList.Contains(stage)) _CacheList.Add(stage); // In AddToCache - } - protected static void RemoveFromCache(Stage stage) - { - while (_CacheList.Contains(stage)) _CacheList.Remove(stage); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Stage(s) from temporary _CacheList to _CacheByPrimaryKey - { - Stage tmp = _CacheList[0]; // Get the first Stage - string pKey = tmp.StageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Stage - } - } - protected static Stage GetCachedByPrimaryKey(int stageID) - { - ConvertListToDictionary(); - string key = stageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextStageID = -1; - public static int NextStageID - { - get { return _nextStageID--; } - } - private int _StageID; - [System.ComponentModel.DataObjectField(true, true)] - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - return _StageID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Description = string.Empty; - public string Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Description", true); - return _Description; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Description", true); - if (value == null) value = string.Empty; - if (_Description != value) - { - _Description = value; - PropertyHasChanged(); - } - } - } - private int _IsApproved; - public int IsApproved - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("IsApproved", true); - return _IsApproved; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("IsApproved", true); - if (_IsApproved != value) - { - _IsApproved = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _StageCheckCount = 0; - /// - /// Count of StageChecks for this Stage - /// - public int StageCheckCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageCheckCount", true); - return _StageCheckCount; - } - } - private StageChecks _StageChecks = null; - /// - /// Related Field - /// - [TypeConverter(typeof(StageChecksConverter))] - public StageChecks StageChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageChecks", true); - if (_StageCheckCount < 0 || (_StageCheckCount > 0 && _StageChecks == null)) - _StageChecks = StageChecks.GetByStageID(StageID); - if (_StageCheckCount < 0 ) - _StageCheckCount = _StageChecks == null ? 0 : _StageChecks.Count; - if (_StageChecks == null) - _StageChecks = StageChecks.New(); - return _StageChecks; - } - } - public void Reset_StageChecks() - { - _StageCheckCount = -1; - } - private int _StageVersionCount = 0; - /// - /// Count of StageVersions for this Stage - /// - public int StageVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageVersionCount", true); - return _StageVersionCount; - } - } - private StageVersions _StageVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(StageVersionsConverter))] - public StageVersions StageVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageVersions", true); - if (_StageVersionCount < 0 || (_StageVersionCount > 0 && _StageVersions == null)) - _StageVersions = StageVersions.GetByStageID(StageID); - if (_StageVersionCount < 0 ) - _StageVersionCount = _StageVersions == null ? 0 : _StageVersions.Count; - if (_StageVersions == null) - _StageVersions = StageVersions.New(); - return _StageVersions; - } - } - public void Reset_StageVersions() - { - _StageVersionCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_StageChecks == null ? false : _StageChecks.IsDirtyList(list)) || (_StageVersions == null ? false : _StageVersions.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_StageChecks == null ? true : _StageChecks.IsValidList(list)) && (_StageVersions == null ? true : _StageVersions.IsValidList(list)); - } - // CSLATODO: Replace base Stage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Stage - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Stage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Stage - protected override object GetIdValue() - { - return MyStageUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_StageChecks != null && (hasBrokenRules = _StageChecks.HasBrokenRules) != null) return hasBrokenRules; - if (_StageVersions != null && (hasBrokenRules = _StageVersions.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 200)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _StageExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _StageExtension.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(StageID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Description, ""); - //AuthorizationRules.AllowRead(IsApproved, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Description, ""); - //AuthorizationRules.AllowWrite(IsApproved, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _StageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _StageExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _StageCheckCount; - usedByCount += _StageVersionCount; - 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; } } - private static int _StageUnique = 0; - protected static int StageUnique - { get { return ++_StageUnique; } } - private int _MyStageUnique = StageUnique; - public int MyStageUnique // Absolutely Unique ID - Editable - { get { return _MyStageUnique; } } - protected Stage() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Stage() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(StageID.ToString())) - { - List listStage = _CacheByPrimaryKey[StageID.ToString()]; // Get the list of items - while (listStage.Contains(this)) listStage.Remove(this); // Remove the item from the list - if (listStage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(StageID.ToString()); // remove the list - } - } - public static Stage New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Stage"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Stage.New", ex); - } - } - public static Stage New(string name) - { - Stage tmp = Stage.New(); - tmp.Name = name; - return tmp; - } - public static Stage New(string name, string description, int isApproved, DateTime dts, string userID) - { - Stage tmp = Stage.New(); - tmp.Name = name; - tmp.Description = description; - tmp.IsApproved = isApproved; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Stage MakeStage(string name, string description, int isApproved, DateTime dts, string userID) - { - Stage tmp = Stage.New(name, description, isApproved, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Stage New(string name, string description) - { - Stage tmp = Stage.New(); - tmp.Name = name; - tmp.Description = description; - return tmp; - } - public static Stage MakeStage(string name, string description) - { - Stage tmp = Stage.New(name, description); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Stage Get(int stageID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Stage"); - try - { - Stage tmp = GetCachedByPrimaryKey(stageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(stageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Stage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Stage.Get", ex); - } - } - public static Stage Get(SafeDataReader dr) - { - if (dr.Read()) return new Stage(dr); - return null; - } - internal Stage(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int stageID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Stage"); - try - { - DataPortal.Delete(new PKCriteria(stageID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Stage.Delete", ex); - } - } - public override Stage Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Stage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Stage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Stage"); - try - { - BuildRefreshList(); - Stage stage = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(stage);//Refresh the item in AllList - ProcessRefreshList(); - return stage; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _StageID; - public int StageID - { get { return _StageID; } } - public PKCriteria(int stageID) - { - _StageID = stageID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _StageID = NextStageID; - // Database Defaults - _IsApproved = _StageExtension.DefaultIsApproved; - _DTS = _StageExtension.DefaultDTS; - _UserID = _StageExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.ReadData", GetHashCode()); - try - { - _StageID = dr.GetInt32("StageID"); - _Name = dr.GetString("Name"); - _Description = dr.GetString("Description"); - _IsApproved = dr.GetInt32("IsApproved"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _StageCheckCount = dr.GetInt32("CheckCount"); - _StageVersionCount = dr.GetInt32("VersionCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Stage.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getStage"; - cm.Parameters.AddWithValue("@StageID", criteria.StageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _StageChecks = StageChecks.Get(dr); - // load child objects - dr.NextResult(); - _StageVersions = StageVersions.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Stage.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Stage.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addStage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Description", _Description); - cm.Parameters.AddWithValue("@IsApproved", _IsApproved); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - // Output Calculated Columns - SqlParameter param_StageID = new SqlParameter("@newStageID", SqlDbType.Int); - param_StageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_StageID); - 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 - _StageID = (int)cm.Parameters["@newStageID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_StageChecks != null) _StageChecks.Update(this); - if (_StageVersions != null) _StageVersions.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Stage.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int stageID, string name, string description, int isApproved, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addStage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Description", description); - cm.Parameters.AddWithValue("@IsApproved", isApproved); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UserID", userID); - // Output Calculated Columns - SqlParameter param_StageID = new SqlParameter("@newStageID", SqlDbType.Int); - param_StageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_StageID); - 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 - stageID = (int)cm.Parameters["@newStageID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Add", ex); - throw new DbCslaException("Stage.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Stage.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateStage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@StageID", _StageID); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Description", _Description); - cm.Parameters.AddWithValue("@IsApproved", _IsApproved); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_StageChecks != null) _StageChecks.Update(this); - if (_StageVersions != null) _StageVersions.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Stage.Add(cn, ref _StageID, _Name, _Description, _IsApproved, _DTS, _UserID); - else - _LastChanged = Stage.Update(cn, ref _StageID, _Name, _Description, _IsApproved, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_StageChecks != null) _StageChecks.Update(this); - if (_StageVersions != null) _StageVersions.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int stageID, string name, string description, int isApproved, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateStage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@StageID", stageID); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Description", description); - cm.Parameters.AddWithValue("@IsApproved", isApproved); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Update", ex); - throw new DbCslaException("Stage.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_StageID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteStage"; - cm.Parameters.AddWithValue("@StageID", criteria.StageID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Stage.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int stageID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteStage"; - // Input PK Fields - cm.Parameters.AddWithValue("@StageID", stageID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Remove", ex); - throw new DbCslaException("Stage.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int stageID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(stageID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Stage.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _StageID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int stageID) - { - _StageID = stageID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsStage"; - cm.Parameters.AddWithValue("@StageID", _StageID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Execute", ex); - throw new DbCslaException("Stage.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - StageExtension _StageExtension = new StageExtension(); - [Serializable()] - partial class StageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultIsApproved - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class StageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Stage) - { - // Return the ToString value - return ((Stage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Stage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageConverter))] + public partial class Stage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshStages = new List(); + private List _RefreshStageChecks = new List(); + private List _RefreshStageVersions = new List(); + private void AddToRefreshList(List refreshStages, List refreshStageChecks, List refreshStageVersions) + { + if (IsDirty) + refreshStages.Add(this); + if (_StageChecks != null && _StageChecks.IsDirty) + { + foreach (StageCheck tmp in _StageChecks) + { + if (tmp.IsDirty) refreshStageChecks.Add(tmp); + } + } + if (_StageVersions != null && _StageVersions.IsDirty) + { + foreach (StageVersion tmp in _StageVersions) + { + if (tmp.IsDirty) refreshStageVersions.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshStages = new List(); + _RefreshStageChecks = new List(); + _RefreshStageVersions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshStages, _RefreshStageChecks, _RefreshStageVersions); + } + private void ProcessRefreshList() + { + foreach (Stage tmp in _RefreshStages) + { + StageInfo.Refresh(tmp); + } + foreach (StageCheck tmp in _RefreshStageChecks) + { + CheckInfo.Refresh(tmp); + } + foreach (StageVersion tmp in _RefreshStageVersions) + { + VersionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Stage stage) + { + if (!_CacheList.Contains(stage)) _CacheList.Add(stage); // In AddToCache + } + protected static void RemoveFromCache(Stage stage) + { + while (_CacheList.Contains(stage)) _CacheList.Remove(stage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Stage(s) from temporary _CacheList to _CacheByPrimaryKey + { + Stage tmp = _CacheList[0]; // Get the first Stage + string pKey = tmp.StageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Stage + } + } + protected static Stage GetCachedByPrimaryKey(int stageID) + { + ConvertListToDictionary(); + string key = stageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextStageID = -1; + public static int NextStageID + { + get { return _nextStageID--; } + } + private int _StageID; + [System.ComponentModel.DataObjectField(true, true)] + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StageID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Description; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Description != value) + { + _Description = value; + PropertyHasChanged(); + } + } + } + private int _IsApproved; + public int IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _IsApproved; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_IsApproved != value) + { + _IsApproved = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _StageCheckCount = 0; + /// + /// Count of StageChecks for this Stage + /// + public int StageCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StageCheckCount; + } + } + private StageChecks _StageChecks = null; + /// + /// Related Field + /// + [TypeConverter(typeof(StageChecksConverter))] + public StageChecks StageChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_StageCheckCount < 0 || (_StageCheckCount > 0 && _StageChecks == null)) + _StageChecks = StageChecks.GetByStageID(StageID); + if (_StageCheckCount < 0) + _StageCheckCount = _StageChecks == null ? 0 : _StageChecks.Count; + if (_StageChecks == null) + _StageChecks = StageChecks.New(); + return _StageChecks; + } + } + public void Reset_StageChecks() + { + _StageCheckCount = -1; + } + private int _StageVersionCount = 0; + /// + /// Count of StageVersions for this Stage + /// + public int StageVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StageVersionCount; + } + } + private StageVersions _StageVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(StageVersionsConverter))] + public StageVersions StageVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_StageVersionCount < 0 || (_StageVersionCount > 0 && _StageVersions == null)) + _StageVersions = StageVersions.GetByStageID(StageID); + if (_StageVersionCount < 0) + _StageVersionCount = _StageVersions == null ? 0 : _StageVersions.Count; + if (_StageVersions == null) + _StageVersions = StageVersions.New(); + return _StageVersions; + } + } + public void Reset_StageVersions() + { + _StageVersionCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_StageChecks == null ? false : _StageChecks.IsDirtyList(list)) || (_StageVersions == null ? false : _StageVersions.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_StageChecks == null ? true : _StageChecks.IsValidList(list)) && (_StageVersions == null ? true : _StageVersions.IsValidList(list)); + } + // CSLATODO: Replace base Stage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Stage + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Stage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Stage + protected override object GetIdValue() + { + return MyStageUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_StageChecks != null && (hasBrokenRules = _StageChecks.HasBrokenRules) != null) return hasBrokenRules; + if (_StageVersions != null && (hasBrokenRules = _StageVersions.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 200)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _StageExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _StageExtension.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(StageID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Description, ""); + //AuthorizationRules.AllowRead(IsApproved, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Description, ""); + //AuthorizationRules.AllowWrite(IsApproved, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _StageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _StageExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _StageCheckCount; + usedByCount += _StageVersionCount; + 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; } } + private static int _StageUnique = 0; + protected static int StageUnique + { get { return ++_StageUnique; } } + private int _MyStageUnique = StageUnique; + public int MyStageUnique // Absolutely Unique ID - Editable + { get { return _MyStageUnique; } } + protected Stage() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Stage() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(StageID.ToString())) + { + List listStage = _CacheByPrimaryKey[StageID.ToString()]; // Get the list of items + while (listStage.Contains(this)) listStage.Remove(this); // Remove the item from the list + if (listStage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(StageID.ToString()); // remove the list + } + } + public static Stage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Stage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.New", ex); + } + } + public static Stage New(string name) + { + Stage tmp = Stage.New(); + tmp.Name = name; + return tmp; + } + public static Stage New(string name, string description, int isApproved, DateTime dts, string userID) + { + Stage tmp = Stage.New(); + tmp.Name = name; + tmp.Description = description; + tmp.IsApproved = isApproved; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Stage MakeStage(string name, string description, int isApproved, DateTime dts, string userID) + { + Stage tmp = Stage.New(name, description, isApproved, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Stage New(string name, string description) + { + Stage tmp = Stage.New(); + tmp.Name = name; + tmp.Description = description; + return tmp; + } + public static Stage MakeStage(string name, string description) + { + Stage tmp = Stage.New(name, description); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Stage Get(int stageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Stage"); + try + { + Stage tmp = GetCachedByPrimaryKey(stageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(stageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Stage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.Get", ex); + } + } + public static Stage Get(SafeDataReader dr) + { + if (dr.Read()) return new Stage(dr); + return null; + } + internal Stage(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int stageID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Stage"); + try + { + DataPortal.Delete(new PKCriteria(stageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.Delete", ex); + } + } + public override Stage Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Stage"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Stage"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Stage"); + try + { + BuildRefreshList(); + Stage stage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(stage);//Refresh the item in AllList + ProcessRefreshList(); + return stage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _StageID; + public int StageID + { get { return _StageID; } } + public PKCriteria(int stageID) + { + _StageID = stageID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _StageID = NextStageID; + // Database Defaults + _IsApproved = _StageExtension.DefaultIsApproved; + _DTS = _StageExtension.DefaultDTS; + _UserID = _StageExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.ReadData", GetHashCode()); + try + { + _StageID = dr.GetInt32("StageID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _IsApproved = dr.GetInt32("IsApproved"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _StageCheckCount = dr.GetInt32("CheckCount"); + _StageVersionCount = dr.GetInt32("VersionCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getStage"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _StageChecks = StageChecks.Get(dr); + // load child objects + dr.NextResult(); + _StageVersions = StageVersions.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addStage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Description", _Description); + cm.Parameters.AddWithValue("@IsApproved", _IsApproved); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_StageID = new SqlParameter("@newStageID", SqlDbType.Int); + param_StageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_StageID); + 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 + _StageID = (int)cm.Parameters["@newStageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_StageChecks != null) _StageChecks.Update(this); + if (_StageVersions != null) _StageVersions.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int stageID, string name, string description, int isApproved, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addStage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Description", description); + cm.Parameters.AddWithValue("@IsApproved", isApproved); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_StageID = new SqlParameter("@newStageID", SqlDbType.Int); + param_StageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_StageID); + 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 + stageID = (int)cm.Parameters["@newStageID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Add", ex); + throw new DbCslaException("Stage.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Stage.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateStage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@StageID", _StageID); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Description", _Description); + cm.Parameters.AddWithValue("@IsApproved", _IsApproved); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_StageChecks != null) _StageChecks.Update(this); + if (_StageVersions != null) _StageVersions.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Stage.Add(cn, ref _StageID, _Name, _Description, _IsApproved, _DTS, _UserID); + else + _LastChanged = Stage.Update(cn, ref _StageID, _Name, _Description, _IsApproved, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_StageChecks != null) _StageChecks.Update(this); + if (_StageVersions != null) _StageVersions.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int stageID, string name, string description, int isApproved, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateStage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@StageID", stageID); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Description", description); + cm.Parameters.AddWithValue("@IsApproved", isApproved); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Update", ex); + throw new DbCslaException("Stage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_StageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteStage"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Stage.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int stageID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteStage"; + // Input PK Fields + cm.Parameters.AddWithValue("@StageID", stageID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.Remove", ex); + throw new DbCslaException("Stage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int stageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(stageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Stage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _StageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int stageID) + { + _StageID = stageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Stage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsStage"; + cm.Parameters.AddWithValue("@StageID", _StageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Stage.DataPortal_Execute", ex); + throw new DbCslaException("Stage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + StageExtension _StageExtension = new StageExtension(); + [Serializable()] + partial class StageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultIsApproved + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class StageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Stage) + { + // Return the ToString value + return ((Stage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs index d2413a0e..c541becc 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageCheck.cs @@ -20,549 +20,530 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// StageCheck Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(StageCheckConverter))] - public partial class StageCheck : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _CheckID; - [System.ComponentModel.DataObjectField(true, true)] - public int CheckID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CheckID", true); - if (_MyCheck != null) _CheckID = _MyCheck.CheckID; - return _CheckID; - } - } - private Check _MyCheck; - [System.ComponentModel.DataObjectField(true, true)] - public Check MyCheck - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyCheck", true); - if (_MyCheck == null && _CheckID != 0) _MyCheck = Check.Get(_CheckID); - return _MyCheck; - } - } - private int _RevisionID; - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; - return _RevisionID; - } - } - private Revision _MyRevision; - public Revision MyRevision - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRevision", true); - if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); - return _MyRevision; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRevision", true); - if (_MyRevision != value) - { - _MyRevision = value; - _RevisionID = value.RevisionID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _ConsistencyChecks = string.Empty; - public string ConsistencyChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConsistencyChecks", true); - return _ConsistencyChecks; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ConsistencyChecks", true); - if (value == null) value = string.Empty; - if (_ConsistencyChecks != value) - { - _ConsistencyChecks = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Revision_ItemID; - public int Revision_ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_ItemID", true); - return _Revision_ItemID; - } - } - private int _Revision_TypeID; - public int Revision_TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_TypeID", true); - return _Revision_TypeID; - } - } - private string _Revision_RevisionNumber = string.Empty; - public string Revision_RevisionNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_RevisionNumber", true); - return _Revision_RevisionNumber; - } - } - private DateTime? _Revision_RevisionDate; - public DateTime? Revision_RevisionDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_RevisionDate", true); - return _Revision_RevisionDate; - } - } - private string _Revision_Notes = string.Empty; - public string Revision_Notes - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_Notes", true); - return _Revision_Notes; - } - } - private string _Revision_Config = string.Empty; - public string Revision_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_Config", true); - return _Revision_Config; - } - } - private DateTime _Revision_DTS = new DateTime(); - public DateTime Revision_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_DTS", true); - return _Revision_DTS; - } - } - private string _Revision_UserID = string.Empty; - public string Revision_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_UserID", true); - return _Revision_UserID; - } - } - // CSLATODO: Check StageCheck.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current StageCheck - protected override object GetIdValue() - { - return MyStageCheckUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base StageCheck.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current StageCheck - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // CSLATODO: Add other validation rules - } - private static bool MyRevisionRequired(StageCheck target, Csla.Validation.RuleArgs e) - { - if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(CheckID, ""); - //AuthorizationRules.AllowRead(RevisionID, ""); - //AuthorizationRules.AllowWrite(RevisionID, ""); - //AuthorizationRules.AllowRead(ConsistencyChecks, ""); - //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _StageCheckUnique = 0; - private static int StageCheckUnique - { get { return ++_StageCheckUnique; } } - private int _MyStageCheckUnique = StageCheckUnique; - public int MyStageCheckUnique // Absolutely Unique ID - Editable FK - { get { return _MyStageCheckUnique; } } - internal static StageCheck New(Revision myRevision) - { - return new StageCheck(myRevision); - } - internal static StageCheck Get(SafeDataReader dr) - { - return new StageCheck(dr); - } - public StageCheck() - { - MarkAsChild(); - _CheckID = Check.NextCheckID; - _DTS = _StageCheckExtension.DefaultDTS; - _UserID = _StageCheckExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private StageCheck(Revision myRevision) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _CheckID = Check.NextCheckID; - _DTS = _StageCheckExtension.DefaultDTS; - _UserID = _StageCheckExtension.DefaultUserID; - _MyRevision = myRevision; - ValidationRules.CheckRules(); - } - internal StageCheck(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~StageCheck() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageCheck.FetchDR", GetHashCode()); - try - { - _CheckID = dr.GetInt32("CheckID"); - _RevisionID = dr.GetInt32("RevisionID"); - _ConsistencyChecks = dr.GetString("ConsistencyChecks"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Revision_ItemID = dr.GetInt32("Revision_ItemID"); - _Revision_TypeID = dr.GetInt32("Revision_TypeID"); - _Revision_RevisionNumber = dr.GetString("Revision_RevisionNumber"); - if (!dr.IsDBNull(dr.GetOrdinal("Revision_RevisionDate"))) _Revision_RevisionDate = dr.GetDateTime("Revision_RevisionDate"); - _Revision_Notes = dr.GetString("Revision_Notes"); - _Revision_Config = dr.GetString("Revision_Config"); - _Revision_DTS = dr.GetDateTime("Revision_DTS"); - _Revision_UserID = dr.GetString("Revision_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("StageCheck.FetchDR", ex); - throw new DbCslaException("StageCheck.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Stage myStage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, myStage, _ConsistencyChecks, _DTS, _UserID); - MarkOld(); - } - internal void Update(Stage myStage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, myStage.StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Stage myStage) - { - // 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"]; - Check.Remove(cn, _CheckID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - StageCheckExtension _StageCheckExtension = new StageCheckExtension(); - [Serializable()] - partial class StageCheckExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class StageCheckConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is StageCheck) - { - // Return the ToString value - return ((StageCheck)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// StageCheck Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageCheckConverter))] + public partial class StageCheck : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _CheckID; + [System.ComponentModel.DataObjectField(true, true)] + public int CheckID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyCheck != null) _CheckID = _MyCheck.CheckID; + return _CheckID; + } + } + private Check _MyCheck; + [System.ComponentModel.DataObjectField(true, true)] + public Check MyCheck + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyCheck == null && _CheckID != 0) _MyCheck = Check.Get(_CheckID); + return _MyCheck; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _ConsistencyChecks = string.Empty; + public string ConsistencyChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConsistencyChecks; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ConsistencyChecks != value) + { + _ConsistencyChecks = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Revision_ItemID; + public int Revision_ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_ItemID; + } + } + private int _Revision_TypeID; + public int Revision_TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_TypeID; + } + } + private string _Revision_RevisionNumber = string.Empty; + public string Revision_RevisionNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_RevisionNumber; + } + } + private DateTime? _Revision_RevisionDate; + public DateTime? Revision_RevisionDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_RevisionDate; + } + } + private string _Revision_Notes = string.Empty; + public string Revision_Notes + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_Notes; + } + } + private string _Revision_Config = string.Empty; + public string Revision_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_Config; + } + } + private DateTime _Revision_DTS = new DateTime(); + public DateTime Revision_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_DTS; + } + } + private string _Revision_UserID = string.Empty; + public string Revision_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_UserID; + } + } + // CSLATODO: Check StageCheck.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current StageCheck + protected override object GetIdValue() + { + return MyStageCheckUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base StageCheck.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current StageCheck + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsistencyChecks", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(StageCheck target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(CheckID, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowRead(ConsistencyChecks, ""); + //AuthorizationRules.AllowWrite(ConsistencyChecks, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _StageCheckUnique = 0; + private static int StageCheckUnique + { get { return ++_StageCheckUnique; } } + private int _MyStageCheckUnique = StageCheckUnique; + public int MyStageCheckUnique // Absolutely Unique ID - Editable FK + { get { return _MyStageCheckUnique; } } + internal static StageCheck New(Revision myRevision) + { + return new StageCheck(myRevision); + } + internal static StageCheck Get(SafeDataReader dr) + { + return new StageCheck(dr); + } + public StageCheck() + { + MarkAsChild(); + _CheckID = Check.NextCheckID; + _DTS = _StageCheckExtension.DefaultDTS; + _UserID = _StageCheckExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private StageCheck(Revision myRevision) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _CheckID = Check.NextCheckID; + _DTS = _StageCheckExtension.DefaultDTS; + _UserID = _StageCheckExtension.DefaultUserID; + _MyRevision = myRevision; + ValidationRules.CheckRules(); + } + internal StageCheck(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~StageCheck() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageCheck.FetchDR", GetHashCode()); + try + { + _CheckID = dr.GetInt32("CheckID"); + _RevisionID = dr.GetInt32("RevisionID"); + _ConsistencyChecks = dr.GetString("ConsistencyChecks"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Revision_ItemID = dr.GetInt32("Revision_ItemID"); + _Revision_TypeID = dr.GetInt32("Revision_TypeID"); + _Revision_RevisionNumber = dr.GetString("Revision_RevisionNumber"); + if (!dr.IsDBNull(dr.GetOrdinal("Revision_RevisionDate"))) _Revision_RevisionDate = dr.GetDateTime("Revision_RevisionDate"); + _Revision_Notes = dr.GetString("Revision_Notes"); + _Revision_Config = dr.GetString("Revision_Config"); + _Revision_DTS = dr.GetDateTime("Revision_DTS"); + _Revision_UserID = dr.GetString("Revision_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageCheck.FetchDR", ex); + throw new DbCslaException("StageCheck.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Add(cn, ref _CheckID, _MyRevision, myStage, _ConsistencyChecks, _DTS, _UserID); + MarkOld(); + } + internal void Update(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Check.Update(cn, ref _CheckID, _RevisionID, myStage.StageID, _ConsistencyChecks, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Stage myStage) + { + // 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"]; + Check.Remove(cn, _CheckID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + StageCheckExtension _StageCheckExtension = new StageCheckExtension(); + [Serializable()] + partial class StageCheckExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class StageCheckConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageCheck) + { + // Return the ToString value + return ((StageCheck)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs index 3cdf1410..2d4170d5 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageInfo.cs @@ -19,428 +19,418 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void StageInfoEvent(object sender); - /// - /// StageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(StageInfoConverter))] - public partial class StageInfo : ReadOnlyBase, IDisposable - { - public event StageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(StageInfo stageInfo) - { - if (!_CacheList.Contains(stageInfo)) _CacheList.Add(stageInfo); // In AddToCache - } - protected static void RemoveFromCache(StageInfo stageInfo) - { - while (_CacheList.Contains(stageInfo)) _CacheList.Remove(stageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move StageInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - StageInfo tmp = _CacheList[0]; // Get the first StageInfo - string pKey = tmp.StageID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first StageInfo - } - } - internal static void AddList(StageInfoList lst) - { - foreach (StageInfo item in lst) AddToCache(item); - } - protected static StageInfo GetCachedByPrimaryKey(int stageID) - { - ConvertListToDictionary(); - string key = stageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Stage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _StageID; - [System.ComponentModel.DataObjectField(true, true)] - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - return _StageID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Description = string.Empty; - public string Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Description", true); - return _Description; - } - } - private int _IsApproved; - public int IsApproved - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("IsApproved", true); - return _IsApproved; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _StageCheckCount = 0; - /// - /// Count of StageChecks for this Stage - /// - public int StageCheckCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageCheckCount", true); - if (_StageCheckCount < 0) - _StageCheckCount = StageChecks.Count; - return _StageCheckCount; - } - } - private CheckInfoList _StageChecks = null; - [TypeConverter(typeof(CheckInfoListConverter))] - public CheckInfoList StageChecks - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageChecks", true); - if (_StageCheckCount < 0 || (_StageCheckCount > 0 && _StageChecks == null)) - _StageChecks = CheckInfoList.GetByStageID(_StageID); - if (_StageCheckCount < 0) - _StageCheckCount = _StageChecks.Count; - return _StageChecks; - } - } - public void RefreshStageChecks() - { - _StageCheckCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_StageID.ToString())) - foreach (StageInfo tmp in _CacheByPrimaryKey[_StageID.ToString()]) - tmp._StageCheckCount = -1; // This will cause the data to be requeried - } - private int _StageVersionCount = 0; - /// - /// Count of StageVersions for this Stage - /// - public int StageVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageVersionCount", true); - if (_StageVersionCount < 0) - _StageVersionCount = StageVersions.Count; - return _StageVersionCount; - } - } - private VersionInfoList _StageVersions = null; - [TypeConverter(typeof(VersionInfoListConverter))] - public VersionInfoList StageVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageVersions", true); - if (_StageVersionCount < 0 || (_StageVersionCount > 0 && _StageVersions == null)) - _StageVersions = VersionInfoList.GetByStageID(_StageID); - if (_StageVersionCount < 0) - _StageVersionCount = _StageVersions.Count; - return _StageVersions; - } - } - public void RefreshStageVersions() - { - _StageVersionCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_StageID.ToString())) - foreach (StageInfo tmp in _CacheByPrimaryKey[_StageID.ToString()]) - tmp._StageVersionCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base StageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current StageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check StageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current StageInfo - protected override object GetIdValue() - { - return MyStageInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _StageInfoUnique = 0; - private static int StageInfoUnique - { get { return ++_StageInfoUnique; } } - private int _MyStageInfoUnique = StageInfoUnique; - public int MyStageInfoUnique // Absolutely Unique ID - Info - { get { return _MyStageInfoUnique; } } - protected StageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~StageInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(StageID.ToString())) return; - List listStageInfo = _CacheByPrimaryKey[StageID.ToString()]; // Get the list of items - while (listStageInfo.Contains(this)) listStageInfo.Remove(this); // Remove the item from the list - if (listStageInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(StageID.ToString()); // remove the list - } - public virtual Stage Get() - { - return _Editable = Stage.GetJustStage(_StageID); - } - public static void Refresh(Stage tmp) - { - string key = tmp.StageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (StageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Stage tmp) - { - _Name = tmp.Name; - _Description = tmp.Description; - _IsApproved = tmp.IsApproved; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _StageInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static StageInfo Get(int stageID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Stage"); - try - { - StageInfo tmp = GetCachedByPrimaryKey(stageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(stageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up StageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on StageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal StageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.Constructor", ex); - throw new DbCslaException("StageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _StageID; - public int StageID - { get { return _StageID; } } - public PKCriteria(int stageID) - { - _StageID = stageID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.ReadData", GetHashCode()); - try - { - _StageID = dr.GetInt32("StageID"); - _Name = dr.GetString("Name"); - _Description = dr.GetString("Description"); - _IsApproved = dr.GetInt32("IsApproved"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _StageCheckCount = dr.GetInt32("CheckCount"); - _StageVersionCount = dr.GetInt32("VersionCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("StageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getStage"; - cm.Parameters.AddWithValue("@StageID", criteria.StageID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); + public delegate void StageInfoEvent(object sender); + /// + /// StageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageInfoConverter))] + public partial class StageInfo : ReadOnlyBase, IDisposable + { + public event StageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(StageInfo stageInfo) + { + if (!_CacheList.Contains(stageInfo)) _CacheList.Add(stageInfo); // In AddToCache + } + protected static void RemoveFromCache(StageInfo stageInfo) + { + while (_CacheList.Contains(stageInfo)) _CacheList.Remove(stageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move StageInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + StageInfo tmp = _CacheList[0]; // Get the first StageInfo + string pKey = tmp.StageID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first StageInfo + } + } + internal static void AddList(StageInfoList lst) + { + foreach (StageInfo item in lst) AddToCache(item); + } + protected static StageInfo GetCachedByPrimaryKey(int stageID) + { + ConvertListToDictionary(); + string key = stageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Stage _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _StageID; + [System.ComponentModel.DataObjectField(true, true)] + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StageID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Description; + } + } + private int _IsApproved; + public int IsApproved + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _IsApproved; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _StageCheckCount = 0; + /// + /// Count of StageChecks for this Stage + /// + public int StageCheckCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_StageCheckCount < 0) + _StageCheckCount = StageChecks.Count; + return _StageCheckCount; + } + } + private CheckInfoList _StageChecks = null; + [TypeConverter(typeof(CheckInfoListConverter))] + public CheckInfoList StageChecks + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_StageCheckCount < 0 || (_StageCheckCount > 0 && _StageChecks == null)) + _StageChecks = CheckInfoList.GetByStageID(_StageID); + if (_StageCheckCount < 0) + _StageCheckCount = _StageChecks.Count; + return _StageChecks; + } + } + public void RefreshStageChecks() + { + _StageCheckCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_StageID.ToString())) + foreach (StageInfo tmp in _CacheByPrimaryKey[_StageID.ToString()]) + tmp._StageCheckCount = -1; // This will cause the data to be requeried + } + private int _StageVersionCount = 0; + /// + /// Count of StageVersions for this Stage + /// + public int StageVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_StageVersionCount < 0) + _StageVersionCount = StageVersions.Count; + return _StageVersionCount; + } + } + private VersionInfoList _StageVersions = null; + [TypeConverter(typeof(VersionInfoListConverter))] + public VersionInfoList StageVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_StageVersionCount < 0 || (_StageVersionCount > 0 && _StageVersions == null)) + _StageVersions = VersionInfoList.GetByStageID(_StageID); + if (_StageVersionCount < 0) + _StageVersionCount = _StageVersions.Count; + return _StageVersions; + } + } + public void RefreshStageVersions() + { + _StageVersionCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_StageID.ToString())) + foreach (StageInfo tmp in _CacheByPrimaryKey[_StageID.ToString()]) + tmp._StageVersionCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base StageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current StageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check StageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current StageInfo + protected override object GetIdValue() + { + return MyStageInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _StageInfoUnique = 0; + private static int StageInfoUnique + { get { return ++_StageInfoUnique; } } + private int _MyStageInfoUnique = StageInfoUnique; + public int MyStageInfoUnique // Absolutely Unique ID - Info + { get { return _MyStageInfoUnique; } } + protected StageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~StageInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(StageID.ToString())) return; + List listStageInfo = _CacheByPrimaryKey[StageID.ToString()]; // Get the list of items + while (listStageInfo.Contains(this)) listStageInfo.Remove(this); // Remove the item from the list + if (listStageInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(StageID.ToString()); // remove the list + } + public virtual Stage Get() + { + return _Editable = Stage.GetJustStage(_StageID); + } + public static void Refresh(Stage tmp) + { + string key = tmp.StageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (StageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Stage tmp) + { + _Name = tmp.Name; + _Description = tmp.Description; + _IsApproved = tmp.IsApproved; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _StageInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static StageInfo Get(int stageID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Stage"); + try + { + StageInfo tmp = GetCachedByPrimaryKey(stageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(stageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up StageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on StageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal StageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.Constructor", ex); + throw new DbCslaException("StageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _StageID; + public int StageID + { get { return _StageID; } } + public PKCriteria(int stageID) + { + _StageID = stageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.ReadData", GetHashCode()); + try + { + _StageID = dr.GetInt32("StageID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _IsApproved = dr.GetInt32("IsApproved"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _StageCheckCount = dr.GetInt32("CheckCount"); + _StageVersionCount = dr.GetInt32("VersionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("StageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getStage"; + cm.Parameters.AddWithValue("@StageID", criteria.StageID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("StageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - StageInfoExtension _StageInfoExtension = new StageInfoExtension(); - [Serializable()] - partial class StageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(StageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class StageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is StageInfo) - { - // Return the ToString value - return ((StageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("StageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + StageInfoExtension _StageInfoExtension = new StageInfoExtension(); + [Serializable()] + partial class StageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(StageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class StageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageInfo) + { + // Return the ToString value + return ((StageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs b/PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs index 0c797500..aa5e9bf0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/StageVersion.cs @@ -20,580 +20,557 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// StageVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(StageVersionConverter))] - public partial class StageVersion : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyVersion != null) _VersionID = _MyVersion.VersionID; - return _VersionID; - } - } - private Version _MyVersion; - [System.ComponentModel.DataObjectField(true, true)] - public Version MyVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyVersion", true); - if (_MyVersion == null && _VersionID != 0) _MyVersion = Version.Get(_VersionID); - return _MyVersion; - } - } - private int _RevisionID; - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; - return _RevisionID; - } - } - private Revision _MyRevision; - public Revision MyRevision - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRevision", true); - if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); - return _MyRevision; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRevision", true); - if (_MyRevision != value) - { - _MyRevision = value; - _RevisionID = value.RevisionID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private byte[] _PDF; - public byte[] PDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PDF", true); - return _PDF; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PDF", true); - if (_PDF != value) - { - _PDF = value; - PropertyHasChanged(); - } - } - } - private byte[] _SummaryPDF; - public byte[] SummaryPDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SummaryPDF", true); - return _SummaryPDF; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SummaryPDF", true); - if (_SummaryPDF != value) - { - _SummaryPDF = value; - PropertyHasChanged(); - } - } - } - private string _ApprovedXML; - public string ApprovedXML - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ApprovedXML", true); - return _ApprovedXML; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ApprovedXML", true); - if (_ApprovedXML != value) - { - _ApprovedXML = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Revision_ItemID; - public int Revision_ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_ItemID", true); - return _Revision_ItemID; - } - } - private int _Revision_TypeID; - public int Revision_TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_TypeID", true); - return _Revision_TypeID; - } - } - private string _Revision_RevisionNumber = string.Empty; - public string Revision_RevisionNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_RevisionNumber", true); - return _Revision_RevisionNumber; - } - } - private DateTime? _Revision_RevisionDate; - public DateTime? Revision_RevisionDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_RevisionDate", true); - return _Revision_RevisionDate; - } - } - private string _Revision_Notes = string.Empty; - public string Revision_Notes - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_Notes", true); - return _Revision_Notes; - } - } - private string _Revision_Config = string.Empty; - public string Revision_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_Config", true); - return _Revision_Config; - } - } - private DateTime _Revision_DTS = new DateTime(); - public DateTime Revision_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_DTS", true); - return _Revision_DTS; - } - } - private string _Revision_UserID = string.Empty; - public string Revision_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Revision_UserID", true); - return _Revision_UserID; - } - } - // CSLATODO: Check StageVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current StageVersion - protected override object GetIdValue() - { - return MyStageVersionUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base StageVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current StageVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - // CSLATODO: Add other validation rules - } - private static bool MyRevisionRequired(StageVersion target, Csla.Validation.RuleArgs e) - { - if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(RevisionID, ""); - //AuthorizationRules.AllowWrite(RevisionID, ""); - //AuthorizationRules.AllowRead(PDF, ""); - //AuthorizationRules.AllowWrite(PDF, ""); - //AuthorizationRules.AllowRead(SummaryPDF, ""); - //AuthorizationRules.AllowWrite(SummaryPDF, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - 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; } } - private static int _StageVersionUnique = 0; - private static int StageVersionUnique - { get { return ++_StageVersionUnique; } } - private int _MyStageVersionUnique = StageVersionUnique; - public int MyStageVersionUnique // Absolutely Unique ID - Editable FK - { get { return _MyStageVersionUnique; } } - internal static StageVersion New(Revision myRevision, DateTime dts, string userID) - { - return new StageVersion(myRevision, dts, userID); - } - internal static StageVersion Get(SafeDataReader dr) - { - return new StageVersion(dr); - } - public StageVersion() - { - MarkAsChild(); - _VersionID = Version.NextVersionID; + /// + /// StageVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(StageVersionConverter))] + public partial class StageVersion : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyVersion != null) _VersionID = _MyVersion.VersionID; + return _VersionID; + } + } + private Version _MyVersion; + [System.ComponentModel.DataObjectField(true, true)] + public Version MyVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyVersion == null && _VersionID != 0) _MyVersion = Version.Get(_VersionID); + return _MyVersion; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PDF != value) + { + _PDF = value; + PropertyHasChanged(); + } + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SummaryPDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_SummaryPDF != value) + { + _SummaryPDF = value; + PropertyHasChanged(); + } + } + } + private string _ApprovedXML; + public string ApprovedXML + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ApprovedXML; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ApprovedXML != value) + { + _ApprovedXML = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Revision_ItemID; + public int Revision_ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_ItemID; + } + } + private int _Revision_TypeID; + public int Revision_TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_TypeID; + } + } + private string _Revision_RevisionNumber = string.Empty; + public string Revision_RevisionNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_RevisionNumber; + } + } + private DateTime? _Revision_RevisionDate; + public DateTime? Revision_RevisionDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_RevisionDate; + } + } + private string _Revision_Notes = string.Empty; + public string Revision_Notes + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_Notes; + } + } + private string _Revision_Config = string.Empty; + public string Revision_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_Config; + } + } + private DateTime _Revision_DTS = new DateTime(); + public DateTime Revision_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_DTS; + } + } + private string _Revision_UserID = string.Empty; + public string Revision_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Revision_UserID; + } + } + // CSLATODO: Check StageVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current StageVersion + protected override object GetIdValue() + { + return MyStageVersionUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base StageVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current StageVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(StageVersion target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowRead(PDF, ""); + //AuthorizationRules.AllowWrite(PDF, ""); + //AuthorizationRules.AllowRead(SummaryPDF, ""); + //AuthorizationRules.AllowWrite(SummaryPDF, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + 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; } } + private static int _StageVersionUnique = 0; + private static int StageVersionUnique + { get { return ++_StageVersionUnique; } } + private int _MyStageVersionUnique = StageVersionUnique; + public int MyStageVersionUnique // Absolutely Unique ID - Editable FK + { get { return _MyStageVersionUnique; } } + internal static StageVersion New(Revision myRevision, DateTime dts, string userID) + { + return new StageVersion(myRevision, dts, userID); + } + internal static StageVersion Get(SafeDataReader dr) + { + return new StageVersion(dr); + } + public StageVersion() + { + MarkAsChild(); + _VersionID = Version.NextVersionID; - ValidationRules.CheckRules(); - } - private StageVersion(Revision myRevision, DateTime dts, string userID) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _VersionID = Version.NextVersionID; + ValidationRules.CheckRules(); + } + private StageVersion(Revision myRevision, DateTime dts, string userID) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _VersionID = Version.NextVersionID; - _MyRevision = myRevision; - _DTS = dts; - _UserID = userID; - ValidationRules.CheckRules(); - } - internal StageVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~StageVersion() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _RevisionID = dr.GetInt32("RevisionID"); - _PDF = (byte[])dr.GetValue("PDF"); - _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Revision_ItemID = dr.GetInt32("Revision_ItemID"); - _Revision_TypeID = dr.GetInt32("Revision_TypeID"); - _Revision_RevisionNumber = dr.GetString("Revision_RevisionNumber"); - if (!dr.IsDBNull(dr.GetOrdinal("Revision_RevisionDate"))) _Revision_RevisionDate = dr.GetDateTime("Revision_RevisionDate"); - _Revision_Notes = dr.GetString("Revision_Notes"); - _Revision_Config = dr.GetString("Revision_Config"); - _Revision_DTS = dr.GetDateTime("Revision_DTS"); - _Revision_UserID = dr.GetString("Revision_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("StageVersion.FetchDR", ex); - throw new DbCslaException("StageVersion.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Stage myStage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Version.Add(cn, ref _VersionID, _MyRevision, myStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); - MarkOld(); - } - internal void Update(Stage myStage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Version.Update(cn, ref _VersionID, _RevisionID, myStage.StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Stage myStage) - { - // 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"]; - Version.Remove(cn, _VersionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - StageVersionExtension _StageVersionExtension = new StageVersionExtension(); - [Serializable()] - partial class StageVersionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class StageVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is StageVersion) - { - // Return the ToString value - return ((StageVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _MyRevision = myRevision; + _DTS = dts; + _UserID = userID; + ValidationRules.CheckRules(); + } + internal StageVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~StageVersion() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] StageVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _RevisionID = dr.GetInt32("RevisionID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Revision_ItemID = dr.GetInt32("Revision_ItemID"); + _Revision_TypeID = dr.GetInt32("Revision_TypeID"); + _Revision_RevisionNumber = dr.GetString("Revision_RevisionNumber"); + if (!dr.IsDBNull(dr.GetOrdinal("Revision_RevisionDate"))) _Revision_RevisionDate = dr.GetDateTime("Revision_RevisionDate"); + _Revision_Notes = dr.GetString("Revision_Notes"); + _Revision_Config = dr.GetString("Revision_Config"); + _Revision_DTS = dr.GetDateTime("Revision_DTS"); + _Revision_UserID = dr.GetString("Revision_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("StageVersion.FetchDR", ex); + throw new DbCslaException("StageVersion.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Add(cn, ref _VersionID, _MyRevision, myStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); + MarkOld(); + } + internal void Update(Stage myStage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Version.Update(cn, ref _VersionID, _RevisionID, myStage.StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Stage myStage) + { + // 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"]; + Version.Remove(cn, _VersionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + StageVersionExtension _StageVersionExtension = new StageVersionExtension(); + [Serializable()] + partial class StageVersionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class StageVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is StageVersion) + { + // Return the ToString value + return ((StageVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs index 2a250ad2..45464f93 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Transition.cs @@ -20,1249 +20,1227 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Transition Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(TransitionConverter))] - public partial class Transition : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshTransitions = new List(); - private void AddToRefreshList(List refreshTransitions) - { - if (IsDirty) - refreshTransitions.Add(this); - } - private void ClearRefreshList() - { - _RefreshTransitions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshTransitions); - } - private void ProcessRefreshList() - { - foreach (Transition tmp in _RefreshTransitions) - { - TransitionInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - if (tmp._MyItemRangeID != null) ItemInfo.Refresh(tmp._MyItemRangeID); - if (tmp._MyItemToID != null) ItemInfo.Refresh(tmp._MyItemToID); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Transition transition) - { - if (!_CacheList.Contains(transition)) _CacheList.Add(transition); // In AddToCache - } - protected static void RemoveFromCache(Transition transition) - { - while (_CacheList.Contains(transition)) _CacheList.Remove(transition); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Transition(s) from temporary _CacheList to _CacheByPrimaryKey - { - Transition tmp = _CacheList[0]; // Get the first Transition - string pKey = tmp.TransitionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Transition - } - } - protected static Transition GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextTransitionID = -1; - public static int NextTransitionID - { - get { return _nextTransitionID--; } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - return _TransitionID; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - _FromID = value.ContentID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private Item _MyItemToID; - public Item MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); - return _MyItemToID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemToID", true); - if (_MyItemToID != value) - { - _MyItemToID = value; - _ToID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private Item _MyItemRangeID; - public Item MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); - return _MyItemRangeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemRangeID", true); - if (_MyItemRangeID != value) - { - _MyItemRangeID = value; - _RangeID = value.ItemID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _IsRange; - /// - /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling - /// - public int IsRange - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("IsRange", true); - return _IsRange; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("IsRange", true); - if (_IsRange != value) - { - _IsRange = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _TransitionZTransitionCount = 0; - /// - /// Count of TransitionZTransitions for this Transition - /// - public int TransitionZTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionZTransitionCount", true); - return _TransitionZTransitionCount; - } - } - private ZTransition _MyZTransition = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ZTransitionConverter))] - public ZTransition MyZTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZTransition", true); - if (_MyZTransition == null) _MyZTransition = ZTransition.New(this); - return _MyZTransition; - } - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyZTransition == null ? false : _MyZTransition.IsDirtyList(list)) || (_MyContent == null ? false : _MyContent.IsDirtyList(list)) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirtyList(list)) || (_MyItemToID == null ? false : _MyItemToID.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyZTransition == null ? true : _MyZTransition.IsValidList(list)) && (_MyContent == null ? true : _MyContent.IsValidList(list)) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValidList(list)) && (_MyItemToID == null ? true : _MyItemToID.IsValidList(list)); - } - // CSLATODO: Replace base Transition.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Transition - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Transition.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Transition - protected override object GetIdValue() - { - return MyTransitionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyZTransition != null && (hasBrokenRules = _MyZTransition.HasBrokenRules) != null) return hasBrokenRules; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); - ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _TransitionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _TransitionExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyContentRequired(Transition target, Csla.Validation.RuleArgs e) - { - if (target._FromID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyItemToIDRequired(Transition target, Csla.Validation.RuleArgs e) - { - if (target._ToID == 0 && target._MyItemToID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyItemRangeIDRequired(Transition target, Csla.Validation.RuleArgs e) - { - if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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(TransitionID, ""); - //AuthorizationRules.AllowRead(FromID, ""); - //AuthorizationRules.AllowRead(ToID, ""); - //AuthorizationRules.AllowRead(RangeID, ""); - //AuthorizationRules.AllowRead(IsRange, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(FromID, ""); - //AuthorizationRules.AllowWrite(ToID, ""); - //AuthorizationRules.AllowWrite(RangeID, ""); - //AuthorizationRules.AllowWrite(IsRange, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _TransitionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _TransitionExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _TransitionZTransitionCount; - 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; } } - private static int _TransitionUnique = 0; - protected static int TransitionUnique - { get { return ++_TransitionUnique; } } - private int _MyTransitionUnique = TransitionUnique; - public int MyTransitionUnique // Absolutely Unique ID - Editable - { get { return _MyTransitionUnique; } } - protected Transition() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Transition() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - if (_MyZTransition != null) - { - _MyZTransition.Dispose(); - _MyZTransition = null; - } - if (_MyContent != null) - _MyContent = null; - //if (_MyItemRangeID!=null) - // _MyItemRangeID = null; - //if (_MyItemToID != null) - // _MyItemToID = null; - //if (_MyItemRangeID != null) - // _MyItemRangeID = null; - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) - { - List listTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listTransition.Contains(this)) listTransition.Remove(this); // Remove the item from the list - if (listTransition.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - } - public static Transition New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Transition"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.New", ex); - } - } - public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID) - { - Transition tmp = Transition.New(); - tmp.MyContent = myContent; - tmp.MyItemToID = myItemToID; - tmp.MyItemRangeID = myItemRangeID; - return tmp; - } - public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, int isRange, int tranType, string config, DateTime dts, string userID) - { - Transition tmp = Transition.New(); - tmp.MyContent = myContent; - tmp.MyItemToID = myItemToID; - tmp.MyItemRangeID = myItemRangeID; - tmp.IsRange = isRange; - tmp.TranType = tranType; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, int isRange, int tranType, string config, DateTime dts, string userID) - { - Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, isRange, tranType, config, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, string config) - { - Transition tmp = Transition.New(); - tmp.MyContent = myContent; - tmp.MyItemToID = myItemToID; - tmp.MyItemRangeID = myItemRangeID; - tmp.Config = config; - return tmp; - } - public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, string config) - { - Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Transition Get(int transitionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Transition"); - try - { - Transition tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Transition - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.Get", ex); - } - } - public static Transition Get(SafeDataReader dr) - { - if (dr.Read()) return new Transition(dr); - return null; - } - internal Transition(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int transitionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Transition"); - try - { - DataPortal.Delete(new PKCriteria(transitionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.Delete", ex); - } - } - public override Transition Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Transition"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Transition"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Transition"); - try - { - BuildRefreshList(); - Transition transition = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(transition);//Refresh the item in AllList - ProcessRefreshList(); - return transition; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _TransitionID = NextTransitionID; - // Database Defaults - _IsRange = _TransitionExtension.DefaultIsRange; - _TranType = _TransitionExtension.DefaultTranType; - _DTS = _TransitionExtension.DefaultDTS; - _UserID = _TransitionExtension.DefaultUserID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _ToID = dr.GetInt32("ToID"); - _RangeID = dr.GetInt32("RangeID"); - _IsRange = dr.GetInt32("IsRange"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _MyZTransition = ZTransition.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItemRangeID != null) _MyItemRangeID.Update(); - if (_MyItemToID != null) _MyItemToID.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FromID", FromID); - cm.Parameters.AddWithValue("@ToID", ToID); - cm.Parameters.AddWithValue("@RangeID", RangeID); - cm.Parameters.AddWithValue("@IsRange", _IsRange); - cm.Parameters.AddWithValue("@TranType", _TranType); - 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); - param_TransitionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_TransitionID); - 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 - _TransitionID = (int)cm.Parameters["@newTransitionID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyZTransition != null) _MyZTransition.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int transitionID, Content myContent, Item myItemToID, Item myItemRangeID, int isRange, int tranType, string config, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FromID", myContent.ContentID); - cm.Parameters.AddWithValue("@ToID", myItemToID.ItemID); - cm.Parameters.AddWithValue("@RangeID", myItemRangeID.ItemID); - cm.Parameters.AddWithValue("@IsRange", isRange); - cm.Parameters.AddWithValue("@TranType", tranType); - 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); - param_TransitionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_TransitionID); - 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 - transitionID = (int)cm.Parameters["@newTransitionID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Add", ex); - throw new DbCslaException("Transition.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Transition.SQLUpdate", GetHashCode()); - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItemRangeID != null) _MyItemRangeID.Update(); - if (_MyItemToID != null) _MyItemToID.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateTransition"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@TransitionID", _TransitionID); - cm.Parameters.AddWithValue("@FromID", FromID); - cm.Parameters.AddWithValue("@ToID", ToID); - cm.Parameters.AddWithValue("@RangeID", RangeID); - cm.Parameters.AddWithValue("@IsRange", _IsRange); - cm.Parameters.AddWithValue("@TranType", _TranType); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_MyZTransition != null) _MyZTransition.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); - else - _LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, _ToID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_MyZTransition != null) _MyZTransition.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int transitionID, int fromID, int toID, int rangeID, int isRange, int tranType, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", transitionID); - cm.Parameters.AddWithValue("@FromID", fromID); - cm.Parameters.AddWithValue("@ToID", toID); - cm.Parameters.AddWithValue("@RangeID", rangeID); - cm.Parameters.AddWithValue("@IsRange", isRange); - cm.Parameters.AddWithValue("@TranType", tranType); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Update", ex); - throw new DbCslaException("Transition.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_TransitionID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int transitionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteTransition"; - // Input PK Fields - cm.Parameters.AddWithValue("@TransitionID", transitionID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Remove", ex); - throw new DbCslaException("Transition.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int transitionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(transitionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _TransitionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int transitionID) - { - _TransitionID = transitionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsTransition"; - cm.Parameters.AddWithValue("@TransitionID", _TransitionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Execute", ex); - throw new DbCslaException("Transition.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - TransitionExtension _TransitionExtension = new TransitionExtension(); - [Serializable()] - partial class TransitionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultIsRange - { - get { return 0; } - } - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class TransitionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Transition) - { - // Return the ToString value - return ((Transition)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Transition Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(TransitionConverter))] + public partial class Transition : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshTransitions = new List(); + private void AddToRefreshList(List refreshTransitions) + { + if (IsDirty) + refreshTransitions.Add(this); + } + private void ClearRefreshList() + { + _RefreshTransitions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshTransitions); + } + private void ProcessRefreshList() + { + foreach (Transition tmp in _RefreshTransitions) + { + TransitionInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + if (tmp._MyItemRangeID != null) ItemInfo.Refresh(tmp._MyItemRangeID); + if (tmp._MyItemToID != null) ItemInfo.Refresh(tmp._MyItemToID); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Transition transition) + { + if (!_CacheList.Contains(transition)) _CacheList.Add(transition); // In AddToCache + } + protected static void RemoveFromCache(Transition transition) + { + while (_CacheList.Contains(transition)) _CacheList.Remove(transition); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Transition(s) from temporary _CacheList to _CacheByPrimaryKey + { + Transition tmp = _CacheList[0]; // Get the first Transition + string pKey = tmp.TransitionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Transition + } + } + protected static Transition GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextTransitionID = -1; + public static int NextTransitionID + { + get { return _nextTransitionID--; } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionID; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + _FromID = value.ContentID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private Item _MyItemToID; + public Item MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); + return _MyItemToID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemToID != value) + { + _MyItemToID = value; + _ToID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private Item _MyItemRangeID; + public Item MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); + return _MyItemRangeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemRangeID != value) + { + _MyItemRangeID = value; + _RangeID = value.ItemID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _IsRange; + /// + /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling + /// + public int IsRange + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _IsRange; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_IsRange != value) + { + _IsRange = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _TransitionZTransitionCount = 0; + /// + /// Count of TransitionZTransitions for this Transition + /// + public int TransitionZTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionZTransitionCount; + } + } + private ZTransition _MyZTransition = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ZTransitionConverter))] + public ZTransition MyZTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyZTransition == null) _MyZTransition = ZTransition.New(this); + return _MyZTransition; + } + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyZTransition == null ? false : _MyZTransition.IsDirtyList(list)) || (_MyContent == null ? false : _MyContent.IsDirtyList(list)) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirtyList(list)) || (_MyItemToID == null ? false : _MyItemToID.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyZTransition == null ? true : _MyZTransition.IsValidList(list)) && (_MyContent == null ? true : _MyContent.IsValidList(list)) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValidList(list)) && (_MyItemToID == null ? true : _MyItemToID.IsValidList(list)); + } + // CSLATODO: Replace base Transition.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Transition + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Transition.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Transition + protected override object GetIdValue() + { + return MyTransitionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyZTransition != null && (hasBrokenRules = _MyZTransition.HasBrokenRules) != null) return hasBrokenRules; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); + ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _TransitionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _TransitionExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyContentRequired(Transition target, Csla.Validation.RuleArgs e) + { + if (target._FromID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyItemToIDRequired(Transition target, Csla.Validation.RuleArgs e) + { + if (target._ToID == 0 && target._MyItemToID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyItemRangeIDRequired(Transition target, Csla.Validation.RuleArgs e) + { + if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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(TransitionID, ""); + //AuthorizationRules.AllowRead(FromID, ""); + //AuthorizationRules.AllowRead(ToID, ""); + //AuthorizationRules.AllowRead(RangeID, ""); + //AuthorizationRules.AllowRead(IsRange, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(FromID, ""); + //AuthorizationRules.AllowWrite(ToID, ""); + //AuthorizationRules.AllowWrite(RangeID, ""); + //AuthorizationRules.AllowWrite(IsRange, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _TransitionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _TransitionExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _TransitionZTransitionCount; + 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; } } + private static int _TransitionUnique = 0; + protected static int TransitionUnique + { get { return ++_TransitionUnique; } } + private int _MyTransitionUnique = TransitionUnique; + public int MyTransitionUnique // Absolutely Unique ID - Editable + { get { return _MyTransitionUnique; } } + protected Transition() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Transition() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + if (_MyZTransition != null) + { + _MyZTransition.Dispose(); + _MyZTransition = null; + } + if (_MyContent != null) + _MyContent = null; + //if (_MyItemRangeID!=null) + // _MyItemRangeID = null; + //if (_MyItemToID != null) + // _MyItemToID = null; + //if (_MyItemRangeID != null) + // _MyItemRangeID = null; + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) + { + List listTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listTransition.Contains(this)) listTransition.Remove(this); // Remove the item from the list + if (listTransition.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + } + public static Transition New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Transition"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.New", ex); + } + } + public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID) + { + Transition tmp = Transition.New(); + tmp.MyContent = myContent; + tmp.MyItemToID = myItemToID; + tmp.MyItemRangeID = myItemRangeID; + return tmp; + } + public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, int isRange, int tranType, string config, DateTime dts, string userID) + { + Transition tmp = Transition.New(); + tmp.MyContent = myContent; + tmp.MyItemToID = myItemToID; + tmp.MyItemRangeID = myItemRangeID; + tmp.IsRange = isRange; + tmp.TranType = tranType; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, int isRange, int tranType, string config, DateTime dts, string userID) + { + Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, isRange, tranType, config, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, string config) + { + Transition tmp = Transition.New(); + tmp.MyContent = myContent; + tmp.MyItemToID = myItemToID; + tmp.MyItemRangeID = myItemRangeID; + tmp.Config = config; + return tmp; + } + public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, string config) + { + Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Transition Get(int transitionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Transition"); + try + { + Transition tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Transition + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.Get", ex); + } + } + public static Transition Get(SafeDataReader dr) + { + if (dr.Read()) return new Transition(dr); + return null; + } + internal Transition(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int transitionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Transition"); + try + { + DataPortal.Delete(new PKCriteria(transitionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.Delete", ex); + } + } + public override Transition Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Transition"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Transition"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Transition"); + try + { + BuildRefreshList(); + Transition transition = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(transition);//Refresh the item in AllList + ProcessRefreshList(); + return transition; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _TransitionID = NextTransitionID; + // Database Defaults + _IsRange = _TransitionExtension.DefaultIsRange; + _TranType = _TransitionExtension.DefaultTranType; + _DTS = _TransitionExtension.DefaultDTS; + _UserID = _TransitionExtension.DefaultUserID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _ToID = dr.GetInt32("ToID"); + _RangeID = dr.GetInt32("RangeID"); + _IsRange = dr.GetInt32("IsRange"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _MyZTransition = ZTransition.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItemRangeID != null) _MyItemRangeID.Update(); + if (_MyItemToID != null) _MyItemToID.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FromID", FromID); + cm.Parameters.AddWithValue("@ToID", ToID); + cm.Parameters.AddWithValue("@RangeID", RangeID); + cm.Parameters.AddWithValue("@IsRange", _IsRange); + cm.Parameters.AddWithValue("@TranType", _TranType); + 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); + param_TransitionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_TransitionID); + 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 + _TransitionID = (int)cm.Parameters["@newTransitionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyZTransition != null) _MyZTransition.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int transitionID, Content myContent, Item myItemToID, Item myItemRangeID, int isRange, int tranType, string config, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FromID", myContent.ContentID); + cm.Parameters.AddWithValue("@ToID", myItemToID.ItemID); + cm.Parameters.AddWithValue("@RangeID", myItemRangeID.ItemID); + cm.Parameters.AddWithValue("@IsRange", isRange); + cm.Parameters.AddWithValue("@TranType", tranType); + 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); + param_TransitionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_TransitionID); + 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 + transitionID = (int)cm.Parameters["@newTransitionID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Add", ex); + throw new DbCslaException("Transition.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Transition.SQLUpdate", GetHashCode()); + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItemRangeID != null) _MyItemRangeID.Update(); + if (_MyItemToID != null) _MyItemToID.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateTransition"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@TransitionID", _TransitionID); + cm.Parameters.AddWithValue("@FromID", FromID); + cm.Parameters.AddWithValue("@ToID", ToID); + cm.Parameters.AddWithValue("@RangeID", RangeID); + cm.Parameters.AddWithValue("@IsRange", _IsRange); + cm.Parameters.AddWithValue("@TranType", _TranType); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_MyZTransition != null) _MyZTransition.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, _MyItemRangeID, _IsRange, _TranType, _Config, _DTS, _UserID); + else + _LastChanged = Transition.Update(cn, ref _TransitionID, _FromID, _ToID, _RangeID, _IsRange, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_MyZTransition != null) _MyZTransition.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int transitionID, int fromID, int toID, int rangeID, int isRange, int tranType, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", transitionID); + cm.Parameters.AddWithValue("@FromID", fromID); + cm.Parameters.AddWithValue("@ToID", toID); + cm.Parameters.AddWithValue("@RangeID", rangeID); + cm.Parameters.AddWithValue("@IsRange", isRange); + cm.Parameters.AddWithValue("@TranType", tranType); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Update", ex); + throw new DbCslaException("Transition.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_TransitionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int transitionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteTransition"; + // Input PK Fields + cm.Parameters.AddWithValue("@TransitionID", transitionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Remove", ex); + throw new DbCslaException("Transition.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int transitionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(transitionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _TransitionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int transitionID) + { + _TransitionID = transitionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsTransition"; + cm.Parameters.AddWithValue("@TransitionID", _TransitionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Execute", ex); + throw new DbCslaException("Transition.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + TransitionExtension _TransitionExtension = new TransitionExtension(); + [Serializable()] + partial class TransitionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultIsRange + { + get { return 0; } + } + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class TransitionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Transition) + { + // Return the ToString value + return ((Transition)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs index badea5fa..8988c6c1 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/TransitionInfo.cs @@ -19,575 +19,561 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void TransitionInfoEvent(object sender); - /// - /// TransitionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(TransitionInfoConverter))] - public partial class TransitionInfo : ReadOnlyBase, IDisposable - { - public event TransitionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(TransitionInfo transitionInfo) - { - if (!_CacheList.Contains(transitionInfo)) _CacheList.Add(transitionInfo); // In AddToCache - } - protected static void RemoveFromCache(TransitionInfo transitionInfo) - { - while (_CacheList.Contains(transitionInfo)) _CacheList.Remove(transitionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move TransitionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - TransitionInfo tmp = _CacheList[0]; // Get the first TransitionInfo - string pKey = tmp.TransitionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first TransitionInfo - } - } - internal static void AddList(TransitionInfoList lst) - { - foreach (TransitionInfo item in lst) AddToCache(item); - } - protected static TransitionInfo GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Transition _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - return _TransitionID; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = ContentInfo.Get(_FromID); - return _MyContent; - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private ItemInfo _MyItemToID; - public ItemInfo MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = ItemInfo.Get(_ToID); - return _MyItemToID; - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private ItemInfo _MyItemRangeID; - public ItemInfo MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = ItemInfo.Get(_RangeID); - return _MyItemRangeID; - } - } - private int _IsRange; - /// - /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling - /// - public int IsRange - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("IsRange", true); - return _IsRange; - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _TransitionZTransitionCount = 0; - /// - /// Count of TransitionZTransitions for this Transition - /// - public int TransitionZTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionZTransitionCount", true); - return _TransitionZTransitionCount; - } - } - private ZTransitionInfo _MyZTransition = null; - [TypeConverter(typeof(ZTransitionInfoConverter))] - public ZTransitionInfo MyZTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZTransition", true); - if (_TransitionZTransitionCount != 0 && _MyZTransition == null) - { - _MyZTransition = ZTransitionInfo.Get(_TransitionID); - _TransitionZTransitionCount = _MyZTransition == null ? 0 : 1; - } - return _MyZTransition; - } - } - // CSLATODO: Replace base TransitionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current TransitionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check TransitionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current TransitionInfo - protected override object GetIdValue() - { - return MyTransitionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _TransitionInfoUnique = 0; - private static int TransitionInfoUnique - { get { return ++_TransitionInfoUnique; } } - private int _MyTransitionInfoUnique = TransitionInfoUnique; - public int MyTransitionInfoUnique // Absolutely Unique ID - Info - { get { return _MyTransitionInfoUnique; } } - protected TransitionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~TransitionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; - List listTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listTransitionInfo.Contains(this)) listTransitionInfo.Remove(this); // Remove the item from the list - if (listTransitionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - public virtual Transition Get() - { - return _Editable = Transition.Get(_TransitionID); - } - public static void Refresh(Transition tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Transition tmp) - { - if (_FromID != tmp.FromID) - { - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value - _FromID = tmp.FromID; // Update the value - } - _MyContent = null; // Reset list so that the next line gets a new list - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value - if (_ToID != tmp.ToID) - { - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value - _ToID = tmp.ToID; // Update the value - } - _MyItemToID = null; // Reset list so that the next line gets a new list - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value - if (_RangeID != tmp.RangeID) - { - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value - _RangeID = tmp.RangeID; // Update the value - } - _MyItemRangeID = null; // Reset list so that the next line gets a new list - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value - _IsRange = tmp.IsRange; - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static void Refresh(ContentTransition tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentTransition tmp) - { - if (_ToID != tmp.ToID) - { - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value - _ToID = tmp.ToID; // Update the value - } - _MyItemToID = null; // Reset list so that the next line gets a new list - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value - if (_RangeID != tmp.RangeID) - { - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value - _RangeID = tmp.RangeID; // Update the value - } - _MyItemRangeID = null; // Reset list so that the next line gets a new list - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value - _IsRange = tmp.IsRange; - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static void Refresh(ItemTransition_RangeID tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemTransition_RangeID tmp) - { - if (_FromID != tmp.FromID) - { - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value - _FromID = tmp.FromID; // Update the value - } - _MyContent = null; // Reset list so that the next line gets a new list - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value - if (_ToID != tmp.ToID) - { - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value - _ToID = tmp.ToID; // Update the value - } - _MyItemToID = null; // Reset list so that the next line gets a new list - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value - _IsRange = tmp.IsRange; - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static void Refresh(ItemTransition_ToID tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemTransition_ToID tmp) - { - if (_FromID != tmp.FromID) - { - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value - _FromID = tmp.FromID; // Update the value - } - _MyContent = null; // Reset list so that the next line gets a new list - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value - if (_RangeID != tmp.RangeID) - { - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value - _RangeID = tmp.RangeID; // Update the value - } - _MyItemRangeID = null; // Reset list so that the next line gets a new list - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value - _IsRange = tmp.IsRange; - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static TransitionInfo Get(int transitionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Transition"); - try - { - TransitionInfo tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up TransitionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on TransitionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal TransitionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.Constructor", ex); - throw new DbCslaException("TransitionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _ToID = dr.GetInt32("ToID"); - _RangeID = dr.GetInt32("RangeID"); - _IsRange = dr.GetInt32("IsRange"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("TransitionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("TransitionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - TransitionInfoExtension _TransitionInfoExtension = new TransitionInfoExtension(); - [Serializable()] - partial class TransitionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(TransitionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class TransitionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is TransitionInfo) - { - // Return the ToString value - return ((TransitionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void TransitionInfoEvent(object sender); + /// + /// TransitionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(TransitionInfoConverter))] + public partial class TransitionInfo : ReadOnlyBase, IDisposable + { + public event TransitionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(TransitionInfo transitionInfo) + { + if (!_CacheList.Contains(transitionInfo)) _CacheList.Add(transitionInfo); // In AddToCache + } + protected static void RemoveFromCache(TransitionInfo transitionInfo) + { + while (_CacheList.Contains(transitionInfo)) _CacheList.Remove(transitionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move TransitionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + TransitionInfo tmp = _CacheList[0]; // Get the first TransitionInfo + string pKey = tmp.TransitionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first TransitionInfo + } + } + internal static void AddList(TransitionInfoList lst) + { + foreach (TransitionInfo item in lst) AddToCache(item); + } + protected static TransitionInfo GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Transition _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionID; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = ContentInfo.Get(_FromID); + return _MyContent; + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private ItemInfo _MyItemToID; + public ItemInfo MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = ItemInfo.Get(_ToID); + return _MyItemToID; + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private ItemInfo _MyItemRangeID; + public ItemInfo MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = ItemInfo.Get(_RangeID); + return _MyItemRangeID; + } + } + private int _IsRange; + /// + /// 0 - Not a Range Transition, 1 - Range Transition, 2 - Range Transition - Extends to last Sibling + /// + public int IsRange + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _IsRange; + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _TransitionZTransitionCount = 0; + /// + /// Count of TransitionZTransitions for this Transition + /// + public int TransitionZTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionZTransitionCount; + } + } + private ZTransitionInfo _MyZTransition = null; + [TypeConverter(typeof(ZTransitionInfoConverter))] + public ZTransitionInfo MyZTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_TransitionZTransitionCount != 0 && _MyZTransition == null) + { + _MyZTransition = ZTransitionInfo.Get(_TransitionID); + _TransitionZTransitionCount = _MyZTransition == null ? 0 : 1; + } + return _MyZTransition; + } + } + // CSLATODO: Replace base TransitionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current TransitionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check TransitionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current TransitionInfo + protected override object GetIdValue() + { + return MyTransitionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _TransitionInfoUnique = 0; + private static int TransitionInfoUnique + { get { return ++_TransitionInfoUnique; } } + private int _MyTransitionInfoUnique = TransitionInfoUnique; + public int MyTransitionInfoUnique // Absolutely Unique ID - Info + { get { return _MyTransitionInfoUnique; } } + protected TransitionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~TransitionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; + List listTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listTransitionInfo.Contains(this)) listTransitionInfo.Remove(this); // Remove the item from the list + if (listTransitionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + public virtual Transition Get() + { + return _Editable = Transition.Get(_TransitionID); + } + public static void Refresh(Transition tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Transition tmp) + { + if (_FromID != tmp.FromID) + { + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value + _FromID = tmp.FromID; // Update the value + } + _MyContent = null; // Reset list so that the next line gets a new list + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value + if (_ToID != tmp.ToID) + { + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value + _ToID = tmp.ToID; // Update the value + } + _MyItemToID = null; // Reset list so that the next line gets a new list + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value + if (_RangeID != tmp.RangeID) + { + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value + _RangeID = tmp.RangeID; // Update the value + } + _MyItemRangeID = null; // Reset list so that the next line gets a new list + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value + _IsRange = tmp.IsRange; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static void Refresh(ContentTransition tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentTransition tmp) + { + if (_ToID != tmp.ToID) + { + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value + _ToID = tmp.ToID; // Update the value + } + _MyItemToID = null; // Reset list so that the next line gets a new list + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value + if (_RangeID != tmp.RangeID) + { + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value + _RangeID = tmp.RangeID; // Update the value + } + _MyItemRangeID = null; // Reset list so that the next line gets a new list + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value + _IsRange = tmp.IsRange; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static void Refresh(ItemTransition_RangeID tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemTransition_RangeID tmp) + { + if (_FromID != tmp.FromID) + { + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value + _FromID = tmp.FromID; // Update the value + } + _MyContent = null; // Reset list so that the next line gets a new list + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value + if (_ToID != tmp.ToID) + { + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value + _ToID = tmp.ToID; // Update the value + } + _MyItemToID = null; // Reset list so that the next line gets a new list + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value + _IsRange = tmp.IsRange; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static void Refresh(ItemTransition_ToID tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemTransition_ToID tmp) + { + if (_FromID != tmp.FromID) + { + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value + _FromID = tmp.FromID; // Update the value + } + _MyContent = null; // Reset list so that the next line gets a new list + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value + if (_RangeID != tmp.RangeID) + { + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value + _RangeID = tmp.RangeID; // Update the value + } + _MyItemRangeID = null; // Reset list so that the next line gets a new list + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value + _IsRange = tmp.IsRange; + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static TransitionInfo Get(int transitionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Transition"); + try + { + TransitionInfo tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up TransitionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on TransitionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal TransitionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.Constructor", ex); + throw new DbCslaException("TransitionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _ToID = dr.GetInt32("ToID"); + _RangeID = dr.GetInt32("RangeID"); + _IsRange = dr.GetInt32("IsRange"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("TransitionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("TransitionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + TransitionInfoExtension _TransitionInfoExtension = new TransitionInfoExtension(); + [Serializable()] + partial class TransitionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(TransitionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class TransitionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is TransitionInfo) + { + // Return the ToString value + return ((TransitionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/User.cs b/PROMS/VEPROMS.CSLA.Library/Generated/User.cs index 25bbfb2c..5734aa8f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/User.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/User.cs @@ -20,1346 +20,1317 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// User Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(UserConverter))] - public partial class User : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshUsers = new List(); - private List _RefreshUserMemberships = new List(); - private void AddToRefreshList(List refreshUsers, List refreshUserMemberships) - { - if (IsDirty) - refreshUsers.Add(this); - if (_UserMemberships != null && _UserMemberships.IsDirty) - { - foreach (UserMembership tmp in _UserMemberships) - { - if (tmp.IsDirty) refreshUserMemberships.Add(tmp); - } - } - } - private void ClearRefreshList() - { - _RefreshUsers = new List(); - _RefreshUserMemberships = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshUsers, _RefreshUserMemberships); - } - private void ProcessRefreshList() - { - foreach (User tmp in _RefreshUsers) - { - UserInfo.Refresh(tmp); - } - foreach (UserMembership tmp in _RefreshUserMemberships) - { - MembershipInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(User user) - { - if (!_CacheList.Contains(user)) _CacheList.Add(user); // In AddToCache - } - protected static void RemoveFromCache(User user) - { - while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move User(s) from temporary _CacheList to _CacheByPrimaryKey - { - User tmp = _CacheList[0]; // Get the first User - string pKey = tmp.UID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first User - } - } - protected static User GetCachedByPrimaryKey(int uid) - { - ConvertListToDictionary(); - string key = uid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextUID = -1; - public static int NextUID - { - get { return _nextUID--; } - } - private int _UID; - [System.ComponentModel.DataObjectField(true, true)] - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - return _UID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private string _FirstName = string.Empty; - public string FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FirstName", true); - return _FirstName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FirstName", true); - if (value == null) value = string.Empty; - if (_FirstName != value) - { - _FirstName = value; - PropertyHasChanged(); - } - } - } - private string _MiddleName = string.Empty; - public string MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MiddleName", true); - return _MiddleName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MiddleName", true); - if (value == null) value = string.Empty; - if (_MiddleName != value) - { - _MiddleName = value; - PropertyHasChanged(); - } - } - } - private string _LastName = string.Empty; - public string LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LastName", true); - return _LastName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("LastName", true); - if (value == null) value = string.Empty; - if (_LastName != value) - { - _LastName = value; - PropertyHasChanged(); - } - } - } - private string _Suffix = string.Empty; - public string Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Suffix", true); - return _Suffix; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Suffix", true); - if (value == null) value = string.Empty; - if (_Suffix != value) - { - _Suffix = value; - PropertyHasChanged(); - } - } - } - private string _CourtesyTitle = string.Empty; - public string CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CourtesyTitle", true); - return _CourtesyTitle; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("CourtesyTitle", true); - if (value == null) value = string.Empty; - if (_CourtesyTitle != value) - { - _CourtesyTitle = value; - PropertyHasChanged(); - } - } - } - private string _PhoneNumber = string.Empty; - public string PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PhoneNumber", true); - return _PhoneNumber; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PhoneNumber", true); - if (value == null) value = string.Empty; - if (_PhoneNumber != value) - { - _PhoneNumber = value; - PropertyHasChanged(); - } - } - } - private string _CFGName = string.Empty; - public string CFGName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CFGName", true); - return _CFGName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("CFGName", true); - if (value == null) value = string.Empty; - if (_CFGName != value) - { - _CFGName = value; - PropertyHasChanged(); - } - } - } - private string _UserLogin = string.Empty; - public string UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserLogin", true); - return _UserLogin; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserLogin", true); - if (value == null) value = string.Empty; - if (_UserLogin != value) - { - _UserLogin = value; - PropertyHasChanged(); - } - } - } - private string _UserName = string.Empty; - public string UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserName", true); - return _UserName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserName", true); - if (value == null) value = string.Empty; - if (_UserName != value) - { - _UserName = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _UserMembershipCount = 0; - /// - /// Count of UserMemberships for this User - /// - public int UserMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMembershipCount", true); - return _UserMembershipCount; - } - } - private UserMemberships _UserMemberships = null; - /// - /// Related Field - /// - [TypeConverter(typeof(UserMembershipsConverter))] - public UserMemberships UserMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMemberships", true); - if (_UserMembershipCount < 0 || (_UserMembershipCount > 0 && _UserMemberships == null)) - _UserMemberships = UserMemberships.GetByUID(UID); - if (_UserMembershipCount < 0 ) - _UserMembershipCount = _UserMemberships == null ? 0 : _UserMemberships.Count; - if (_UserMemberships == null) - _UserMemberships = UserMemberships.New(); - return _UserMemberships; - } - } - public void Reset_UserMemberships() - { - _UserMembershipCount = -1; - } - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_UserMemberships == null ? false : _UserMemberships.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_UserMemberships == null ? true : _UserMemberships.IsValidList(list)); - } - // CSLATODO: Replace base User.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current User - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check User.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current User - protected override object GetIdValue() - { - return MyUserUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_UserMemberships != null && (hasBrokenRules = _UserMemberships.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FirstName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("MiddleName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("LastName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Suffix", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("CourtesyTitle", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("PhoneNumber", 30)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("CFGName", 8)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserLogin", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserName", 32)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _UserExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _UserExtension.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(UID, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(FirstName, ""); - //AuthorizationRules.AllowRead(MiddleName, ""); - //AuthorizationRules.AllowRead(LastName, ""); - //AuthorizationRules.AllowRead(Suffix, ""); - //AuthorizationRules.AllowRead(CourtesyTitle, ""); - //AuthorizationRules.AllowRead(PhoneNumber, ""); - //AuthorizationRules.AllowRead(CFGName, ""); - //AuthorizationRules.AllowRead(UserLogin, ""); - //AuthorizationRules.AllowRead(UserName, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(FirstName, ""); - //AuthorizationRules.AllowWrite(MiddleName, ""); - //AuthorizationRules.AllowWrite(LastName, ""); - //AuthorizationRules.AllowWrite(Suffix, ""); - //AuthorizationRules.AllowWrite(CourtesyTitle, ""); - //AuthorizationRules.AllowWrite(PhoneNumber, ""); - //AuthorizationRules.AllowWrite(CFGName, ""); - //AuthorizationRules.AllowWrite(UserLogin, ""); - //AuthorizationRules.AllowWrite(UserName, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _UserExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _UserExtension.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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _UserMembershipCount; - 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; } } - private static int _UserUnique = 0; - protected static int UserUnique - { get { return ++_UserUnique; } } - private int _MyUserUnique = UserUnique; - public int MyUserUnique // Absolutely Unique ID - Editable - { get { return _MyUserUnique; } } - protected User() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~User() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(UID.ToString())) - { - List listUser = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items - while (listUser.Contains(this)) listUser.Remove(this); // Remove the item from the list - if (listUser.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list - } - } - public static User New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a User"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.New", ex); - } - } - public static User New(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) - { - User tmp = User.New(); - tmp.UserID = userID; - tmp.FirstName = firstName; - tmp.MiddleName = middleName; - tmp.LastName = lastName; - tmp.Suffix = suffix; - tmp.CourtesyTitle = courtesyTitle; - tmp.PhoneNumber = phoneNumber; - tmp.CFGName = cFGName; - tmp.UserLogin = userLogin; - tmp.UserName = userName; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static User MakeUser(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) - { - User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static User New(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) - { - User tmp = User.New(); - tmp.FirstName = firstName; - tmp.MiddleName = middleName; - tmp.LastName = lastName; - tmp.Suffix = suffix; - tmp.CourtesyTitle = courtesyTitle; - tmp.PhoneNumber = phoneNumber; - tmp.CFGName = cFGName; - tmp.UserLogin = userLogin; - tmp.UserName = userName; - tmp.Config = config; - return tmp; - } - public static User MakeUser(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) - { - User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static User Get(int uid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a User"); - try - { - User tmp = GetCachedByPrimaryKey(uid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(uid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up User - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.Get", ex); - } - } - public static User Get(SafeDataReader dr) - { - if (dr.Read()) return new User(dr); - return null; - } - internal User(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int uid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a User"); - try - { - DataPortal.Delete(new PKCriteria(uid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.Delete", ex); - } - } - public override User Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a User"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a User"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a User"); - try - { - BuildRefreshList(); - User user = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(user);//Refresh the item in AllList - ProcessRefreshList(); - return user; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _UID; - public int UID - { get { return _UID; } } - public PKCriteria(int uid) - { - _UID = uid; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _UID = NextUID; - // Database Defaults - _UserID = _UserExtension.DefaultUserID; - _DTS = _UserExtension.DefaultDTS; - _UsrID = _UserExtension.DefaultUsrID; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.ReadData", GetHashCode()); - try - { - _UID = dr.GetInt32("UID"); - _UserID = dr.GetString("UserID"); - _FirstName = dr.GetString("FirstName"); - _MiddleName = dr.GetString("MiddleName"); - _LastName = dr.GetString("LastName"); - _Suffix = dr.GetString("Suffix"); - _CourtesyTitle = dr.GetString("CourtesyTitle"); - _PhoneNumber = dr.GetString("PhoneNumber"); - _CFGName = dr.GetString("CFGName"); - _UserLogin = dr.GetString("UserLogin"); - _UserName = dr.GetString("UserName"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _UserMembershipCount = dr.GetInt32("MembershipCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getUser"; - cm.Parameters.AddWithValue("@UID", criteria.UID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _UserMemberships = UserMemberships.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addUser"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@FirstName", _FirstName); - cm.Parameters.AddWithValue("@MiddleName", _MiddleName); - cm.Parameters.AddWithValue("@LastName", _LastName); - cm.Parameters.AddWithValue("@Suffix", _Suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); - cm.Parameters.AddWithValue("@CFGName", _CFGName); - cm.Parameters.AddWithValue("@UserLogin", _UserLogin); - cm.Parameters.AddWithValue("@UserName", _UserName); - 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_UID = new SqlParameter("@newUID", SqlDbType.Int); - param_UID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UID); - 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 - _UID = (int)cm.Parameters["@newUID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_UserMemberships != null) _UserMemberships.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addUser"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", userID); - cm.Parameters.AddWithValue("@FirstName", firstName); - cm.Parameters.AddWithValue("@MiddleName", middleName); - cm.Parameters.AddWithValue("@LastName", lastName); - cm.Parameters.AddWithValue("@Suffix", suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); - cm.Parameters.AddWithValue("@CFGName", cFGName); - cm.Parameters.AddWithValue("@UserLogin", userLogin); - cm.Parameters.AddWithValue("@UserName", userName); - 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_UID = new SqlParameter("@newUID", SqlDbType.Int); - param_UID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UID); - 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 - uid = (int)cm.Parameters["@newUID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Add", ex); - throw new DbCslaException("User.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] User.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateUser"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@UID", _UID); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@FirstName", _FirstName); - cm.Parameters.AddWithValue("@MiddleName", _MiddleName); - cm.Parameters.AddWithValue("@LastName", _LastName); - cm.Parameters.AddWithValue("@Suffix", _Suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); - cm.Parameters.AddWithValue("@CFGName", _CFGName); - cm.Parameters.AddWithValue("@UserLogin", _UserLogin); - cm.Parameters.AddWithValue("@UserName", _UserName); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - if (_UserMemberships != null) _UserMemberships.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = User.Add(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID); - else - _LastChanged = User.Update(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - if (_UserMemberships != null) _UserMemberships.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateUser"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UID", uid); - cm.Parameters.AddWithValue("@UserID", userID); - cm.Parameters.AddWithValue("@FirstName", firstName); - cm.Parameters.AddWithValue("@MiddleName", middleName); - cm.Parameters.AddWithValue("@LastName", lastName); - cm.Parameters.AddWithValue("@Suffix", suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); - cm.Parameters.AddWithValue("@CFGName", cFGName); - cm.Parameters.AddWithValue("@UserLogin", userLogin); - cm.Parameters.AddWithValue("@UserName", userName); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Update", ex); - throw new DbCslaException("User.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_UID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteUser"; - cm.Parameters.AddWithValue("@UID", criteria.UID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int uid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteUser"; - // Input PK Fields - cm.Parameters.AddWithValue("@UID", uid); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Remove", ex); - throw new DbCslaException("User.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int uid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(uid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _UID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int uid) - { - _UID = uid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsUser"; - cm.Parameters.AddWithValue("@UID", _UID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Execute", ex); - throw new DbCslaException("User.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - UserExtension _UserExtension = new UserExtension(); - [Serializable()] - partial class UserExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Volian.Base.Library.VlnSettings.UserID; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class UserConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is User) - { - // Return the ToString value - return ((User)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// User Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserConverter))] + public partial class User : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshUsers = new List(); + private List _RefreshUserMemberships = new List(); + private void AddToRefreshList(List refreshUsers, List refreshUserMemberships) + { + if (IsDirty) + refreshUsers.Add(this); + if (_UserMemberships != null && _UserMemberships.IsDirty) + { + foreach (UserMembership tmp in _UserMemberships) + { + if (tmp.IsDirty) refreshUserMemberships.Add(tmp); + } + } + } + private void ClearRefreshList() + { + _RefreshUsers = new List(); + _RefreshUserMemberships = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshUsers, _RefreshUserMemberships); + } + private void ProcessRefreshList() + { + foreach (User tmp in _RefreshUsers) + { + UserInfo.Refresh(tmp); + } + foreach (UserMembership tmp in _RefreshUserMemberships) + { + MembershipInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(User user) + { + if (!_CacheList.Contains(user)) _CacheList.Add(user); // In AddToCache + } + protected static void RemoveFromCache(User user) + { + while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move User(s) from temporary _CacheList to _CacheByPrimaryKey + { + User tmp = _CacheList[0]; // Get the first User + string pKey = tmp.UID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first User + } + } + protected static User GetCachedByPrimaryKey(int uid) + { + ConvertListToDictionary(); + string key = uid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextUID = -1; + public static int NextUID + { + get { return _nextUID--; } + } + private int _UID; + [System.ComponentModel.DataObjectField(true, true)] + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private string _FirstName = string.Empty; + public string FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FirstName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FirstName != value) + { + _FirstName = value; + PropertyHasChanged(); + } + } + } + private string _MiddleName = string.Empty; + public string MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MiddleName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_MiddleName != value) + { + _MiddleName = value; + PropertyHasChanged(); + } + } + } + private string _LastName = string.Empty; + public string LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LastName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_LastName != value) + { + _LastName = value; + PropertyHasChanged(); + } + } + } + private string _Suffix = string.Empty; + public string Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Suffix; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Suffix != value) + { + _Suffix = value; + PropertyHasChanged(); + } + } + } + private string _CourtesyTitle = string.Empty; + public string CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CourtesyTitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_CourtesyTitle != value) + { + _CourtesyTitle = value; + PropertyHasChanged(); + } + } + } + private string _PhoneNumber = string.Empty; + public string PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PhoneNumber; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_PhoneNumber != value) + { + _PhoneNumber = value; + PropertyHasChanged(); + } + } + } + private string _CFGName = string.Empty; + public string CFGName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CFGName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_CFGName != value) + { + _CFGName = value; + PropertyHasChanged(); + } + } + } + private string _UserLogin = string.Empty; + public string UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserLogin; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserLogin != value) + { + _UserLogin = value; + PropertyHasChanged(); + } + } + } + private string _UserName = string.Empty; + public string UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserName != value) + { + _UserName = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _UserMembershipCount = 0; + /// + /// Count of UserMemberships for this User + /// + public int UserMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserMembershipCount; + } + } + private UserMemberships _UserMemberships = null; + /// + /// Related Field + /// + [TypeConverter(typeof(UserMembershipsConverter))] + public UserMemberships UserMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_UserMembershipCount < 0 || (_UserMembershipCount > 0 && _UserMemberships == null)) + _UserMemberships = UserMemberships.GetByUID(UID); + if (_UserMembershipCount < 0) + _UserMembershipCount = _UserMemberships == null ? 0 : _UserMemberships.Count; + if (_UserMemberships == null) + _UserMemberships = UserMemberships.New(); + return _UserMemberships; + } + } + public void Reset_UserMemberships() + { + _UserMembershipCount = -1; + } + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_UserMemberships == null ? false : _UserMemberships.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_UserMemberships == null ? true : _UserMemberships.IsValidList(list)); + } + // CSLATODO: Replace base User.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current User + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check User.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current User + protected override object GetIdValue() + { + return MyUserUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_UserMemberships != null && (hasBrokenRules = _UserMemberships.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FirstName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("MiddleName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("LastName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Suffix", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("CourtesyTitle", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("PhoneNumber", 30)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("CFGName", 8)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserLogin", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserName", 32)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _UserExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _UserExtension.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(UID, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(FirstName, ""); + //AuthorizationRules.AllowRead(MiddleName, ""); + //AuthorizationRules.AllowRead(LastName, ""); + //AuthorizationRules.AllowRead(Suffix, ""); + //AuthorizationRules.AllowRead(CourtesyTitle, ""); + //AuthorizationRules.AllowRead(PhoneNumber, ""); + //AuthorizationRules.AllowRead(CFGName, ""); + //AuthorizationRules.AllowRead(UserLogin, ""); + //AuthorizationRules.AllowRead(UserName, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(FirstName, ""); + //AuthorizationRules.AllowWrite(MiddleName, ""); + //AuthorizationRules.AllowWrite(LastName, ""); + //AuthorizationRules.AllowWrite(Suffix, ""); + //AuthorizationRules.AllowWrite(CourtesyTitle, ""); + //AuthorizationRules.AllowWrite(PhoneNumber, ""); + //AuthorizationRules.AllowWrite(CFGName, ""); + //AuthorizationRules.AllowWrite(UserLogin, ""); + //AuthorizationRules.AllowWrite(UserName, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _UserExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _UserExtension.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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _UserMembershipCount; + 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; } } + private static int _UserUnique = 0; + protected static int UserUnique + { get { return ++_UserUnique; } } + private int _MyUserUnique = UserUnique; + public int MyUserUnique // Absolutely Unique ID - Editable + { get { return _MyUserUnique; } } + protected User() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~User() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(UID.ToString())) + { + List listUser = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items + while (listUser.Contains(this)) listUser.Remove(this); // Remove the item from the list + if (listUser.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list + } + } + public static User New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a User"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.New", ex); + } + } + public static User New(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) + { + User tmp = User.New(); + tmp.UserID = userID; + tmp.FirstName = firstName; + tmp.MiddleName = middleName; + tmp.LastName = lastName; + tmp.Suffix = suffix; + tmp.CourtesyTitle = courtesyTitle; + tmp.PhoneNumber = phoneNumber; + tmp.CFGName = cFGName; + tmp.UserLogin = userLogin; + tmp.UserName = userName; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static User MakeUser(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) + { + User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static User New(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) + { + User tmp = User.New(); + tmp.FirstName = firstName; + tmp.MiddleName = middleName; + tmp.LastName = lastName; + tmp.Suffix = suffix; + tmp.CourtesyTitle = courtesyTitle; + tmp.PhoneNumber = phoneNumber; + tmp.CFGName = cFGName; + tmp.UserLogin = userLogin; + tmp.UserName = userName; + tmp.Config = config; + return tmp; + } + public static User MakeUser(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) + { + User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static User Get(int uid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a User"); + try + { + User tmp = GetCachedByPrimaryKey(uid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(uid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up User + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.Get", ex); + } + } + public static User Get(SafeDataReader dr) + { + if (dr.Read()) return new User(dr); + return null; + } + internal User(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int uid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a User"); + try + { + DataPortal.Delete(new PKCriteria(uid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.Delete", ex); + } + } + public override User Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a User"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a User"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a User"); + try + { + BuildRefreshList(); + User user = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(user);//Refresh the item in AllList + ProcessRefreshList(); + return user; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _UID; + public int UID + { get { return _UID; } } + public PKCriteria(int uid) + { + _UID = uid; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _UID = NextUID; + // Database Defaults + _UserID = _UserExtension.DefaultUserID; + _DTS = _UserExtension.DefaultDTS; + _UsrID = _UserExtension.DefaultUsrID; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.ReadData", GetHashCode()); + try + { + _UID = dr.GetInt32("UID"); + _UserID = dr.GetString("UserID"); + _FirstName = dr.GetString("FirstName"); + _MiddleName = dr.GetString("MiddleName"); + _LastName = dr.GetString("LastName"); + _Suffix = dr.GetString("Suffix"); + _CourtesyTitle = dr.GetString("CourtesyTitle"); + _PhoneNumber = dr.GetString("PhoneNumber"); + _CFGName = dr.GetString("CFGName"); + _UserLogin = dr.GetString("UserLogin"); + _UserName = dr.GetString("UserName"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _UserMembershipCount = dr.GetInt32("MembershipCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getUser"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _UserMemberships = UserMemberships.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addUser"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@FirstName", _FirstName); + cm.Parameters.AddWithValue("@MiddleName", _MiddleName); + cm.Parameters.AddWithValue("@LastName", _LastName); + cm.Parameters.AddWithValue("@Suffix", _Suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); + cm.Parameters.AddWithValue("@CFGName", _CFGName); + cm.Parameters.AddWithValue("@UserLogin", _UserLogin); + cm.Parameters.AddWithValue("@UserName", _UserName); + 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_UID = new SqlParameter("@newUID", SqlDbType.Int); + param_UID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UID); + 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 + _UID = (int)cm.Parameters["@newUID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_UserMemberships != null) _UserMemberships.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addUser"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@FirstName", firstName); + cm.Parameters.AddWithValue("@MiddleName", middleName); + cm.Parameters.AddWithValue("@LastName", lastName); + cm.Parameters.AddWithValue("@Suffix", suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); + cm.Parameters.AddWithValue("@CFGName", cFGName); + cm.Parameters.AddWithValue("@UserLogin", userLogin); + cm.Parameters.AddWithValue("@UserName", userName); + 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_UID = new SqlParameter("@newUID", SqlDbType.Int); + param_UID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UID); + 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 + uid = (int)cm.Parameters["@newUID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Add", ex); + throw new DbCslaException("User.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] User.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateUser"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@UID", _UID); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@FirstName", _FirstName); + cm.Parameters.AddWithValue("@MiddleName", _MiddleName); + cm.Parameters.AddWithValue("@LastName", _LastName); + cm.Parameters.AddWithValue("@Suffix", _Suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); + cm.Parameters.AddWithValue("@CFGName", _CFGName); + cm.Parameters.AddWithValue("@UserLogin", _UserLogin); + cm.Parameters.AddWithValue("@UserName", _UserName); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + if (_UserMemberships != null) _UserMemberships.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = User.Add(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID); + else + _LastChanged = User.Update(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + if (_UserMemberships != null) _UserMemberships.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateUser"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UID", uid); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@FirstName", firstName); + cm.Parameters.AddWithValue("@MiddleName", middleName); + cm.Parameters.AddWithValue("@LastName", lastName); + cm.Parameters.AddWithValue("@Suffix", suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); + cm.Parameters.AddWithValue("@CFGName", cFGName); + cm.Parameters.AddWithValue("@UserLogin", userLogin); + cm.Parameters.AddWithValue("@UserName", userName); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Update", ex); + throw new DbCslaException("User.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_UID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteUser"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int uid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteUser"; + // Input PK Fields + cm.Parameters.AddWithValue("@UID", uid); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Remove", ex); + throw new DbCslaException("User.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int uid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(uid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _UID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int uid) + { + _UID = uid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsUser"; + cm.Parameters.AddWithValue("@UID", _UID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Execute", ex); + throw new DbCslaException("User.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + UserExtension _UserExtension = new UserExtension(); + [Serializable()] + partial class UserExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Volian.Base.Library.VlnSettings.UserID; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class UserConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is User) + { + // Return the ToString value + return ((User)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs index 16985a2f..b1caa2a4 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/UserInfo.cs @@ -19,484 +19,468 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void UserInfoEvent(object sender); - /// - /// UserInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(UserInfoConverter))] - public partial class UserInfo : ReadOnlyBase, IDisposable - { - public event UserInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(UserInfo userInfo) - { - if (!_CacheList.Contains(userInfo)) _CacheList.Add(userInfo); // In AddToCache - } - protected static void RemoveFromCache(UserInfo userInfo) - { - while (_CacheList.Contains(userInfo)) _CacheList.Remove(userInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move UserInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - UserInfo tmp = _CacheList[0]; // Get the first UserInfo - string pKey = tmp.UID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first UserInfo - } - } - internal static void AddList(UserInfoList lst) - { - foreach (UserInfo item in lst) AddToCache(item); - } - protected static UserInfo GetCachedByPrimaryKey(int uid) - { - ConvertListToDictionary(); - string key = uid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected User _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _UID; - [System.ComponentModel.DataObjectField(true, true)] - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - return _UID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private string _FirstName = string.Empty; - public string FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FirstName", true); - return _FirstName; - } - } - private string _MiddleName = string.Empty; - public string MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MiddleName", true); - return _MiddleName; - } - } - private string _LastName = string.Empty; - public string LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LastName", true); - return _LastName; - } - } - private string _Suffix = string.Empty; - public string Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Suffix", true); - return _Suffix; - } - } - private string _CourtesyTitle = string.Empty; - public string CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CourtesyTitle", true); - return _CourtesyTitle; - } - } - private string _PhoneNumber = string.Empty; - public string PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PhoneNumber", true); - return _PhoneNumber; - } - } - private string _CFGName = string.Empty; - public string CFGName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CFGName", true); - return _CFGName; - } - } - private string _UserLogin = string.Empty; - public string UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserLogin", true); - return _UserLogin; - } - } - private string _UserName = string.Empty; - public string UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserName", true); - return _UserName; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _UserMembershipCount = 0; - /// - /// Count of UserMemberships for this User - /// - public int UserMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMembershipCount", true); - if (_UserMembershipCount < 0) - _UserMembershipCount = UserMemberships.Count; - return _UserMembershipCount; - } - } - private MembershipInfoList _UserMemberships = null; - [TypeConverter(typeof(MembershipInfoListConverter))] - public MembershipInfoList UserMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMemberships", true); - if (_UserMembershipCount < 0 || (_UserMembershipCount > 0 && _UserMemberships == null)) - _UserMemberships = MembershipInfoList.GetByUID(_UID); - if (_UserMembershipCount < 0) - _UserMembershipCount = _UserMemberships.Count; - return _UserMemberships; - } - } - public void RefreshUserMemberships() - { - _UserMembershipCount = -1; - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_UID.ToString())) - foreach (UserInfo tmp in _CacheByPrimaryKey[_UID.ToString()]) - tmp._UserMembershipCount = -1; // This will cause the data to be requeried - } - // CSLATODO: Replace base UserInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current UserInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check UserInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current UserInfo - protected override object GetIdValue() - { - return MyUserInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _UserInfoUnique = 0; - private static int UserInfoUnique - { get { return ++_UserInfoUnique; } } - private int _MyUserInfoUnique = UserInfoUnique; - public int MyUserInfoUnique // Absolutely Unique ID - Info - { get { return _MyUserInfoUnique; } } - protected UserInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~UserInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(UID.ToString())) return; - List listUserInfo = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items - while (listUserInfo.Contains(this)) listUserInfo.Remove(this); // Remove the item from the list - if (listUserInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list - } - public virtual User Get() - { - return _Editable = User.Get(_UID); - } - public static void Refresh(User tmp) - { - string key = tmp.UID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (UserInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(User tmp) - { - _UserID = tmp.UserID; - _FirstName = tmp.FirstName; - _MiddleName = tmp.MiddleName; - _LastName = tmp.LastName; - _Suffix = tmp.Suffix; - _CourtesyTitle = tmp.CourtesyTitle; - _PhoneNumber = tmp.PhoneNumber; - _CFGName = tmp.CFGName; - _UserLogin = tmp.UserLogin; - _UserName = tmp.UserName; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _UserInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static UserInfo Get(int uid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a User"); - try - { - UserInfo tmp = GetCachedByPrimaryKey(uid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(uid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up UserInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on UserInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal UserInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.Constructor", ex); - throw new DbCslaException("UserInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _UID; - public int UID - { get { return _UID; } } - public PKCriteria(int uid) - { - _UID = uid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.ReadData", GetHashCode()); - try - { - _UID = dr.GetInt32("UID"); - _UserID = dr.GetString("UserID"); - _FirstName = dr.GetString("FirstName"); - _MiddleName = dr.GetString("MiddleName"); - _LastName = dr.GetString("LastName"); - _Suffix = dr.GetString("Suffix"); - _CourtesyTitle = dr.GetString("CourtesyTitle"); - _PhoneNumber = dr.GetString("PhoneNumber"); - _CFGName = dr.GetString("CFGName"); - _UserLogin = dr.GetString("UserLogin"); - _UserName = dr.GetString("UserName"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _UserMembershipCount = dr.GetInt32("MembershipCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("UserInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getUser"; - cm.Parameters.AddWithValue("@UID", criteria.UID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("UserInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - UserInfoExtension _UserInfoExtension = new UserInfoExtension(); - [Serializable()] - partial class UserInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(UserInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class UserInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is UserInfo) - { - // Return the ToString value - return ((UserInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void UserInfoEvent(object sender); + /// + /// UserInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserInfoConverter))] + public partial class UserInfo : ReadOnlyBase, IDisposable + { + public event UserInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(UserInfo userInfo) + { + if (!_CacheList.Contains(userInfo)) _CacheList.Add(userInfo); // In AddToCache + } + protected static void RemoveFromCache(UserInfo userInfo) + { + while (_CacheList.Contains(userInfo)) _CacheList.Remove(userInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move UserInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + UserInfo tmp = _CacheList[0]; // Get the first UserInfo + string pKey = tmp.UID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first UserInfo + } + } + internal static void AddList(UserInfoList lst) + { + foreach (UserInfo item in lst) AddToCache(item); + } + protected static UserInfo GetCachedByPrimaryKey(int uid) + { + ConvertListToDictionary(); + string key = uid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected User _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _UID; + [System.ComponentModel.DataObjectField(true, true)] + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private string _FirstName = string.Empty; + public string FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FirstName; + } + } + private string _MiddleName = string.Empty; + public string MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MiddleName; + } + } + private string _LastName = string.Empty; + public string LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LastName; + } + } + private string _Suffix = string.Empty; + public string Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Suffix; + } + } + private string _CourtesyTitle = string.Empty; + public string CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CourtesyTitle; + } + } + private string _PhoneNumber = string.Empty; + public string PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PhoneNumber; + } + } + private string _CFGName = string.Empty; + public string CFGName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CFGName; + } + } + private string _UserLogin = string.Empty; + public string UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserLogin; + } + } + private string _UserName = string.Empty; + public string UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserName; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _UserMembershipCount = 0; + /// + /// Count of UserMemberships for this User + /// + public int UserMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_UserMembershipCount < 0) + _UserMembershipCount = UserMemberships.Count; + return _UserMembershipCount; + } + } + private MembershipInfoList _UserMemberships = null; + [TypeConverter(typeof(MembershipInfoListConverter))] + public MembershipInfoList UserMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_UserMembershipCount < 0 || (_UserMembershipCount > 0 && _UserMemberships == null)) + _UserMemberships = MembershipInfoList.GetByUID(_UID); + if (_UserMembershipCount < 0) + _UserMembershipCount = _UserMemberships.Count; + return _UserMemberships; + } + } + public void RefreshUserMemberships() + { + _UserMembershipCount = -1; + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_UID.ToString())) + foreach (UserInfo tmp in _CacheByPrimaryKey[_UID.ToString()]) + tmp._UserMembershipCount = -1; // This will cause the data to be requeried + } + // CSLATODO: Replace base UserInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current UserInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check UserInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current UserInfo + protected override object GetIdValue() + { + return MyUserInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _UserInfoUnique = 0; + private static int UserInfoUnique + { get { return ++_UserInfoUnique; } } + private int _MyUserInfoUnique = UserInfoUnique; + public int MyUserInfoUnique // Absolutely Unique ID - Info + { get { return _MyUserInfoUnique; } } + protected UserInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~UserInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(UID.ToString())) return; + List listUserInfo = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items + while (listUserInfo.Contains(this)) listUserInfo.Remove(this); // Remove the item from the list + if (listUserInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list + } + public virtual User Get() + { + return _Editable = User.Get(_UID); + } + public static void Refresh(User tmp) + { + string key = tmp.UID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (UserInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(User tmp) + { + _UserID = tmp.UserID; + _FirstName = tmp.FirstName; + _MiddleName = tmp.MiddleName; + _LastName = tmp.LastName; + _Suffix = tmp.Suffix; + _CourtesyTitle = tmp.CourtesyTitle; + _PhoneNumber = tmp.PhoneNumber; + _CFGName = tmp.CFGName; + _UserLogin = tmp.UserLogin; + _UserName = tmp.UserName; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _UserInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static UserInfo Get(int uid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a User"); + try + { + UserInfo tmp = GetCachedByPrimaryKey(uid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(uid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up UserInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on UserInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal UserInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.Constructor", ex); + throw new DbCslaException("UserInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _UID; + public int UID + { get { return _UID; } } + public PKCriteria(int uid) + { + _UID = uid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.ReadData", GetHashCode()); + try + { + _UID = dr.GetInt32("UID"); + _UserID = dr.GetString("UserID"); + _FirstName = dr.GetString("FirstName"); + _MiddleName = dr.GetString("MiddleName"); + _LastName = dr.GetString("LastName"); + _Suffix = dr.GetString("Suffix"); + _CourtesyTitle = dr.GetString("CourtesyTitle"); + _PhoneNumber = dr.GetString("PhoneNumber"); + _CFGName = dr.GetString("CFGName"); + _UserLogin = dr.GetString("UserLogin"); + _UserName = dr.GetString("UserName"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _UserMembershipCount = dr.GetInt32("MembershipCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("UserInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getUser"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("UserInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + UserInfoExtension _UserInfoExtension = new UserInfoExtension(); + [Serializable()] + partial class UserInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(UserInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class UserInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is UserInfo) + { + // Return the ToString value + return ((UserInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/UserMembership.cs b/PROMS/VEPROMS.CSLA.Library/Generated/UserMembership.cs index c93cb1f1..976e0629 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/UserMembership.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/UserMembership.cs @@ -20,618 +20,598 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// UserMembership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(UserMembershipConverter))] - public partial class UserMembership : BusinessBase, IVEHasBrokenRules, IDisposable - { - #region Log4Net - 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 int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - if (_MyMembership != null) _UGID = _MyMembership.UGID; - return _UGID; - } - } - private Membership _MyMembership; - [System.ComponentModel.DataObjectField(true, true)] - public Membership MyMembership - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyMembership", true); - if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); - return _MyMembership; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - _GID = value.GID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // CSLATODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Group_GroupName = string.Empty; - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupName", true); - return _Group_GroupName; - } - } - private int? _Group_GroupType; - public int? Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupType", true); - return _Group_GroupType; - } - } - private string _Group_Config = string.Empty; - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_Config", true); - return _Group_Config; - } - } - private DateTime _Group_DTS = new DateTime(); - public DateTime Group_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_DTS", true); - return _Group_DTS; - } - } - private string _Group_UsrID = string.Empty; - public string Group_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_UsrID", true); - return _Group_UsrID; - } - } - // CSLATODO: Check UserMembership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current UserMembership - protected override object GetIdValue() - { - return MyUserMembershipUnique; // Absolutely Unique ID - } - // CSLATODO: Replace base UserMembership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current UserMembership - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // CSLATODO: Add other validation rules - } - private static bool StartDateValid(UserMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(UserMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyGroupRequired(UserMembership target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - 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; } } - private static int _UserMembershipUnique = 0; - private static int UserMembershipUnique - { get { return ++_UserMembershipUnique; } } - private int _MyUserMembershipUnique = UserMembershipUnique; - public int MyUserMembershipUnique // Absolutely Unique ID - Editable FK - { get { return _MyUserMembershipUnique; } } - internal static UserMembership New(Group myGroup) - { - return new UserMembership(myGroup); - } - internal static UserMembership Get(SafeDataReader dr) - { - return new UserMembership(dr); - } - public UserMembership() - { - MarkAsChild(); - _UGID = Membership.NextUGID; - _StartDate = _UserMembershipExtension.DefaultStartDate; - _DTS = _UserMembershipExtension.DefaultDTS; - _UsrID = _UserMembershipExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private UserMembership(Group myGroup) - { - MarkAsChild(); - // CSLATODO: Add any initialization & defaults - _UGID = Membership.NextUGID; - _StartDate = _UserMembershipExtension.DefaultStartDate; - _DTS = _UserMembershipExtension.DefaultDTS; - _UsrID = _UserMembershipExtension.DefaultUsrID; - _MyGroup = myGroup; - ValidationRules.CheckRules(); - } - internal UserMembership(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - 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; } } - ~UserMembership() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserMembership.FetchDR", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _GID = dr.GetInt32("GID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Group_GroupName = dr.GetString("Group_GroupName"); - _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); - _Group_Config = dr.GetString("Group_Config"); - _Group_DTS = dr.GetDateTime("Group_DTS"); - _Group_UsrID = dr.GetString("Group_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserMembership.FetchDR", ex); - throw new DbCslaException("UserMembership.Fetch", ex); - } - MarkOld(); - } - internal void Insert(User myUser) - { - // 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); - MarkOld(); - } - internal void Update(User myUser) - { - // 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, myUser.UID, _GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(User myUser) - { - // 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"]; - Membership.Remove(cn, _UGID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - UserMembershipExtension _UserMembershipExtension = new UserMembershipExtension(); - [Serializable()] - partial class UserMembershipExtension : extensionBase - { - } - [Serializable()] - 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; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class UserMembershipConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is UserMembership) - { - // Return the ToString value - return ((UserMembership)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// UserMembership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserMembershipConverter))] + public partial class UserMembership : BusinessBase, IVEHasBrokenRules, IDisposable + { + #region Log4Net + 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 int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership != null) _UGID = _MyMembership.UGID; + return _UGID; + } + } + private Membership _MyMembership; + [System.ComponentModel.DataObjectField(true, true)] + public Membership MyMembership + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); + return _MyMembership; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + _GID = value.GID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // CSLATODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Group_GroupName = string.Empty; + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupName; + } + } + private int? _Group_GroupType; + public int? Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupType; + } + } + private string _Group_Config = string.Empty; + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_Config; + } + } + private DateTime _Group_DTS = new DateTime(); + public DateTime Group_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_DTS; + } + } + private string _Group_UsrID = string.Empty; + public string Group_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_UsrID; + } + } + // CSLATODO: Check UserMembership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current UserMembership + protected override object GetIdValue() + { + return MyUserMembershipUnique; // Absolutely Unique ID + } + // CSLATODO: Replace base UserMembership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current UserMembership + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValidList(list)); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // CSLATODO: Add other validation rules + } + private static bool StartDateValid(UserMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(UserMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyGroupRequired(UserMembership target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + 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; } } + private static int _UserMembershipUnique = 0; + private static int UserMembershipUnique + { get { return ++_UserMembershipUnique; } } + private int _MyUserMembershipUnique = UserMembershipUnique; + public int MyUserMembershipUnique // Absolutely Unique ID - Editable FK + { get { return _MyUserMembershipUnique; } } + internal static UserMembership New(Group myGroup) + { + return new UserMembership(myGroup); + } + internal static UserMembership Get(SafeDataReader dr) + { + return new UserMembership(dr); + } + public UserMembership() + { + MarkAsChild(); + _UGID = Membership.NextUGID; + _StartDate = _UserMembershipExtension.DefaultStartDate; + _DTS = _UserMembershipExtension.DefaultDTS; + _UsrID = _UserMembershipExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private UserMembership(Group myGroup) + { + MarkAsChild(); + // CSLATODO: Add any initialization & defaults + _UGID = Membership.NextUGID; + _StartDate = _UserMembershipExtension.DefaultStartDate; + _DTS = _UserMembershipExtension.DefaultDTS; + _UsrID = _UserMembershipExtension.DefaultUsrID; + _MyGroup = myGroup; + ValidationRules.CheckRules(); + } + internal UserMembership(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + 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; } } + ~UserMembership() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserMembership.FetchDR", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _GID = dr.GetInt32("GID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Group_GroupName = dr.GetString("Group_GroupName"); + _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); + _Group_Config = dr.GetString("Group_Config"); + _Group_DTS = dr.GetDateTime("Group_DTS"); + _Group_UsrID = dr.GetString("Group_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserMembership.FetchDR", ex); + throw new DbCslaException("UserMembership.Fetch", ex); + } + MarkOld(); + } + internal void Insert(User myUser) + { + // 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); + MarkOld(); + } + internal void Update(User myUser) + { + // 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, myUser.UID, _GID, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(User myUser) + { + // 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"]; + Membership.Remove(cn, _UGID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + UserMembershipExtension _UserMembershipExtension = new UserMembershipExtension(); + [Serializable()] + partial class UserMembershipExtension : extensionBase + { + } + [Serializable()] + 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; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class UserMembershipConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is UserMembership) + { + // Return the ToString value + return ((UserMembership)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Version.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Version.cs index 9204c918..daaac392 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Version.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Version.cs @@ -20,1076 +20,1059 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Version Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(VersionConverter))] - public partial class Version : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshVersions = new List(); - private void AddToRefreshList(List refreshVersions) - { - if (IsDirty) - refreshVersions.Add(this); - } - private void ClearRefreshList() - { - _RefreshVersions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshVersions); - } - private void ProcessRefreshList() - { - foreach (Version tmp in _RefreshVersions) - { - VersionInfo.Refresh(tmp); - if (tmp._MyRevision != null) RevisionInfo.Refresh(tmp._MyRevision); - if (tmp._MyStage != null) StageInfo.Refresh(tmp._MyStage); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Version version) - { - if (!_CacheList.Contains(version)) _CacheList.Add(version); // In AddToCache - } - protected static void RemoveFromCache(Version version) - { - while (_CacheList.Contains(version)) _CacheList.Remove(version); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Version(s) from temporary _CacheList to _CacheByPrimaryKey - { - Version tmp = _CacheList[0]; // Get the first Version - string pKey = tmp.VersionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Version - } - } - protected static Version GetCachedByPrimaryKey(int versionID) - { - ConvertListToDictionary(); - string key = versionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextVersionID = -1; - public static int NextVersionID - { - get { return _nextVersionID--; } - } - private int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - return _VersionID; - } - } - private int _RevisionID; - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; - return _RevisionID; - } - } - private Revision _MyRevision; - public Revision MyRevision - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRevision", true); - if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); - return _MyRevision; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRevision", true); - if (_MyRevision != value) - { - _MyRevision = value; - _RevisionID = value.RevisionID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private int _StageID; - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - if (_MyStage != null) _StageID = _MyStage.StageID; - return _StageID; - } - } - private Stage _MyStage; - public Stage MyStage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyStage", true); - if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); - return _MyStage; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyStage", true); - if (_MyStage != value) - { - _MyStage = value; - _StageID = value.StageID;// Update underlying data field - PropertyHasChanged(); - } - } - } - private byte[] _PDF; - public byte[] PDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PDF", true); - return _PDF; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PDF", true); - if (_PDF != value) - { - _PDF = value; - PropertyHasChanged(); - } - } - } - private byte[] _SummaryPDF; - public byte[] SummaryPDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SummaryPDF", true); - return _SummaryPDF; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SummaryPDF", true); - if (_SummaryPDF != value) - { - _SummaryPDF = value; - PropertyHasChanged(); - } - } - } - private string _ApprovedXML; - public string ApprovedXML - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ApprovedXML", true); - return _ApprovedXML; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ApprovedXML", true); - if (_ApprovedXML != value) - { - _ApprovedXML = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get - { - if ( base.IsDirty ) - return true; - return IsDirtyList(new List()); - } - } - public bool IsDirtyList(List list) - { - if (base.IsDirty || list.Contains(this)) - return base.IsDirty; - list.Add(this); - return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)) || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); - } - public override bool IsValid - { - get { return IsValidList(new List()); } - } - public bool IsValidList(List list) - { - if(list.Contains(this)) - return (IsNew && !IsDirty) ? true : base.IsValid; - list.Add(this); - return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)) && (_MyStage == null ? true : _MyStage.IsValidList(list)); - } - // CSLATODO: Replace base Version.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Version - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Version.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Version - protected override object GetIdValue() - { - return MyVersionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; - if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); - ValidationRules.AddRule(MyStageRequired, "MyStage"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); - //ValidationRules.AddDependantProperty("x", "y"); - _VersionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _VersionExtension.AddInstanceValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - private static bool MyRevisionRequired(Version target, Csla.Validation.RuleArgs e) - { - if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyStageRequired(Version target, Csla.Validation.RuleArgs e) - { - if (target._StageID == 0 && target._MyStage == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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, ""); - //AuthorizationRules.AllowRead(RevisionID, ""); - //AuthorizationRules.AllowRead(StageID, ""); - //AuthorizationRules.AllowRead(PDF, ""); - //AuthorizationRules.AllowRead(SummaryPDF, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RevisionID, ""); - //AuthorizationRules.AllowWrite(StageID, ""); - //AuthorizationRules.AllowWrite(PDF, ""); - //AuthorizationRules.AllowWrite(SummaryPDF, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _VersionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _VersionExtension.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; } } - private static int _VersionUnique = 0; - protected static int VersionUnique - { get { return ++_VersionUnique; } } - private int _MyVersionUnique = VersionUnique; - public int MyVersionUnique // Absolutely Unique ID - Editable - { get { return _MyVersionUnique; } } - protected Version() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Version() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) - { - List listVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items - while (listVersion.Contains(this)) listVersion.Remove(this); // Remove the item from the list - if (listVersion.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list - } - } - public static Version New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Version"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Version.New", ex); - } - } - public static Version New(Revision myRevision, Stage myStage, DateTime dts, string userID) - { - Version tmp = Version.New(); - tmp.MyRevision = myRevision; - tmp.MyStage = myStage; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Version New(Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID) - { - Version tmp = Version.New(); - tmp.MyRevision = myRevision; - tmp.MyStage = myStage; - tmp.PDF = pdf; - tmp.SummaryPDF = summaryPDF; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Version MakeVersion(Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID) - { - Version tmp = Version.New(myRevision, myStage, pdf, summaryPDF, dts, userID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Version Get(int versionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Version"); - try - { - Version tmp = GetCachedByPrimaryKey(versionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Version - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Version.Get", ex); - } - } - public static Version Get(SafeDataReader dr) - { - if (dr.Read()) return new Version(dr); - return null; - } - internal Version(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int versionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Version"); - try - { - DataPortal.Delete(new PKCriteria(versionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Version.Delete", ex); - } - } - public override Version Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Version"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Version"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Version"); - try - { - BuildRefreshList(); - Version version = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(version);//Refresh the item in AllList - ProcessRefreshList(); - return version; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _VersionID = NextVersionID; - // Database Defaults + /// + /// Version Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(VersionConverter))] + public partial class Version : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshVersions = new List(); + private void AddToRefreshList(List refreshVersions) + { + if (IsDirty) + refreshVersions.Add(this); + } + private void ClearRefreshList() + { + _RefreshVersions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshVersions); + } + private void ProcessRefreshList() + { + foreach (Version tmp in _RefreshVersions) + { + VersionInfo.Refresh(tmp); + if (tmp._MyRevision != null) RevisionInfo.Refresh(tmp._MyRevision); + if (tmp._MyStage != null) StageInfo.Refresh(tmp._MyStage); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Version version) + { + if (!_CacheList.Contains(version)) _CacheList.Add(version); // In AddToCache + } + protected static void RemoveFromCache(Version version) + { + while (_CacheList.Contains(version)) _CacheList.Remove(version); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Version(s) from temporary _CacheList to _CacheByPrimaryKey + { + Version tmp = _CacheList[0]; // Get the first Version + string pKey = tmp.VersionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Version + } + } + protected static Version GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextVersionID = -1; + public static int NextVersionID + { + get { return _nextVersionID--; } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionID; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private Revision _MyRevision; + public Revision MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision == null && _RevisionID != 0) _MyRevision = Revision.Get(_RevisionID); + return _MyRevision; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRevision != value) + { + _MyRevision = value; + _RevisionID = value.RevisionID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private Stage _MyStage; + public Stage MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage == null && _StageID != 0) _MyStage = Stage.GetJustStage(_StageID); + return _MyStage; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyStage != value) + { + _MyStage = value; + _StageID = value.StageID;// Update underlying data field + PropertyHasChanged(); + } + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PDF != value) + { + _PDF = value; + PropertyHasChanged(); + } + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SummaryPDF; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_SummaryPDF != value) + { + _SummaryPDF = value; + PropertyHasChanged(); + } + } + } + private string _ApprovedXML; + public string ApprovedXML + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ApprovedXML; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ApprovedXML != value) + { + _ApprovedXML = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get + { + if (base.IsDirty) + return true; + return IsDirtyList(new List()); + } + } + public bool IsDirtyList(List list) + { + if (base.IsDirty || list.Contains(this)) + return base.IsDirty; + list.Add(this); + return base.IsDirty || (_MyRevision == null ? false : _MyRevision.IsDirtyList(list)) || (_MyStage == null ? false : _MyStage.IsDirtyList(list)); + } + public override bool IsValid + { + get { return IsValidList(new List()); } + } + public bool IsValidList(List list) + { + if (list.Contains(this)) + return (IsNew && !IsDirty) ? true : base.IsValid; + list.Add(this); + return ((IsNew && !IsDirty) ? true : base.IsValid) && (_MyRevision == null ? true : _MyRevision.IsValidList(list)) && (_MyStage == null ? true : _MyStage.IsValidList(list)); + } + // CSLATODO: Replace base Version.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Version + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Version.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Version + protected override object GetIdValue() + { + return MyVersionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRevision != null && (hasBrokenRules = _MyRevision.HasBrokenRules) != null) return hasBrokenRules; + if (_MyStage != null && (hasBrokenRules = _MyStage.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRevisionRequired, "MyRevision"); + ValidationRules.AddRule(MyStageRequired, "MyStage"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 200)); + //ValidationRules.AddDependantProperty("x", "y"); + _VersionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _VersionExtension.AddInstanceValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + private static bool MyRevisionRequired(Version target, Csla.Validation.RuleArgs e) + { + if (target._RevisionID == 0 && target._MyRevision == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyStageRequired(Version target, Csla.Validation.RuleArgs e) + { + if (target._StageID == 0 && target._MyStage == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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, ""); + //AuthorizationRules.AllowRead(RevisionID, ""); + //AuthorizationRules.AllowRead(StageID, ""); + //AuthorizationRules.AllowRead(PDF, ""); + //AuthorizationRules.AllowRead(SummaryPDF, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RevisionID, ""); + //AuthorizationRules.AllowWrite(StageID, ""); + //AuthorizationRules.AllowWrite(PDF, ""); + //AuthorizationRules.AllowWrite(SummaryPDF, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _VersionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _VersionExtension.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; } } + private static int _VersionUnique = 0; + protected static int VersionUnique + { get { return ++_VersionUnique; } } + private int _MyVersionUnique = VersionUnique; + public int MyVersionUnique // Absolutely Unique ID - Editable + { get { return _MyVersionUnique; } } + protected Version() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Version() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) + { + List listVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listVersion.Contains(this)) listVersion.Remove(this); // Remove the item from the list + if (listVersion.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list + } + } + public static Version New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Version"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.New", ex); + } + } + public static Version New(Revision myRevision, Stage myStage, DateTime dts, string userID) + { + Version tmp = Version.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Version New(Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID) + { + Version tmp = Version.New(); + tmp.MyRevision = myRevision; + tmp.MyStage = myStage; + tmp.PDF = pdf; + tmp.SummaryPDF = summaryPDF; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Version MakeVersion(Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, DateTime dts, string userID) + { + Version tmp = Version.New(myRevision, myStage, pdf, summaryPDF, dts, userID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Version Get(int versionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Version"); + try + { + Version tmp = GetCachedByPrimaryKey(versionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Version + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.Get", ex); + } + } + public static Version Get(SafeDataReader dr) + { + if (dr.Read()) return new Version(dr); + return null; + } + internal Version(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int versionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Version"); + try + { + DataPortal.Delete(new PKCriteria(versionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.Delete", ex); + } + } + public override Version Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Version"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Version"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Version"); + try + { + BuildRefreshList(); + Version version = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(version);//Refresh the item in AllList + ProcessRefreshList(); + return version; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _VersionID = NextVersionID; + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _RevisionID = dr.GetInt32("RevisionID"); - _StageID = dr.GetInt32("StageID"); - _PDF = (byte[])dr.GetValue("PDF"); - _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); - _ApprovedXML = dr.GetString("ApprovedXML"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Version.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Version.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Version.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRevision != null) _MyRevision.Update(); - if (_MyStage != null) _MyStage.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addVersion"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RevisionID", RevisionID); - cm.Parameters.AddWithValue("@StageID", StageID); - cm.Parameters.AddWithValue("@PDF", _PDF); - cm.Parameters.AddWithValue("@SummaryPDF", _SummaryPDF); - cm.Parameters.AddWithValue("@ApprovedXML", _ApprovedXML); - 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Version.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int versionID, Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, string approvedXML, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addVersion"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RevisionID", myRevision.RevisionID); - cm.Parameters.AddWithValue("@StageID", myStage.StageID); - cm.Parameters.AddWithValue("@PDF", pdf); - cm.Parameters.AddWithValue("@SummaryPDF", summaryPDF); - cm.Parameters.AddWithValue("@ApprovedXML", approvedXML); - 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; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Add", ex); - throw new DbCslaException("Version.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Version.SQLUpdate", GetHashCode()); - try - { - if (_MyRevision != null) _MyRevision.Update(); - if (_MyStage != null) _MyStage.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateVersion"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@VersionID", _VersionID); - cm.Parameters.AddWithValue("@RevisionID", RevisionID); - cm.Parameters.AddWithValue("@StageID", StageID); - cm.Parameters.AddWithValue("@PDF", _PDF); - cm.Parameters.AddWithValue("@SummaryPDF", _SummaryPDF); - cm.Parameters.AddWithValue("@ApprovedXML", _ApprovedXML); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Version.Add(cn, ref _VersionID, _MyRevision, _MyStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); - else - _LastChanged = Version.Update(cn, ref _VersionID, _RevisionID, _StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int versionID, int revisionID, int stageID, byte[] pdf, byte[] summaryPDF, string approvedXML, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateVersion"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@VersionID", versionID); - cm.Parameters.AddWithValue("@RevisionID", revisionID); - cm.Parameters.AddWithValue("@StageID", stageID); - cm.Parameters.AddWithValue("@PDF", pdf); - cm.Parameters.AddWithValue("@SummaryPDF", summaryPDF); - cm.Parameters.AddWithValue("@ApprovedXML", approvedXML); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Update", ex); - throw new DbCslaException("Version.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}] Version.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Version.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int versionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteVersion"; - // Input PK Fields - cm.Parameters.AddWithValue("@VersionID", versionID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Remove", ex); - throw new DbCslaException("Version.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int versionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(versionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Version.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _VersionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int versionID) - { - _VersionID = versionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsVersion"; - cm.Parameters.AddWithValue("@VersionID", _VersionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Execute", ex); - throw new DbCslaException("Version.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - VersionExtension _VersionExtension = new VersionExtension(); - [Serializable()] - partial class VersionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class VersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Version) - { - // Return the ToString value - return ((Version)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _ApprovedXML = dr.GetString("ApprovedXML"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@PDF", _PDF); + cm.Parameters.AddWithValue("@SummaryPDF", _SummaryPDF); + cm.Parameters.AddWithValue("@ApprovedXML", _ApprovedXML); + 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int versionID, Revision myRevision, Stage myStage, byte[] pdf, byte[] summaryPDF, string approvedXML, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RevisionID", myRevision.RevisionID); + cm.Parameters.AddWithValue("@StageID", myStage.StageID); + cm.Parameters.AddWithValue("@PDF", pdf); + cm.Parameters.AddWithValue("@SummaryPDF", summaryPDF); + cm.Parameters.AddWithValue("@ApprovedXML", approvedXML); + 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; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Add", ex); + throw new DbCslaException("Version.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Version.SQLUpdate", GetHashCode()); + try + { + if (_MyRevision != null) _MyRevision.Update(); + if (_MyStage != null) _MyStage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateVersion"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@VersionID", _VersionID); + cm.Parameters.AddWithValue("@RevisionID", RevisionID); + cm.Parameters.AddWithValue("@StageID", StageID); + cm.Parameters.AddWithValue("@PDF", _PDF); + cm.Parameters.AddWithValue("@SummaryPDF", _SummaryPDF); + cm.Parameters.AddWithValue("@ApprovedXML", _ApprovedXML); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Version.Add(cn, ref _VersionID, _MyRevision, _MyStage, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID); + else + _LastChanged = Version.Update(cn, ref _VersionID, _RevisionID, _StageID, _PDF, _SummaryPDF, _ApprovedXML, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int versionID, int revisionID, int stageID, byte[] pdf, byte[] summaryPDF, string approvedXML, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", versionID); + cm.Parameters.AddWithValue("@RevisionID", revisionID); + cm.Parameters.AddWithValue("@StageID", stageID); + cm.Parameters.AddWithValue("@PDF", pdf); + cm.Parameters.AddWithValue("@SummaryPDF", summaryPDF); + cm.Parameters.AddWithValue("@ApprovedXML", approvedXML); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Update", ex); + throw new DbCslaException("Version.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}] Version.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Version.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int versionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteVersion"; + // Input PK Fields + cm.Parameters.AddWithValue("@VersionID", versionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.Remove", ex); + throw new DbCslaException("Version.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int versionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(versionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Version.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _VersionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int versionID) + { + _VersionID = versionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Version.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsVersion"; + cm.Parameters.AddWithValue("@VersionID", _VersionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Version.DataPortal_Execute", ex); + throw new DbCslaException("Version.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + VersionExtension _VersionExtension = new VersionExtension(); + [Serializable()] + partial class VersionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class VersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Version) + { + // Return the ToString value + return ((Version)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs index e05166da..a9c4979f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/VersionInfo.cs @@ -19,468 +19,458 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void VersionInfoEvent(object sender); - /// - /// VersionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(VersionInfoConverter))] - public partial class VersionInfo : ReadOnlyBase, IDisposable - { - public event VersionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(VersionInfo versionInfo) - { - if (!_CacheList.Contains(versionInfo)) _CacheList.Add(versionInfo); // In AddToCache - } - protected static void RemoveFromCache(VersionInfo versionInfo) - { - while (_CacheList.Contains(versionInfo)) _CacheList.Remove(versionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move VersionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - VersionInfo tmp = _CacheList[0]; // Get the first VersionInfo - string pKey = tmp.VersionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first VersionInfo - } - } - internal static void AddList(VersionInfoList lst) - { - foreach (VersionInfo item in lst) AddToCache(item); - } - protected static VersionInfo GetCachedByPrimaryKey(int versionID) - { - ConvertListToDictionary(); - string key = versionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Version _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - return _VersionID; - } - } - private int _RevisionID; - public int RevisionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RevisionID", true); - if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; - return _RevisionID; - } - } - private RevisionInfo _MyRevision; - public RevisionInfo MyRevision - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRevision", true); - if (_MyRevision == null && _RevisionID != 0) _MyRevision = RevisionInfo.Get(_RevisionID); - return _MyRevision; - } - } - private int _StageID; - public int StageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StageID", true); - if (_MyStage != null) _StageID = _MyStage.StageID; - return _StageID; - } - } - private StageInfo _MyStage; - public StageInfo MyStage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyStage", true); - if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.GetJustStage(_StageID); - return _MyStage; - } - } - private byte[] _PDF; - public byte[] PDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PDF", true); - return _PDF; - } - set - { - _PDF = value; - } - } - private byte[] _SummaryPDF; - public byte[] SummaryPDF - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SummaryPDF", true); - return _SummaryPDF; - } - set - { - _SummaryPDF = value; - } - } - private string _ApprovedXML; - public string ApprovedXML - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ApprovedXML", true); - return _ApprovedXML; - } - set - { - _ApprovedXML = value; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // CSLATODO: Replace base VersionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current VersionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check VersionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current VersionInfo - protected override object GetIdValue() - { - return MyVersionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _VersionInfoUnique = 0; - private static int VersionInfoUnique - { get { return ++_VersionInfoUnique; } } - private int _MyVersionInfoUnique = VersionInfoUnique; - public int MyVersionInfoUnique // Absolutely Unique ID - Info - { get { return _MyVersionInfoUnique; } } - protected VersionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~VersionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; - List listVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items - while (listVersionInfo.Contains(this)) listVersionInfo.Remove(this); // Remove the item from the list - if (listVersionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list - } - public virtual Version Get() - { - return _Editable = Version.Get(_VersionID); - } - public static void Refresh(Version tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Version tmp) - { - if (_RevisionID != tmp.RevisionID) - { - if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value - _RevisionID = tmp.RevisionID; // Update the value - } - _MyRevision = null; // Reset list so that the next line gets a new list - if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value - if (_StageID != tmp.StageID) - { - if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value - _StageID = tmp.StageID; // Update the value - } - _MyStage = null; // Reset list so that the next line gets a new list - if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value - _PDF = tmp.PDF; - _SummaryPDF = tmp.SummaryPDF; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _VersionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(RevisionVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RevisionVersion tmp) - { - if (_StageID != tmp.StageID) - { - if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value - _StageID = tmp.StageID; // Update the value - } - _MyStage = null; // Reset list so that the next line gets a new list - if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value - _PDF = tmp.PDF; - _SummaryPDF = tmp.SummaryPDF; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _VersionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static void Refresh(StageVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(StageVersion tmp) - { - if (_RevisionID != tmp.RevisionID) - { - if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value - _RevisionID = tmp.RevisionID; // Update the value - } - _MyRevision = null; // Reset list so that the next line gets a new list - if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value - _PDF = tmp.PDF; - _SummaryPDF = tmp.SummaryPDF; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _VersionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static VersionInfo Get(int versionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Version"); - try - { - VersionInfo tmp = GetCachedByPrimaryKey(versionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up VersionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on VersionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal VersionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.Constructor", ex); - throw new DbCslaException("VersionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _RevisionID = dr.GetInt32("RevisionID"); - _StageID = dr.GetInt32("StageID"); - _PDF = (byte[])dr.GetValue("PDF"); - _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); - _ApprovedXML = dr.GetString("ApprovedXML"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("VersionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("VersionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - VersionInfoExtension _VersionInfoExtension = new VersionInfoExtension(); - [Serializable()] - partial class VersionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(VersionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class VersionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is VersionInfo) - { - // Return the ToString value - return ((VersionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void VersionInfoEvent(object sender); + /// + /// VersionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(VersionInfoConverter))] + public partial class VersionInfo : ReadOnlyBase, IDisposable + { + public event VersionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(VersionInfo versionInfo) + { + if (!_CacheList.Contains(versionInfo)) _CacheList.Add(versionInfo); // In AddToCache + } + protected static void RemoveFromCache(VersionInfo versionInfo) + { + while (_CacheList.Contains(versionInfo)) _CacheList.Remove(versionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move VersionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + VersionInfo tmp = _CacheList[0]; // Get the first VersionInfo + string pKey = tmp.VersionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first VersionInfo + } + } + internal static void AddList(VersionInfoList lst) + { + foreach (VersionInfo item in lst) AddToCache(item); + } + protected static VersionInfo GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Version _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionID; + } + } + private int _RevisionID; + public int RevisionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision != null) _RevisionID = _MyRevision.RevisionID; + return _RevisionID; + } + } + private RevisionInfo _MyRevision; + public RevisionInfo MyRevision + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRevision == null && _RevisionID != 0) _MyRevision = RevisionInfo.Get(_RevisionID); + return _MyRevision; + } + } + private int _StageID; + public int StageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage != null) _StageID = _MyStage.StageID; + return _StageID; + } + } + private StageInfo _MyStage; + public StageInfo MyStage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyStage == null && _StageID != 0) _MyStage = StageInfo.GetJustStage(_StageID); + return _MyStage; + } + } + private byte[] _PDF; + public byte[] PDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PDF; + } + set + { + _PDF = value; + } + } + private byte[] _SummaryPDF; + public byte[] SummaryPDF + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SummaryPDF; + } + set + { + _SummaryPDF = value; + } + } + private string _ApprovedXML; + public string ApprovedXML + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ApprovedXML; + } + set + { + _ApprovedXML = value; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // CSLATODO: Replace base VersionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current VersionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check VersionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current VersionInfo + protected override object GetIdValue() + { + return MyVersionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _VersionInfoUnique = 0; + private static int VersionInfoUnique + { get { return ++_VersionInfoUnique; } } + private int _MyVersionInfoUnique = VersionInfoUnique; + public int MyVersionInfoUnique // Absolutely Unique ID - Info + { get { return _MyVersionInfoUnique; } } + protected VersionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~VersionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; + List listVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listVersionInfo.Contains(this)) listVersionInfo.Remove(this); // Remove the item from the list + if (listVersionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list + } + public virtual Version Get() + { + return _Editable = Version.Get(_VersionID); + } + public static void Refresh(Version tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Version tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value + _PDF = tmp.PDF; + _SummaryPDF = tmp.SummaryPDF; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _VersionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(RevisionVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RevisionVersion tmp) + { + if (_StageID != tmp.StageID) + { + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for old value + _StageID = tmp.StageID; // Update the value + } + _MyStage = null; // Reset list so that the next line gets a new list + if (MyStage != null) MyStage.RefreshStageVersions(); // Update List for new value + _PDF = tmp.PDF; + _SummaryPDF = tmp.SummaryPDF; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _VersionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static void Refresh(StageVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (VersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(StageVersion tmp) + { + if (_RevisionID != tmp.RevisionID) + { + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for old value + _RevisionID = tmp.RevisionID; // Update the value + } + _MyRevision = null; // Reset list so that the next line gets a new list + if (MyRevision != null) MyRevision.RefreshRevisionVersions(); // Update List for new value + _PDF = tmp.PDF; + _SummaryPDF = tmp.SummaryPDF; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _VersionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static VersionInfo Get(int versionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Version"); + try + { + VersionInfo tmp = GetCachedByPrimaryKey(versionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up VersionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on VersionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal VersionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.Constructor", ex); + throw new DbCslaException("VersionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _RevisionID = dr.GetInt32("RevisionID"); + _StageID = dr.GetInt32("StageID"); + _PDF = (byte[])dr.GetValue("PDF"); + _SummaryPDF = (byte[])dr.GetValue("SummaryPDF"); + _ApprovedXML = dr.GetString("ApprovedXML"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("VersionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] VersionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("VersionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("VersionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + VersionInfoExtension _VersionInfoExtension = new VersionInfoExtension(); + [Serializable()] + partial class VersionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(VersionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class VersionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is VersionInfo) + { + // Return the ToString value + return ((VersionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs index 6d800c7e..5c857f94 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZContent.cs @@ -20,850 +20,846 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ZContent Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZContentConverter))] - public partial class ZContent : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshZContents = new List(); - private void AddToRefreshList(List refreshZContents) - { - if (IsDirty) - refreshZContents.Add(this); - } - private void ClearRefreshList() - { - _RefreshZContents = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshZContents); - } - private void ProcessRefreshList() - { - foreach (ZContent tmp in _RefreshZContents) - { - ZContentInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZContent zContent) - { - if (!_CacheList.Contains(zContent)) _CacheList.Add(zContent); // In AddToCache - } - protected static void RemoveFromCache(ZContent zContent) - { - while (_CacheList.Contains(zContent)) _CacheList.Remove(zContent); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ZContent(s) from temporary _CacheList to _CacheByPrimaryKey - { - ZContent tmp = _CacheList[0]; // Get the first ZContent - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ZContent - } - } - protected static ZContent GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private string _OldStepSequence = string.Empty; - public string OldStepSequence - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OldStepSequence", true); - return _OldStepSequence; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("OldStepSequence", true); - if (value == null) value = string.Empty; - if (_OldStepSequence != value) - { - _OldStepSequence = value; - if (_OldStepSequence.Length > 32) - _OldStepSequence = _OldStepSequence.Substring(0, 32); - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base ZContent.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZContent - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ZContent.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZContent - protected override object GetIdValue() - { - return MyZContentUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "OldStepSequence"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("OldStepSequence", 32)); - //ValidationRules.AddDependantProperty("x", "y"); - _ZContentExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ZContentExtension.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, ""); - //AuthorizationRules.AllowRead(OldStepSequence, ""); - //AuthorizationRules.AllowWrite(OldStepSequence, ""); - _ZContentExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ZContentExtension.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; } } - private static int _ZContentUnique = 0; - protected static int ZContentUnique - { get { return ++_ZContentUnique; } } - private int _MyZContentUnique = ZContentUnique; - public int MyZContentUnique // Absolutely Unique ID - Editable - { get { return _MyZContentUnique; } } - protected ZContent() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ZContent() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listZContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listZContent.Contains(this)) listZContent.Remove(this); // Remove the item from the list - if (listZContent.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static ZContent New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZContent"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.New", ex); - } - } - public static ZContent New(Content myContent, string oldStepSequence) - { - ZContent tmp = ZContent.New(); - tmp._MyContent = myContent; - tmp.OldStepSequence = oldStepSequence; - return tmp; - } - public static ZContent MakeZContent(Content myContent, string oldStepSequence) - { - ZContent tmp = ZContent.New(myContent, oldStepSequence); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ZContent New(Content myContent) - { - ZContent tmp = ZContent.New(); - tmp._MyContent = myContent; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - public static ZContent Get(int contentID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ZContent"); - try - { - ZContent tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZContent - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.Get", ex); - } - } - public static ZContent Get(SafeDataReader dr) - { - if (dr.Read()) return new ZContent(dr); - return null; - } - internal ZContent(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int contentID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZContent"); - try - { - DataPortal.Delete(new PKCriteria(contentID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.Delete", ex); - } - } - public override ZContent Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZContent"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZContent"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ZContent"); - try - { - BuildRefreshList(); - ZContent zContent = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(zContent);//Refresh the item in AllList - ProcessRefreshList(); - return zContent; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// ZContent Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZContentConverter))] + public partial class ZContent : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshZContents = new List(); + private void AddToRefreshList(List refreshZContents) + { + if (IsDirty) + refreshZContents.Add(this); + } + private void ClearRefreshList() + { + _RefreshZContents = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshZContents); + } + private void ProcessRefreshList() + { + foreach (ZContent tmp in _RefreshZContents) + { + ZContentInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZContent zContent) + { + if (!_CacheList.Contains(zContent)) _CacheList.Add(zContent); // In AddToCache + } + protected static void RemoveFromCache(ZContent zContent) + { + while (_CacheList.Contains(zContent)) _CacheList.Remove(zContent); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ZContent(s) from temporary _CacheList to _CacheByPrimaryKey + { + ZContent tmp = _CacheList[0]; // Get the first ZContent + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ZContent + } + } + protected static ZContent GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private string _OldStepSequence = string.Empty; + public string OldStepSequence + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OldStepSequence; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_OldStepSequence != value) + { + _OldStepSequence = value; + if (_OldStepSequence.Length > 32) + _OldStepSequence = _OldStepSequence.Substring(0, 32); + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ZContent.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZContent + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ZContent.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZContent + protected override object GetIdValue() + { + return MyZContentUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "OldStepSequence"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("OldStepSequence", 32)); + //ValidationRules.AddDependantProperty("x", "y"); + _ZContentExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ZContentExtension.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, ""); + //AuthorizationRules.AllowRead(OldStepSequence, ""); + //AuthorizationRules.AllowWrite(OldStepSequence, ""); + _ZContentExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ZContentExtension.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; } } + private static int _ZContentUnique = 0; + protected static int ZContentUnique + { get { return ++_ZContentUnique; } } + private int _MyZContentUnique = ZContentUnique; + public int MyZContentUnique // Absolutely Unique ID - Editable + { get { return _MyZContentUnique; } } + protected ZContent() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ZContent() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listZContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listZContent.Contains(this)) listZContent.Remove(this); // Remove the item from the list + if (listZContent.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static ZContent New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZContent"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.New", ex); + } + } + public static ZContent New(Content myContent, string oldStepSequence) + { + ZContent tmp = ZContent.New(); + tmp._MyContent = myContent; + tmp.OldStepSequence = oldStepSequence; + return tmp; + } + public static ZContent MakeZContent(Content myContent, string oldStepSequence) + { + ZContent tmp = ZContent.New(myContent, oldStepSequence); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ZContent New(Content myContent) + { + ZContent tmp = ZContent.New(); + tmp._MyContent = myContent; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + public static ZContent Get(int contentID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ZContent"); + try + { + ZContent tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZContent + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.Get", ex); + } + } + public static ZContent Get(SafeDataReader dr) + { + if (dr.Read()) return new ZContent(dr); + return null; + } + internal ZContent(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int contentID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZContent"); + try + { + DataPortal.Delete(new PKCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.Delete", ex); + } + } + public override ZContent Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZContent"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZContent"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ZContent"); + try + { + BuildRefreshList(); + ZContent zContent = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(zContent);//Refresh the item in AllList + ProcessRefreshList(); + return zContent; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _OldStepSequence = dr.GetString("OldStepSequence"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addZContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); - // 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, Content myContent, string oldStepSequence) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addZContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); - // 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Add", ex); - throw new DbCslaException("ZContent.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ZContent.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateZContent"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Content content) - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ZContent.Add(cn, content, _OldStepSequence); - else - _LastChanged = ZContent.Update(cn, content.ContentID, _OldStepSequence, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, int contentID, string oldStepSequence, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateZContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Update", ex); - throw new DbCslaException("ZContent.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}] ZContent.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteZContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int contentID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteZContent"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Remove", ex); - throw new DbCslaException("ZContent.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsZContent"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Execute", ex); - throw new DbCslaException("ZContent.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ZContentExtension _ZContentExtension = new ZContentExtension(); - [Serializable()] - partial class ZContentExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ZContentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZContent) - { - // Return the ToString value - return ((ZContent)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _OldStepSequence = dr.GetString("OldStepSequence"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addZContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); + // 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, Content myContent, string oldStepSequence) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addZContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); + // 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Add", ex); + throw new DbCslaException("ZContent.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ZContent.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateZContent"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Content content) + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ZContent.Add(cn, content, _OldStepSequence); + else + _LastChanged = ZContent.Update(cn, content.ContentID, _OldStepSequence, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, int contentID, string oldStepSequence, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateZContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Update", ex); + throw new DbCslaException("ZContent.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}] ZContent.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteZContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int contentID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteZContent"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Remove", ex); + throw new DbCslaException("ZContent.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsZContent"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Execute", ex); + throw new DbCslaException("ZContent.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ZContentExtension _ZContentExtension = new ZContentExtension(); + [Serializable()] + partial class ZContentExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ZContentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZContent) + { + // Return the ToString value + return ((ZContent)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs index 3f0fdd02..d6997a1a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZContentInfo.cs @@ -19,318 +19,315 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ZContentInfoEvent(object sender); - /// - /// ZContentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZContentInfoConverter))] - public partial class ZContentInfo : ReadOnlyBase, IDisposable - { - public event ZContentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZContentInfo zContentInfo) - { - if (!_CacheList.Contains(zContentInfo)) _CacheList.Add(zContentInfo); // In AddToCache - } - protected static void RemoveFromCache(ZContentInfo zContentInfo) - { - while (_CacheList.Contains(zContentInfo)) _CacheList.Remove(zContentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ZContentInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ZContentInfo tmp = _CacheList[0]; // Get the first ZContentInfo - string pKey = tmp.ContentID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ZContentInfo - } - } - protected static ZContentInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ZContent _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private string _OldStepSequence = string.Empty; - public string OldStepSequence - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OldStepSequence", true); - return _OldStepSequence; - } - } - // CSLATODO: Replace base ZContentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZContentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ZContentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZContentInfo - protected override object GetIdValue() - { - return MyZContentInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ZContentInfoUnique = 0; - private static int ZContentInfoUnique - { get { return ++_ZContentInfoUnique; } } - private int _MyZContentInfoUnique = ZContentInfoUnique; - public int MyZContentInfoUnique // Absolutely Unique ID - Info - { get { return _MyZContentInfoUnique; } } - protected ZContentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ZContentInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listZContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listZContentInfo.Contains(this)) listZContentInfo.Remove(this); // Remove the item from the list - if (listZContentInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - public virtual ZContent Get() - { - return _Editable = ZContent.Get(_ContentID); - } - public static void Refresh(ZContent tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ZContentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ZContent tmp) - { - _OldStepSequence = tmp.OldStepSequence; - _ZContentInfoExtension.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 ZContentInfo Get(int contentID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ZContent"); - try - { - ZContentInfo tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZContentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ZContentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.Constructor", ex); - throw new DbCslaException("ZContentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _OldStepSequence = dr.GetString("OldStepSequence"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ZContentInfoExtension _ZContentInfoExtension = new ZContentInfoExtension(); - [Serializable()] - partial class ZContentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ZContentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ZContentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZContentInfo) - { - // Return the ToString value - return ((ZContentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ZContentInfoEvent(object sender); + /// + /// ZContentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZContentInfoConverter))] + public partial class ZContentInfo : ReadOnlyBase, IDisposable + { + public event ZContentInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZContentInfo zContentInfo) + { + if (!_CacheList.Contains(zContentInfo)) _CacheList.Add(zContentInfo); // In AddToCache + } + protected static void RemoveFromCache(ZContentInfo zContentInfo) + { + while (_CacheList.Contains(zContentInfo)) _CacheList.Remove(zContentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ZContentInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ZContentInfo tmp = _CacheList[0]; // Get the first ZContentInfo + string pKey = tmp.ContentID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ZContentInfo + } + } + protected static ZContentInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ZContent _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private string _OldStepSequence = string.Empty; + public string OldStepSequence + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OldStepSequence; + } + } + // CSLATODO: Replace base ZContentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZContentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ZContentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZContentInfo + protected override object GetIdValue() + { + return MyZContentInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ZContentInfoUnique = 0; + private static int ZContentInfoUnique + { get { return ++_ZContentInfoUnique; } } + private int _MyZContentInfoUnique = ZContentInfoUnique; + public int MyZContentInfoUnique // Absolutely Unique ID - Info + { get { return _MyZContentInfoUnique; } } + protected ZContentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ZContentInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listZContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listZContentInfo.Contains(this)) listZContentInfo.Remove(this); // Remove the item from the list + if (listZContentInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + public virtual ZContent Get() + { + return _Editable = ZContent.Get(_ContentID); + } + public static void Refresh(ZContent tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ZContentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ZContent tmp) + { + _OldStepSequence = tmp.OldStepSequence; + _ZContentInfoExtension.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 ZContentInfo Get(int contentID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ZContent"); + try + { + ZContentInfo tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZContentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ZContentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.Constructor", ex); + throw new DbCslaException("ZContentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _OldStepSequence = dr.GetString("OldStepSequence"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ZContentInfoExtension _ZContentInfoExtension = new ZContentInfoExtension(); + [Serializable()] + partial class ZContentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ZContentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ZContentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZContentInfo) + { + // Return the ToString value + return ((ZContentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs index aa450758..f62de163 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransition.cs @@ -20,848 +20,844 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ZTransition Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZTransitionConverter))] - public partial class ZTransition : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshZTransitions = new List(); - private void AddToRefreshList(List refreshZTransitions) - { - if (IsDirty) - refreshZTransitions.Add(this); - } - private void ClearRefreshList() - { - _RefreshZTransitions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshZTransitions); - } - private void ProcessRefreshList() - { - foreach (ZTransition tmp in _RefreshZTransitions) - { - ZTransitionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZTransition zTransition) - { - if (!_CacheList.Contains(zTransition)) _CacheList.Add(zTransition); // In AddToCache - } - protected static void RemoveFromCache(ZTransition zTransition) - { - while (_CacheList.Contains(zTransition)) _CacheList.Remove(zTransition); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ZTransition(s) from temporary _CacheList to _CacheByPrimaryKey - { - ZTransition tmp = _CacheList[0]; // Get the first ZTransition - string pKey = tmp.TransitionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ZTransition - } - } - protected static ZTransition GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private string _Oldto = string.Empty; - public string Oldto - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Oldto", true); - return _Oldto; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Oldto", true); - if (value == null) value = string.Empty; - if (_Oldto != value) - { - _Oldto = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base ZTransition.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZTransition - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ZTransition.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZTransition - protected override object GetIdValue() - { - return MyZTransitionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Oldto"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Oldto", 32)); - //ValidationRules.AddDependantProperty("x", "y"); - _ZTransitionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ZTransitionExtension.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(TransitionID, ""); - //AuthorizationRules.AllowRead(Oldto, ""); - //AuthorizationRules.AllowWrite(Oldto, ""); - _ZTransitionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _ZTransitionExtension.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; } } - private static int _ZTransitionUnique = 0; - protected static int ZTransitionUnique - { get { return ++_ZTransitionUnique; } } - private int _MyZTransitionUnique = ZTransitionUnique; - public int MyZTransitionUnique // Absolutely Unique ID - Editable - { get { return _MyZTransitionUnique; } } - protected ZTransition() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ZTransition() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) - { - List listZTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listZTransition.Contains(this)) listZTransition.Remove(this); // Remove the item from the list - if (listZTransition.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - } - public static ZTransition New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZTransition"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.New", ex); - } - } - public static ZTransition New(Transition myTransition, string oldto) - { - ZTransition tmp = ZTransition.New(); - tmp._MyTransition = myTransition; - tmp.Oldto = oldto; - return tmp; - } - public static ZTransition MakeZTransition(Transition myTransition, string oldto) - { - ZTransition tmp = ZTransition.New(myTransition, oldto); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ZTransition New(Transition myTransition) - { - ZTransition tmp = ZTransition.New(); - tmp._MyTransition = myTransition; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - public static ZTransition Get(int transitionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ZTransition"); - try - { - ZTransition tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZTransition - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.Get", ex); - } - } - public static ZTransition Get(SafeDataReader dr) - { - if (dr.Read()) return new ZTransition(dr); - return null; - } - internal ZTransition(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int transitionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); - try - { - DataPortal.Delete(new PKCriteria(transitionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.Delete", ex); - } - } - public override ZTransition Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZTransition"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ZTransition"); - try - { - BuildRefreshList(); - ZTransition zTransition = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(zTransition);//Refresh the item in AllList - ProcessRefreshList(); - return zTransition; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// ZTransition Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZTransitionConverter))] + public partial class ZTransition : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshZTransitions = new List(); + private void AddToRefreshList(List refreshZTransitions) + { + if (IsDirty) + refreshZTransitions.Add(this); + } + private void ClearRefreshList() + { + _RefreshZTransitions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshZTransitions); + } + private void ProcessRefreshList() + { + foreach (ZTransition tmp in _RefreshZTransitions) + { + ZTransitionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZTransition zTransition) + { + if (!_CacheList.Contains(zTransition)) _CacheList.Add(zTransition); // In AddToCache + } + protected static void RemoveFromCache(ZTransition zTransition) + { + while (_CacheList.Contains(zTransition)) _CacheList.Remove(zTransition); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ZTransition(s) from temporary _CacheList to _CacheByPrimaryKey + { + ZTransition tmp = _CacheList[0]; // Get the first ZTransition + string pKey = tmp.TransitionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ZTransition + } + } + protected static ZTransition GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private string _Oldto = string.Empty; + public string Oldto + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Oldto; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Oldto != value) + { + _Oldto = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base ZTransition.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZTransition + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ZTransition.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZTransition + protected override object GetIdValue() + { + return MyZTransitionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Oldto"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Oldto", 32)); + //ValidationRules.AddDependantProperty("x", "y"); + _ZTransitionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ZTransitionExtension.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(TransitionID, ""); + //AuthorizationRules.AllowRead(Oldto, ""); + //AuthorizationRules.AllowWrite(Oldto, ""); + _ZTransitionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _ZTransitionExtension.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; } } + private static int _ZTransitionUnique = 0; + protected static int ZTransitionUnique + { get { return ++_ZTransitionUnique; } } + private int _MyZTransitionUnique = ZTransitionUnique; + public int MyZTransitionUnique // Absolutely Unique ID - Editable + { get { return _MyZTransitionUnique; } } + protected ZTransition() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ZTransition() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) + { + List listZTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listZTransition.Contains(this)) listZTransition.Remove(this); // Remove the item from the list + if (listZTransition.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + } + public static ZTransition New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZTransition"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.New", ex); + } + } + public static ZTransition New(Transition myTransition, string oldto) + { + ZTransition tmp = ZTransition.New(); + tmp._MyTransition = myTransition; + tmp.Oldto = oldto; + return tmp; + } + public static ZTransition MakeZTransition(Transition myTransition, string oldto) + { + ZTransition tmp = ZTransition.New(myTransition, oldto); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ZTransition New(Transition myTransition) + { + ZTransition tmp = ZTransition.New(); + tmp._MyTransition = myTransition; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + public static ZTransition Get(int transitionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ZTransition"); + try + { + ZTransition tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZTransition + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.Get", ex); + } + } + public static ZTransition Get(SafeDataReader dr) + { + if (dr.Read()) return new ZTransition(dr); + return null; + } + internal ZTransition(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int transitionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); + try + { + DataPortal.Delete(new PKCriteria(transitionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.Delete", ex); + } + } + public override ZTransition Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZTransition"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ZTransition"); + try + { + BuildRefreshList(); + ZTransition zTransition = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(zTransition);//Refresh the item in AllList + ProcessRefreshList(); + return zTransition; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults + // Database Defaults - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _Oldto = dr.GetString("oldto"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addZTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", TransitionID); - cm.Parameters.AddWithValue("@Oldto", _Oldto); - // 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; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, Transition myTransition, string oldto) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "addZTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", myTransition.TransitionID); - cm.Parameters.AddWithValue("@Oldto", oldto); - // 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Add", ex); - throw new DbCslaException("ZTransition.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ZTransition.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateZTransition"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@TransitionID", TransitionID); - cm.Parameters.AddWithValue("@Oldto", _Oldto); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Transition transition) - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ZTransition.Add(cn, transition, _Oldto); - else - _LastChanged = ZTransition.Update(cn, transition.TransitionID, _Oldto, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, int transitionID, string oldto, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "updateZTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", transitionID); - cm.Parameters.AddWithValue("@Oldto", oldto); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Update", ex); - throw new DbCslaException("ZTransition.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_TransitionID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteZTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int transitionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "deleteZTransition"; - // Input PK Fields - cm.Parameters.AddWithValue("@TransitionID", transitionID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Remove", ex); - throw new DbCslaException("ZTransition.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int transitionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(transitionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _TransitionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int transitionID) - { - _TransitionID = transitionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandTimeout = Database.SQLTimeout; - cm.CommandText = "existsZTransition"; - cm.Parameters.AddWithValue("@TransitionID", _TransitionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Execute", ex); - throw new DbCslaException("ZTransition.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ZTransitionExtension _ZTransitionExtension = new ZTransitionExtension(); - [Serializable()] - partial class ZTransitionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ZTransitionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZTransition) - { - // Return the ToString value - return ((ZTransition)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _Oldto = dr.GetString("oldto"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addZTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", TransitionID); + cm.Parameters.AddWithValue("@Oldto", _Oldto); + // 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; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, Transition myTransition, string oldto) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "addZTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", myTransition.TransitionID); + cm.Parameters.AddWithValue("@Oldto", oldto); + // 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Add", ex); + throw new DbCslaException("ZTransition.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ZTransition.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateZTransition"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@TransitionID", TransitionID); + cm.Parameters.AddWithValue("@Oldto", _Oldto); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Transition transition) + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ZTransition.Add(cn, transition, _Oldto); + else + _LastChanged = ZTransition.Update(cn, transition.TransitionID, _Oldto, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, int transitionID, string oldto, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "updateZTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", transitionID); + cm.Parameters.AddWithValue("@Oldto", oldto); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Update", ex); + throw new DbCslaException("ZTransition.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_TransitionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteZTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int transitionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "deleteZTransition"; + // Input PK Fields + cm.Parameters.AddWithValue("@TransitionID", transitionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Remove", ex); + throw new DbCslaException("ZTransition.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int transitionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(transitionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _TransitionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int transitionID) + { + _TransitionID = transitionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandTimeout = Database.SQLTimeout; + cm.CommandText = "existsZTransition"; + cm.Parameters.AddWithValue("@TransitionID", _TransitionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Execute", ex); + throw new DbCslaException("ZTransition.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ZTransitionExtension _ZTransitionExtension = new ZTransitionExtension(); + [Serializable()] + partial class ZTransitionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ZTransitionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZTransition) + { + // Return the ToString value + return ((ZTransition)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs index 49ad0a9d..c0e92d69 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/ZTransitionInfo.cs @@ -19,310 +19,307 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ZTransitionInfoEvent(object sender); - /// - /// ZTransitionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZTransitionInfoConverter))] - public partial class ZTransitionInfo : ReadOnlyBase, IDisposable - { - public event ZTransitionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZTransitionInfo zTransitionInfo) - { - if (!_CacheList.Contains(zTransitionInfo)) _CacheList.Add(zTransitionInfo); // In AddToCache - } - protected static void RemoveFromCache(ZTransitionInfo zTransitionInfo) - { - while (_CacheList.Contains(zTransitionInfo)) _CacheList.Remove(zTransitionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move ZTransitionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - ZTransitionInfo tmp = _CacheList[0]; // Get the first ZTransitionInfo - string pKey = tmp.TransitionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first ZTransitionInfo - } - } - protected static ZTransitionInfo GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ZTransition _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private TransitionInfo _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public TransitionInfo MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = TransitionInfo.Get(_TransitionID); - return _MyTransition; - } - } - private string _Oldto = string.Empty; - public string Oldto - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Oldto", true); - return _Oldto; - } - } - // CSLATODO: Replace base ZTransitionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZTransitionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check ZTransitionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZTransitionInfo - protected override object GetIdValue() - { - return MyZTransitionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _ZTransitionInfoUnique = 0; - private static int ZTransitionInfoUnique - { get { return ++_ZTransitionInfoUnique; } } - private int _MyZTransitionInfoUnique = ZTransitionInfoUnique; - public int MyZTransitionInfoUnique // Absolutely Unique ID - Info - { get { return _MyZTransitionInfoUnique; } } - protected ZTransitionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~ZTransitionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; - List listZTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listZTransitionInfo.Contains(this)) listZTransitionInfo.Remove(this); // Remove the item from the list - if (listZTransitionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - public virtual ZTransition Get() - { - return _Editable = ZTransition.Get(_TransitionID); - } - public static void Refresh(ZTransition tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ZTransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ZTransition tmp) - { - _Oldto = tmp.Oldto; - _ZTransitionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ZTransitionInfo Get(int transitionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ZTransition"); - try - { - ZTransitionInfo tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZTransitionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransitionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ZTransitionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.Constructor", ex); - throw new DbCslaException("ZTransitionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _Oldto = dr.GetString("oldto"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransitionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.CommandTimeout = Database.DefaultTimeout; - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransitionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ZTransitionInfoExtension _ZTransitionInfoExtension = new ZTransitionInfoExtension(); - [Serializable()] - partial class ZTransitionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ZTransitionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ZTransitionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZTransitionInfo) - { - // Return the ToString value - return ((ZTransitionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ZTransitionInfoEvent(object sender); + /// + /// ZTransitionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZTransitionInfoConverter))] + public partial class ZTransitionInfo : ReadOnlyBase, IDisposable + { + public event ZTransitionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZTransitionInfo zTransitionInfo) + { + if (!_CacheList.Contains(zTransitionInfo)) _CacheList.Add(zTransitionInfo); // In AddToCache + } + protected static void RemoveFromCache(ZTransitionInfo zTransitionInfo) + { + while (_CacheList.Contains(zTransitionInfo)) _CacheList.Remove(zTransitionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move ZTransitionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + ZTransitionInfo tmp = _CacheList[0]; // Get the first ZTransitionInfo + string pKey = tmp.TransitionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first ZTransitionInfo + } + } + protected static ZTransitionInfo GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ZTransition _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private TransitionInfo _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public TransitionInfo MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = TransitionInfo.Get(_TransitionID); + return _MyTransition; + } + } + private string _Oldto = string.Empty; + public string Oldto + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Oldto; + } + } + // CSLATODO: Replace base ZTransitionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZTransitionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check ZTransitionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZTransitionInfo + protected override object GetIdValue() + { + return MyZTransitionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _ZTransitionInfoUnique = 0; + private static int ZTransitionInfoUnique + { get { return ++_ZTransitionInfoUnique; } } + private int _MyZTransitionInfoUnique = ZTransitionInfoUnique; + public int MyZTransitionInfoUnique // Absolutely Unique ID - Info + { get { return _MyZTransitionInfoUnique; } } + protected ZTransitionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~ZTransitionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; + List listZTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listZTransitionInfo.Contains(this)) listZTransitionInfo.Remove(this); // Remove the item from the list + if (listZTransitionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + public virtual ZTransition Get() + { + return _Editable = ZTransition.Get(_TransitionID); + } + public static void Refresh(ZTransition tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ZTransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ZTransition tmp) + { + _Oldto = tmp.Oldto; + _ZTransitionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ZTransitionInfo Get(int transitionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ZTransition"); + try + { + ZTransitionInfo tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZTransitionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransitionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ZTransitionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.Constructor", ex); + throw new DbCslaException("ZTransitionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _Oldto = dr.GetString("oldto"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransitionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransitionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ZTransitionInfoExtension _ZTransitionInfoExtension = new ZTransitionInfoExtension(); + [Serializable()] + partial class ZTransitionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ZTransitionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ZTransitionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZTransitionInfo) + { + // Return the ToString value + return ((ZTransitionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/NewGenerated/Owner.cs b/PROMS/VEPROMS.CSLA.Library/NewGenerated/Owner.cs index 25074da1..30a7d78c 100644 --- a/PROMS/VEPROMS.CSLA.Library/NewGenerated/Owner.cs +++ b/PROMS/VEPROMS.CSLA.Library/NewGenerated/Owner.cs @@ -20,926 +20,917 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Owner Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(OwnerConverter))] - public partial class Owner : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshOwners = new List(); - private void AddToRefreshList(List refreshOwners) - { - if (IsDirty) - refreshOwners.Add(this); - } - private void ClearRefreshList() - { - _RefreshOwners = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshOwners); - } - private void ProcessRefreshList() - { - foreach (Owner tmp in _RefreshOwners) - { - OwnerInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Owner owner) - { - if (!_CacheList.Contains(owner)) _CacheList.Add(owner); // In AddToCache - } - protected static void RemoveFromCache(Owner owner) - { - while (_CacheList.Contains(owner)) _CacheList.Remove(owner); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Owner(s) from temporary _CacheList to _CacheByPrimaryKey - { - Owner tmp = _CacheList[0]; // Get the first Owner - string pKey = tmp.OwnerID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Owner - } - } - protected static Owner GetCachedByPrimaryKey(int ownerID) - { - ConvertListToDictionary(); - string key = ownerID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextOwnerID = -1; - public static int NextOwnerID - { - get { return _nextOwnerID--; } - } - private int _OwnerID; - [System.ComponentModel.DataObjectField(true, true)] - public int OwnerID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerID", true); - return _OwnerID; - } - } - private int _SessionID; - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SessionID", true); - if (_SessionID != value) - { - _SessionID = value; - PropertyHasChanged(); - } - } - } - private byte _OwnerType; - public byte OwnerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerType", true); - return _OwnerType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("OwnerType", true); - if (_OwnerType != value) - { - _OwnerType = value; - PropertyHasChanged(); - } - } - } - private int _OwnerItemID; - public int OwnerItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerItemID", true); - return _OwnerItemID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("OwnerItemID", true); - if (_OwnerItemID != value) - { - _OwnerItemID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTSStart = new DateTime(); - public DateTime DTSStart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSStart", true); - return _DTSStart; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSStart", true); - if (_DTSStart != value) - { - _DTSStart = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base Owner.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Owner - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Owner.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Owner - protected override object GetIdValue() - { - return MyOwnerUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - //ValidationRules.AddDependantProperty("x", "y"); - _OwnerExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _OwnerExtension.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(OwnerID, ""); - //AuthorizationRules.AllowRead(SessionID, ""); - //AuthorizationRules.AllowRead(OwnerType, ""); - //AuthorizationRules.AllowRead(OwnerItemID, ""); - //AuthorizationRules.AllowRead(DTSStart, ""); - //AuthorizationRules.AllowWrite(SessionID, ""); - //AuthorizationRules.AllowWrite(OwnerType, ""); - //AuthorizationRules.AllowWrite(OwnerItemID, ""); - //AuthorizationRules.AllowWrite(DTSStart, ""); - _OwnerExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _OwnerExtension.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; } } - private static int _OwnerUnique = 0; - protected static int OwnerUnique - { get { return ++_OwnerUnique; } } - private int _MyOwnerUnique = OwnerUnique; - public int MyOwnerUnique // Absolutely Unique ID - Editable - { get { return _MyOwnerUnique; } } - protected Owner() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Owner() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) - { - List listOwner = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items - while (listOwner.Contains(this)) listOwner.Remove(this); // Remove the item from the list - if (listOwner.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list - } - } - public static Owner New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Owner"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.New", ex); - } - } - public static Owner New(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) - { - Owner tmp = Owner.New(); - tmp.SessionID = sessionID; - tmp.OwnerType = ownerType; - tmp.OwnerItemID = ownerItemID; - tmp.DTSStart = dTSStart; - return tmp; - } - public static Owner MakeOwner(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) - { - Owner tmp = Owner.New(sessionID, ownerType, ownerItemID, dTSStart); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Owner Get(int ownerID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Owner"); - try - { - Owner tmp = GetCachedByPrimaryKey(ownerID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ownerID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Owner - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.Get", ex); - } - } - public static Owner Get(SafeDataReader dr) - { - if (dr.Read()) return new Owner(dr); - return null; - } - internal Owner(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int ownerID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Owner"); - try - { - DataPortal.Delete(new PKCriteria(ownerID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.Delete", ex); - } - } - public override Owner Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Owner"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Owner"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Owner"); - try - { - BuildRefreshList(); - Owner owner = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(owner);//Refresh the item in AllList - ProcessRefreshList(); - return owner; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _OwnerID; - public int OwnerID - { get { return _OwnerID; } } - public PKCriteria(int ownerID) - { - _OwnerID = ownerID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _OwnerID = NextOwnerID; - // Database Defaults - _SessionID = _OwnerExtension.DefaultSessionID; - _OwnerType = _OwnerExtension.DefaultOwnerType; - _OwnerItemID = _OwnerExtension.DefaultOwnerItemID; - _DTSStart = _OwnerExtension.DefaultDTSStart; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.ReadData", GetHashCode()); - try - { - _OwnerID = dr.GetInt32("OwnerID"); - _SessionID = dr.GetInt32("SessionID"); - _OwnerType = dr.GetByte("OwnerType"); - _OwnerItemID = dr.GetInt32("OwnerItemID"); - _DTSStart = dr.GetDateTime("DTSStart"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getOwner"; - cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addOwner"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@SessionID", _SessionID); - cm.Parameters.AddWithValue("@OwnerType", _OwnerType); - cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); - if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); - // Output Calculated Columns - SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); - param_OwnerID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_OwnerID); - 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 - _OwnerID = (int)cm.Parameters["@newOwnerID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addOwner"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@SessionID", sessionID); - cm.Parameters.AddWithValue("@OwnerType", ownerType); - cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); - if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); - // Output Calculated Columns - SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); - param_OwnerID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_OwnerID); - 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 - ownerID = (int)cm.Parameters["@newOwnerID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Add", ex); - throw new DbCslaException("Owner.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Owner.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateOwner"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@OwnerID", _OwnerID); - cm.Parameters.AddWithValue("@SessionID", _SessionID); - cm.Parameters.AddWithValue("@OwnerType", _OwnerType); - cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); - if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); - 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Owner.Add(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart); - else - _LastChanged = Owner.Update(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateOwner"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@OwnerID", ownerID); - cm.Parameters.AddWithValue("@SessionID", sessionID); - cm.Parameters.AddWithValue("@OwnerType", ownerType); - cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); - if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); - 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Update", ex); - throw new DbCslaException("Owner.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_OwnerID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteOwner"; - cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Owner.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int ownerID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteOwner"; - // Input PK Fields - cm.Parameters.AddWithValue("@OwnerID", ownerID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Remove", ex); - throw new DbCslaException("Owner.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int ownerID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(ownerID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Owner.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _OwnerID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int ownerID) - { - _OwnerID = ownerID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsOwner"; - cm.Parameters.AddWithValue("@OwnerID", _OwnerID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Execute", ex); - throw new DbCslaException("Owner.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - OwnerExtension _OwnerExtension = new OwnerExtension(); - [Serializable()] - partial class OwnerExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultSessionID - { - get { return 0; } - } - public virtual byte DefaultOwnerType - { - get { return 0; } - } - public virtual int DefaultOwnerItemID - { - get { return 0; } - } - public virtual DateTime DefaultDTSStart - { - get { return DateTime.Now; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class OwnerConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Owner) - { - // Return the ToString value - return ((Owner)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Owner Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(OwnerConverter))] + public partial class Owner : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshOwners = new List(); + private void AddToRefreshList(List refreshOwners) + { + if (IsDirty) + refreshOwners.Add(this); + } + private void ClearRefreshList() + { + _RefreshOwners = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshOwners); + } + private void ProcessRefreshList() + { + foreach (Owner tmp in _RefreshOwners) + { + OwnerInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Owner owner) + { + if (!_CacheList.Contains(owner)) _CacheList.Add(owner); // In AddToCache + } + protected static void RemoveFromCache(Owner owner) + { + while (_CacheList.Contains(owner)) _CacheList.Remove(owner); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Owner(s) from temporary _CacheList to _CacheByPrimaryKey + { + Owner tmp = _CacheList[0]; // Get the first Owner + string pKey = tmp.OwnerID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Owner + } + } + protected static Owner GetCachedByPrimaryKey(int ownerID) + { + ConvertListToDictionary(); + string key = ownerID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextOwnerID = -1; + public static int NextOwnerID + { + get { return _nextOwnerID--; } + } + private int _OwnerID; + [System.ComponentModel.DataObjectField(true, true)] + public int OwnerID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerID; + } + } + private int _SessionID; + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_SessionID != value) + { + _SessionID = value; + PropertyHasChanged(); + } + } + } + private byte _OwnerType; + public byte OwnerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_OwnerType != value) + { + _OwnerType = value; + PropertyHasChanged(); + } + } + } + private int _OwnerItemID; + public int OwnerItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerItemID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_OwnerItemID != value) + { + _OwnerItemID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTSStart = new DateTime(); + public DateTime DTSStart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSStart; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSStart != value) + { + _DTSStart = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base Owner.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Owner + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Owner.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Owner + protected override object GetIdValue() + { + return MyOwnerUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + //ValidationRules.AddDependantProperty("x", "y"); + _OwnerExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _OwnerExtension.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(OwnerID, ""); + //AuthorizationRules.AllowRead(SessionID, ""); + //AuthorizationRules.AllowRead(OwnerType, ""); + //AuthorizationRules.AllowRead(OwnerItemID, ""); + //AuthorizationRules.AllowRead(DTSStart, ""); + //AuthorizationRules.AllowWrite(SessionID, ""); + //AuthorizationRules.AllowWrite(OwnerType, ""); + //AuthorizationRules.AllowWrite(OwnerItemID, ""); + //AuthorizationRules.AllowWrite(DTSStart, ""); + _OwnerExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _OwnerExtension.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; } } + private static int _OwnerUnique = 0; + protected static int OwnerUnique + { get { return ++_OwnerUnique; } } + private int _MyOwnerUnique = OwnerUnique; + public int MyOwnerUnique // Absolutely Unique ID - Editable + { get { return _MyOwnerUnique; } } + protected Owner() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Owner() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) + { + List listOwner = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items + while (listOwner.Contains(this)) listOwner.Remove(this); // Remove the item from the list + if (listOwner.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list + } + } + public static Owner New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Owner"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.New", ex); + } + } + public static Owner New(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) + { + Owner tmp = Owner.New(); + tmp.SessionID = sessionID; + tmp.OwnerType = ownerType; + tmp.OwnerItemID = ownerItemID; + tmp.DTSStart = dTSStart; + return tmp; + } + public static Owner MakeOwner(int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) + { + Owner tmp = Owner.New(sessionID, ownerType, ownerItemID, dTSStart); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Owner Get(int ownerID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Owner"); + try + { + Owner tmp = GetCachedByPrimaryKey(ownerID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ownerID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Owner + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.Get", ex); + } + } + public static Owner Get(SafeDataReader dr) + { + if (dr.Read()) return new Owner(dr); + return null; + } + internal Owner(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int ownerID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Owner"); + try + { + DataPortal.Delete(new PKCriteria(ownerID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.Delete", ex); + } + } + public override Owner Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Owner"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Owner"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Owner"); + try + { + BuildRefreshList(); + Owner owner = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(owner);//Refresh the item in AllList + ProcessRefreshList(); + return owner; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _OwnerID; + public int OwnerID + { get { return _OwnerID; } } + public PKCriteria(int ownerID) + { + _OwnerID = ownerID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _OwnerID = NextOwnerID; + // Database Defaults + _SessionID = _OwnerExtension.DefaultSessionID; + _OwnerType = _OwnerExtension.DefaultOwnerType; + _OwnerItemID = _OwnerExtension.DefaultOwnerItemID; + _DTSStart = _OwnerExtension.DefaultDTSStart; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.ReadData", GetHashCode()); + try + { + _OwnerID = dr.GetInt32("OwnerID"); + _SessionID = dr.GetInt32("SessionID"); + _OwnerType = dr.GetByte("OwnerType"); + _OwnerItemID = dr.GetInt32("OwnerItemID"); + _DTSStart = dr.GetDateTime("DTSStart"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getOwner"; + cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addOwner"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@SessionID", _SessionID); + cm.Parameters.AddWithValue("@OwnerType", _OwnerType); + cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); + if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); + // Output Calculated Columns + SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); + param_OwnerID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_OwnerID); + 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 + _OwnerID = (int)cm.Parameters["@newOwnerID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addOwner"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@SessionID", sessionID); + cm.Parameters.AddWithValue("@OwnerType", ownerType); + cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); + if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); + // Output Calculated Columns + SqlParameter param_OwnerID = new SqlParameter("@newOwnerID", SqlDbType.Int); + param_OwnerID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_OwnerID); + 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 + ownerID = (int)cm.Parameters["@newOwnerID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Add", ex); + throw new DbCslaException("Owner.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Owner.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateOwner"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@OwnerID", _OwnerID); + cm.Parameters.AddWithValue("@SessionID", _SessionID); + cm.Parameters.AddWithValue("@OwnerType", _OwnerType); + cm.Parameters.AddWithValue("@OwnerItemID", _OwnerItemID); + if (_DTSStart.Year >= 1753 && _DTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", _DTSStart); + 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Owner.Add(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart); + else + _LastChanged = Owner.Update(cn, ref _OwnerID, _SessionID, _OwnerType, _OwnerItemID, _DTSStart, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int ownerID, int sessionID, byte ownerType, int ownerItemID, DateTime dTSStart, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateOwner"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@OwnerID", ownerID); + cm.Parameters.AddWithValue("@SessionID", sessionID); + cm.Parameters.AddWithValue("@OwnerType", ownerType); + cm.Parameters.AddWithValue("@OwnerItemID", ownerItemID); + if (dTSStart.Year >= 1753 && dTSStart.Year <= 9999) cm.Parameters.AddWithValue("@DTSStart", dTSStart); + 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Update", ex); + throw new DbCslaException("Owner.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_OwnerID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteOwner"; + cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Owner.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int ownerID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteOwner"; + // Input PK Fields + cm.Parameters.AddWithValue("@OwnerID", ownerID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.Remove", ex); + throw new DbCslaException("Owner.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int ownerID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(ownerID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Owner.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _OwnerID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int ownerID) + { + _OwnerID = ownerID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Owner.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsOwner"; + cm.Parameters.AddWithValue("@OwnerID", _OwnerID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Owner.DataPortal_Execute", ex); + throw new DbCslaException("Owner.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + OwnerExtension _OwnerExtension = new OwnerExtension(); + [Serializable()] + partial class OwnerExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultSessionID + { + get { return 0; } + } + public virtual byte DefaultOwnerType + { + get { return 0; } + } + public virtual int DefaultOwnerItemID + { + get { return 0; } + } + public virtual DateTime DefaultDTSStart + { + get { return DateTime.Now; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class OwnerConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Owner) + { + // Return the ToString value + return ((Owner)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/NewGenerated/OwnerInfo.cs b/PROMS/VEPROMS.CSLA.Library/NewGenerated/OwnerInfo.cs index ebf718de..c01d2795 100644 --- a/PROMS/VEPROMS.CSLA.Library/NewGenerated/OwnerInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/NewGenerated/OwnerInfo.cs @@ -19,336 +19,331 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void OwnerInfoEvent(object sender); - /// - /// OwnerInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(OwnerInfoConverter))] - public partial class OwnerInfo : ReadOnlyBase, IDisposable - { - public event OwnerInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(OwnerInfo ownerInfo) - { - if (!_CacheList.Contains(ownerInfo)) _CacheList.Add(ownerInfo); // In AddToCache - } - protected static void RemoveFromCache(OwnerInfo ownerInfo) - { - while (_CacheList.Contains(ownerInfo)) _CacheList.Remove(ownerInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move OwnerInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - OwnerInfo tmp = _CacheList[0]; // Get the first OwnerInfo - string pKey = tmp.OwnerID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first OwnerInfo - } - } - internal static void AddList(OwnerInfoList lst) - { - foreach (OwnerInfo item in lst) AddToCache(item); - } - protected static OwnerInfo GetCachedByPrimaryKey(int ownerID) - { - ConvertListToDictionary(); - string key = ownerID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Owner _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _OwnerID; - [System.ComponentModel.DataObjectField(true, true)] - public int OwnerID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerID", true); - return _OwnerID; - } - } - private int _SessionID; - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - } - private byte _OwnerType; - public byte OwnerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerType", true); - return _OwnerType; - } - } - private int _OwnerItemID; - public int OwnerItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OwnerItemID", true); - return _OwnerItemID; - } - } - private DateTime _DTSStart = new DateTime(); - public DateTime DTSStart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSStart", true); - return _DTSStart; - } - } - // CSLATODO: Replace base OwnerInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current OwnerInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check OwnerInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current OwnerInfo - protected override object GetIdValue() - { - return MyOwnerInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _OwnerInfoUnique = 0; - private static int OwnerInfoUnique - { get { return ++_OwnerInfoUnique; } } - private int _MyOwnerInfoUnique = OwnerInfoUnique; - public int MyOwnerInfoUnique // Absolutely Unique ID - Info - { get { return _MyOwnerInfoUnique; } } - protected OwnerInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~OwnerInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) return; - List listOwnerInfo = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items - while (listOwnerInfo.Contains(this)) listOwnerInfo.Remove(this); // Remove the item from the list - if (listOwnerInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list - } - public virtual Owner Get() - { - return _Editable = Owner.Get(_OwnerID); - } - public static void Refresh(Owner tmp) - { - string key = tmp.OwnerID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (OwnerInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Owner tmp) - { - _SessionID = tmp.SessionID; - _OwnerType = tmp.OwnerType; - _OwnerItemID = tmp.OwnerItemID; - _DTSStart = tmp.DTSStart; - _OwnerInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static OwnerInfo Get(int ownerID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Owner"); - try - { - OwnerInfo tmp = GetCachedByPrimaryKey(ownerID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ownerID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up OwnerInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on OwnerInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal OwnerInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.Constructor", ex); - throw new DbCslaException("OwnerInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _OwnerID; - public int OwnerID - { get { return _OwnerID; } } - public PKCriteria(int ownerID) - { - _OwnerID = ownerID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.ReadData", GetHashCode()); - try - { - _OwnerID = dr.GetInt32("OwnerID"); - _SessionID = dr.GetInt32("SessionID"); - _OwnerType = dr.GetByte("OwnerType"); - _OwnerItemID = dr.GetInt32("OwnerItemID"); - _DTSStart = dr.GetDateTime("DTSStart"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("OwnerInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getOwner"; - cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("OwnerInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - OwnerInfoExtension _OwnerInfoExtension = new OwnerInfoExtension(); - [Serializable()] - partial class OwnerInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(OwnerInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class OwnerInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is OwnerInfo) - { - // Return the ToString value - return ((OwnerInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void OwnerInfoEvent(object sender); + /// + /// OwnerInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(OwnerInfoConverter))] + public partial class OwnerInfo : ReadOnlyBase, IDisposable + { + public event OwnerInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(OwnerInfo ownerInfo) + { + if (!_CacheList.Contains(ownerInfo)) _CacheList.Add(ownerInfo); // In AddToCache + } + protected static void RemoveFromCache(OwnerInfo ownerInfo) + { + while (_CacheList.Contains(ownerInfo)) _CacheList.Remove(ownerInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move OwnerInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + OwnerInfo tmp = _CacheList[0]; // Get the first OwnerInfo + string pKey = tmp.OwnerID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first OwnerInfo + } + } + internal static void AddList(OwnerInfoList lst) + { + foreach (OwnerInfo item in lst) AddToCache(item); + } + protected static OwnerInfo GetCachedByPrimaryKey(int ownerID) + { + ConvertListToDictionary(); + string key = ownerID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Owner _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _OwnerID; + [System.ComponentModel.DataObjectField(true, true)] + public int OwnerID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerID; + } + } + private int _SessionID; + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + } + private byte _OwnerType; + public byte OwnerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerType; + } + } + private int _OwnerItemID; + public int OwnerItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OwnerItemID; + } + } + private DateTime _DTSStart = new DateTime(); + public DateTime DTSStart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSStart; + } + } + // CSLATODO: Replace base OwnerInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current OwnerInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check OwnerInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current OwnerInfo + protected override object GetIdValue() + { + return MyOwnerInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _OwnerInfoUnique = 0; + private static int OwnerInfoUnique + { get { return ++_OwnerInfoUnique; } } + private int _MyOwnerInfoUnique = OwnerInfoUnique; + public int MyOwnerInfoUnique // Absolutely Unique ID - Info + { get { return _MyOwnerInfoUnique; } } + protected OwnerInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~OwnerInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(OwnerID.ToString())) return; + List listOwnerInfo = _CacheByPrimaryKey[OwnerID.ToString()]; // Get the list of items + while (listOwnerInfo.Contains(this)) listOwnerInfo.Remove(this); // Remove the item from the list + if (listOwnerInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(OwnerID.ToString()); // remove the list + } + public virtual Owner Get() + { + return _Editable = Owner.Get(_OwnerID); + } + public static void Refresh(Owner tmp) + { + string key = tmp.OwnerID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (OwnerInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Owner tmp) + { + _SessionID = tmp.SessionID; + _OwnerType = tmp.OwnerType; + _OwnerItemID = tmp.OwnerItemID; + _DTSStart = tmp.DTSStart; + _OwnerInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static OwnerInfo Get(int ownerID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Owner"); + try + { + OwnerInfo tmp = GetCachedByPrimaryKey(ownerID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ownerID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up OwnerInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on OwnerInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal OwnerInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.Constructor", ex); + throw new DbCslaException("OwnerInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _OwnerID; + public int OwnerID + { get { return _OwnerID; } } + public PKCriteria(int ownerID) + { + _OwnerID = ownerID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.ReadData", GetHashCode()); + try + { + _OwnerID = dr.GetInt32("OwnerID"); + _SessionID = dr.GetInt32("SessionID"); + _OwnerType = dr.GetByte("OwnerType"); + _OwnerItemID = dr.GetInt32("OwnerItemID"); + _DTSStart = dr.GetDateTime("DTSStart"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("OwnerInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] OwnerInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getOwner"; + cm.Parameters.AddWithValue("@OwnerID", criteria.OwnerID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("OwnerInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("OwnerInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + OwnerInfoExtension _OwnerInfoExtension = new OwnerInfoExtension(); + [Serializable()] + partial class OwnerInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(OwnerInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class OwnerInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is OwnerInfo) + { + // Return the ToString value + return ((OwnerInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/NewGenerated/Session.cs b/PROMS/VEPROMS.CSLA.Library/NewGenerated/Session.cs index 9a0820c0..59026810 100644 --- a/PROMS/VEPROMS.CSLA.Library/NewGenerated/Session.cs +++ b/PROMS/VEPROMS.CSLA.Library/NewGenerated/Session.cs @@ -20,1020 +20,1007 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Session Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(SessionConverter))] - public partial class Session : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshSessions = new List(); - private void AddToRefreshList(List refreshSessions) - { - if (IsDirty) - refreshSessions.Add(this); - } - private void ClearRefreshList() - { - _RefreshSessions = new List(); - } - private void BuildRefreshList() - { - ClearRefreshList(); - AddToRefreshList(_RefreshSessions); - } - private void ProcessRefreshList() - { - foreach (Session tmp in _RefreshSessions) - { - SessionInfo.Refresh(tmp); - } - ClearRefreshList(); - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Session session) - { - if (!_CacheList.Contains(session)) _CacheList.Add(session); // In AddToCache - } - protected static void RemoveFromCache(Session session) - { - while (_CacheList.Contains(session)) _CacheList.Remove(session); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move Session(s) from temporary _CacheList to _CacheByPrimaryKey - { - Session tmp = _CacheList[0]; // Get the first Session - string pKey = tmp.SessionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first Session - } - } - protected static Session GetCachedByPrimaryKey(int sessionID) - { - ConvertListToDictionary(); - string key = sessionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextSessionID = -1; - public static int NextSessionID - { - get { return _nextSessionID--; } - } - private int _SessionID; - [System.ComponentModel.DataObjectField(true, true)] - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTSDtart = new DateTime(); - public DateTime DTSDtart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSDtart", true); - return _DTSDtart; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSDtart", true); - if (_DTSDtart != value) - { - _DTSDtart = value; - PropertyHasChanged(); - } - } - } - private DateTime? _DTSEnd; - public DateTime? DTSEnd - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSEnd", true); - return _DTSEnd; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSEnd", true); - if (_DTSEnd != value) - { - _DTSEnd = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTSActivity = new DateTime(); - public DateTime DTSActivity - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSActivity", true); - return _DTSActivity; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTSActivity", true); - if (_DTSActivity != value) - { - _DTSActivity = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _MachineName = string.Empty; - public string MachineName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MachineName", true); - return _MachineName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MachineName", true); - if (value == null) value = string.Empty; - if (_MachineName != value) - { - _MachineName = value; - PropertyHasChanged(); - } - } - } - private int _ProcessID; - public int ProcessID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ProcessID", true); - return _ProcessID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ProcessID", true); - if (_ProcessID != value) - { - _ProcessID = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty; } - } - public bool IsDirtyList(List list) - { - return base.IsDirty; - } - public override bool IsValid - { - get { return (IsNew && !IsDirty) ? true : base.IsValid; } - } - public bool IsValidList(List list) - { - return (IsNew && !IsDirty) ? true : base.IsValid; - } - // CSLATODO: Replace base Session.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Session - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check Session.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Session - protected override object GetIdValue() - { - return MySessionUnique; // Absolutely Unique ID - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "MachineName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("MachineName", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _SessionExtension.AddValidationRules(ValidationRules); - // CSLATODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _SessionExtension.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(SessionID, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(DTSDtart, ""); - //AuthorizationRules.AllowRead(DTSEnd, ""); - //AuthorizationRules.AllowRead(DTSActivity, ""); - //AuthorizationRules.AllowRead(MachineName, ""); - //AuthorizationRules.AllowRead(ProcessID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(DTSDtart, ""); - //AuthorizationRules.AllowWrite(DTSEnd, ""); - //AuthorizationRules.AllowWrite(DTSActivity, ""); - //AuthorizationRules.AllowWrite(MachineName, ""); - //AuthorizationRules.AllowWrite(ProcessID, ""); - _SessionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //CSLATODO: Who can read/write which fields - _SessionExtension.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; } } - private static int _SessionUnique = 0; - protected static int SessionUnique - { get { return ++_SessionUnique; } } - private int _MySessionUnique = SessionUnique; - public int MySessionUnique // Absolutely Unique ID - Editable - { get { return _MySessionUnique; } } - protected Session() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~Session() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) - { - List listSession = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items - while (listSession.Contains(this)) listSession.Remove(this); // Remove the item from the list - if (listSession.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list - } - } - public static Session New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Session"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.New", ex); - } - } - public static Session New(string machineName, int processID) - { - Session tmp = Session.New(); - tmp.MachineName = machineName; - tmp.ProcessID = processID; - return tmp; - } - public static Session New(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) - { - Session tmp = Session.New(); - tmp.UserID = userID; - tmp.DTSDtart = dTSDtart; - tmp.DTSEnd = dTSEnd; - tmp.DTSActivity = dTSActivity; - tmp.MachineName = machineName; - tmp.ProcessID = processID; - return tmp; - } - public static Session MakeSession(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) - { - Session tmp = Session.New(userID, dTSDtart, dTSEnd, dTSActivity, machineName, processID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Session New(DateTime? dTSEnd, string machineName, int processID) - { - Session tmp = Session.New(); - tmp.DTSEnd = dTSEnd; - tmp.MachineName = machineName; - tmp.ProcessID = processID; - return tmp; - } - public static Session MakeSession(DateTime? dTSEnd, string machineName, int processID) - { - Session tmp = Session.New(dTSEnd, machineName, processID); - if (tmp.IsSavable) - tmp = tmp.Save(); - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Session Get(int sessionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Session"); - try - { - Session tmp = GetCachedByPrimaryKey(sessionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(sessionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Session - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.Get", ex); - } - } - public static Session Get(SafeDataReader dr) - { - if (dr.Read()) return new Session(dr); - return null; - } - internal Session(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int sessionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Session"); - try - { - DataPortal.Delete(new PKCriteria(sessionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.Delete", ex); - } - } - public override Session Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Session"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Session"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Session"); - try - { - BuildRefreshList(); - Session session = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(session);//Refresh the item in AllList - ProcessRefreshList(); - return session; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _SessionID; - public int SessionID - { get { return _SessionID; } } - public PKCriteria(int sessionID) - { - _SessionID = sessionID; - } - } - // CSLATODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _SessionID = NextSessionID; - // Database Defaults - _UserID = _SessionExtension.DefaultUserID; - _DTSDtart = _SessionExtension.DefaultDTSDtart; - _DTSActivity = _SessionExtension.DefaultDTSActivity; - // CSLATODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.ReadData", GetHashCode()); - try - { - _SessionID = dr.GetInt32("SessionID"); - _UserID = dr.GetString("UserID"); - _DTSDtart = dr.GetDateTime("DTSDtart"); - if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); - _DTSActivity = dr.GetDateTime("DTSActivity"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _MachineName = dr.GetString("MachineName"); - _ProcessID = dr.GetInt32("ProcessID"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getSession"; - cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addSession"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", _UserID); - if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); - if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); - if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); - cm.Parameters.AddWithValue("@MachineName", _MachineName); - cm.Parameters.AddWithValue("@ProcessID", _ProcessID); - // Output Calculated Columns - SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); - param_SessionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_SessionID); - 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 - _SessionID = (int)cm.Parameters["@newSessionID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addSession"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", userID); - if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); - if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); - if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); - cm.Parameters.AddWithValue("@MachineName", machineName); - cm.Parameters.AddWithValue("@ProcessID", processID); - // Output Calculated Columns - SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); - param_SessionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_SessionID); - 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 - sessionID = (int)cm.Parameters["@newSessionID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Add", ex); - throw new DbCslaException("Session.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Session.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateSession"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@SessionID", _SessionID); - cm.Parameters.AddWithValue("@UserID", _UserID); - if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); - if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); - if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); - cm.Parameters.AddWithValue("@LastChanged", _LastChanged); - cm.Parameters.AddWithValue("@MachineName", _MachineName); - cm.Parameters.AddWithValue("@ProcessID", _ProcessID); - // 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; - } - } - MarkOld(); - // use the open connection to update child objects - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Session.Add(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, _MachineName, _ProcessID); - else - _LastChanged = Session.Update(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, ref _LastChanged, _MachineName, _ProcessID); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, ref byte[] lastChanged, string machineName, int processID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateSession"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@SessionID", sessionID); - cm.Parameters.AddWithValue("@UserID", userID); - if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); - if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); - if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); - cm.Parameters.AddWithValue("@LastChanged", lastChanged); - cm.Parameters.AddWithValue("@MachineName", machineName); - cm.Parameters.AddWithValue("@ProcessID", processID); - // 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 - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Update", ex); - throw new DbCslaException("Session.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_SessionID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteSession"; - cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Session.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int sessionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteSession"; - // Input PK Fields - cm.Parameters.AddWithValue("@SessionID", sessionID); - // CSLATODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Remove", ex); - throw new DbCslaException("Session.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int sessionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(sessionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Session.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _SessionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int sessionID) - { - _SessionID = sessionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsSession"; - cm.Parameters.AddWithValue("@SessionID", _SessionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Execute", ex); - throw new DbCslaException("Session.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - SessionExtension _SessionExtension = new SessionExtension(); - [Serializable()] - partial class SessionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - public virtual DateTime DefaultDTSDtart - { - get { return DateTime.Now; } - } - public virtual DateTime DefaultDTSActivity - { - get { return DateTime.Now; } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class SessionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Session) - { - // Return the ToString value - return ((Session)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Session Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(SessionConverter))] + public partial class Session : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshSessions = new List(); + private void AddToRefreshList(List refreshSessions) + { + if (IsDirty) + refreshSessions.Add(this); + } + private void ClearRefreshList() + { + _RefreshSessions = new List(); + } + private void BuildRefreshList() + { + ClearRefreshList(); + AddToRefreshList(_RefreshSessions); + } + private void ProcessRefreshList() + { + foreach (Session tmp in _RefreshSessions) + { + SessionInfo.Refresh(tmp); + } + ClearRefreshList(); + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Session session) + { + if (!_CacheList.Contains(session)) _CacheList.Add(session); // In AddToCache + } + protected static void RemoveFromCache(Session session) + { + while (_CacheList.Contains(session)) _CacheList.Remove(session); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move Session(s) from temporary _CacheList to _CacheByPrimaryKey + { + Session tmp = _CacheList[0]; // Get the first Session + string pKey = tmp.SessionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first Session + } + } + protected static Session GetCachedByPrimaryKey(int sessionID) + { + ConvertListToDictionary(); + string key = sessionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextSessionID = -1; + public static int NextSessionID + { + get { return _nextSessionID--; } + } + private int _SessionID; + [System.ComponentModel.DataObjectField(true, true)] + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTSDtart = new DateTime(); + public DateTime DTSDtart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSDtart; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSDtart != value) + { + _DTSDtart = value; + PropertyHasChanged(); + } + } + } + private DateTime? _DTSEnd; + public DateTime? DTSEnd + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSEnd; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSEnd != value) + { + _DTSEnd = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTSActivity = new DateTime(); + public DateTime DTSActivity + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSActivity; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTSActivity != value) + { + _DTSActivity = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _MachineName = string.Empty; + public string MachineName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MachineName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_MachineName != value) + { + _MachineName = value; + PropertyHasChanged(); + } + } + } + private int _ProcessID; + public int ProcessID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ProcessID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ProcessID != value) + { + _ProcessID = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty; } + } + public bool IsDirtyList(List list) + { + return base.IsDirty; + } + public override bool IsValid + { + get { return (IsNew && !IsDirty) ? true : base.IsValid; } + } + public bool IsValidList(List list) + { + return (IsNew && !IsDirty) ? true : base.IsValid; + } + // CSLATODO: Replace base Session.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Session + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check Session.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Session + protected override object GetIdValue() + { + return MySessionUnique; // Absolutely Unique ID + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "MachineName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("MachineName", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _SessionExtension.AddValidationRules(ValidationRules); + // CSLATODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _SessionExtension.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(SessionID, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(DTSDtart, ""); + //AuthorizationRules.AllowRead(DTSEnd, ""); + //AuthorizationRules.AllowRead(DTSActivity, ""); + //AuthorizationRules.AllowRead(MachineName, ""); + //AuthorizationRules.AllowRead(ProcessID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(DTSDtart, ""); + //AuthorizationRules.AllowWrite(DTSEnd, ""); + //AuthorizationRules.AllowWrite(DTSActivity, ""); + //AuthorizationRules.AllowWrite(MachineName, ""); + //AuthorizationRules.AllowWrite(ProcessID, ""); + _SessionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //CSLATODO: Who can read/write which fields + _SessionExtension.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; } } + private static int _SessionUnique = 0; + protected static int SessionUnique + { get { return ++_SessionUnique; } } + private int _MySessionUnique = SessionUnique; + public int MySessionUnique // Absolutely Unique ID - Editable + { get { return _MySessionUnique; } } + protected Session() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~Session() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) + { + List listSession = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items + while (listSession.Contains(this)) listSession.Remove(this); // Remove the item from the list + if (listSession.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list + } + } + public static Session New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Session"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.New", ex); + } + } + public static Session New(string machineName, int processID) + { + Session tmp = Session.New(); + tmp.MachineName = machineName; + tmp.ProcessID = processID; + return tmp; + } + public static Session New(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) + { + Session tmp = Session.New(); + tmp.UserID = userID; + tmp.DTSDtart = dTSDtart; + tmp.DTSEnd = dTSEnd; + tmp.DTSActivity = dTSActivity; + tmp.MachineName = machineName; + tmp.ProcessID = processID; + return tmp; + } + public static Session MakeSession(string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) + { + Session tmp = Session.New(userID, dTSDtart, dTSEnd, dTSActivity, machineName, processID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Session New(DateTime? dTSEnd, string machineName, int processID) + { + Session tmp = Session.New(); + tmp.DTSEnd = dTSEnd; + tmp.MachineName = machineName; + tmp.ProcessID = processID; + return tmp; + } + public static Session MakeSession(DateTime? dTSEnd, string machineName, int processID) + { + Session tmp = Session.New(dTSEnd, machineName, processID); + if (tmp.IsSavable) + tmp = tmp.Save(); + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Session Get(int sessionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Session"); + try + { + Session tmp = GetCachedByPrimaryKey(sessionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(sessionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Session + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.Get", ex); + } + } + public static Session Get(SafeDataReader dr) + { + if (dr.Read()) return new Session(dr); + return null; + } + internal Session(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int sessionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Session"); + try + { + DataPortal.Delete(new PKCriteria(sessionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.Delete", ex); + } + } + public override Session Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Session"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Session"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Session"); + try + { + BuildRefreshList(); + Session session = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(session);//Refresh the item in AllList + ProcessRefreshList(); + return session; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _SessionID; + public int SessionID + { get { return _SessionID; } } + public PKCriteria(int sessionID) + { + _SessionID = sessionID; + } + } + // CSLATODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _SessionID = NextSessionID; + // Database Defaults + _UserID = _SessionExtension.DefaultUserID; + _DTSDtart = _SessionExtension.DefaultDTSDtart; + _DTSActivity = _SessionExtension.DefaultDTSActivity; + // CSLATODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.ReadData", GetHashCode()); + try + { + _SessionID = dr.GetInt32("SessionID"); + _UserID = dr.GetString("UserID"); + _DTSDtart = dr.GetDateTime("DTSDtart"); + if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); + _DTSActivity = dr.GetDateTime("DTSActivity"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _MachineName = dr.GetString("MachineName"); + _ProcessID = dr.GetInt32("ProcessID"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getSession"; + cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addSession"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", _UserID); + if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); + if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); + if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); + cm.Parameters.AddWithValue("@MachineName", _MachineName); + cm.Parameters.AddWithValue("@ProcessID", _ProcessID); + // Output Calculated Columns + SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); + param_SessionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_SessionID); + 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 + _SessionID = (int)cm.Parameters["@newSessionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, string machineName, int processID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addSession"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", userID); + if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); + if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); + if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); + cm.Parameters.AddWithValue("@MachineName", machineName); + cm.Parameters.AddWithValue("@ProcessID", processID); + // Output Calculated Columns + SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int); + param_SessionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_SessionID); + 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 + sessionID = (int)cm.Parameters["@newSessionID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Add", ex); + throw new DbCslaException("Session.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Session.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateSession"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@SessionID", _SessionID); + cm.Parameters.AddWithValue("@UserID", _UserID); + if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart); + if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd); + if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity); + cm.Parameters.AddWithValue("@LastChanged", _LastChanged); + cm.Parameters.AddWithValue("@MachineName", _MachineName); + cm.Parameters.AddWithValue("@ProcessID", _ProcessID); + // 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; + } + } + MarkOld(); + // use the open connection to update child objects + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Session.Add(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, _MachineName, _ProcessID); + else + _LastChanged = Session.Update(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, ref _LastChanged, _MachineName, _ProcessID); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int sessionID, string userID, DateTime dTSDtart, DateTime? dTSEnd, DateTime dTSActivity, ref byte[] lastChanged, string machineName, int processID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateSession"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@SessionID", sessionID); + cm.Parameters.AddWithValue("@UserID", userID); + if (dTSDtart.Year >= 1753 && dTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", dTSDtart); + if (dTSEnd != null && ((DateTime)dTSEnd).Year >= 1753 && ((DateTime)dTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", dTSEnd); + if (dTSActivity.Year >= 1753 && dTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", dTSActivity); + cm.Parameters.AddWithValue("@LastChanged", lastChanged); + cm.Parameters.AddWithValue("@MachineName", machineName); + cm.Parameters.AddWithValue("@ProcessID", processID); + // 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 + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Update", ex); + throw new DbCslaException("Session.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_SessionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteSession"; + cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Session.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int sessionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteSession"; + // Input PK Fields + cm.Parameters.AddWithValue("@SessionID", sessionID); + // CSLATODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.Remove", ex); + throw new DbCslaException("Session.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int sessionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(sessionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Session.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _SessionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int sessionID) + { + _SessionID = sessionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsSession"; + cm.Parameters.AddWithValue("@SessionID", _SessionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Session.DataPortal_Execute", ex); + throw new DbCslaException("Session.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + SessionExtension _SessionExtension = new SessionExtension(); + [Serializable()] + partial class SessionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + public virtual DateTime DefaultDTSDtart + { + get { return DateTime.Now; } + } + public virtual DateTime DefaultDTSActivity + { + get { return DateTime.Now; } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class SessionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Session) + { + // Return the ToString value + return ((Session)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/NewGenerated/SessionInfo.cs b/PROMS/VEPROMS.CSLA.Library/NewGenerated/SessionInfo.cs index 857d80b9..38d9ff98 100644 --- a/PROMS/VEPROMS.CSLA.Library/NewGenerated/SessionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/NewGenerated/SessionInfo.cs @@ -19,360 +19,353 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void SessionInfoEvent(object sender); - /// - /// SessionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(SessionInfoConverter))] - public partial class SessionInfo : ReadOnlyBase, IDisposable - { - public event SessionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(SessionInfo sessionInfo) - { - if (!_CacheList.Contains(sessionInfo)) _CacheList.Add(sessionInfo); // In AddToCache - } - protected static void RemoveFromCache(SessionInfo sessionInfo) - { - while (_CacheList.Contains(sessionInfo)) _CacheList.Remove(sessionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - while (_CacheList.Count > 0) // Move SessionInfo(s) from temporary _CacheList to _CacheByPrimaryKey - { - SessionInfo tmp = _CacheList[0]; // Get the first SessionInfo - string pKey = tmp.SessionID.ToString(); - if (!_CacheByPrimaryKey.ContainsKey(pKey)) - { - _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list - _CacheList.RemoveAt(0); // Remove the first SessionInfo - } - } - internal static void AddList(SessionInfoList lst) - { - foreach (SessionInfo item in lst) AddToCache(item); - } - protected static SessionInfo GetCachedByPrimaryKey(int sessionID) - { - ConvertListToDictionary(); - string key = sessionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Session _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _SessionID; - [System.ComponentModel.DataObjectField(true, true)] - public int SessionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SessionID", true); - return _SessionID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private DateTime _DTSDtart = new DateTime(); - public DateTime DTSDtart - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSDtart", true); - return _DTSDtart; - } - } - private DateTime? _DTSEnd; - public DateTime? DTSEnd - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSEnd", true); - return _DTSEnd; - } - } - private DateTime _DTSActivity = new DateTime(); - public DateTime DTSActivity - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTSActivity", true); - return _DTSActivity; - } - } - private string _MachineName = string.Empty; - public string MachineName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MachineName", true); - return _MachineName; - } - } - private int _ProcessID; - public int ProcessID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ProcessID", true); - return _ProcessID; - } - } - // CSLATODO: Replace base SessionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current SessionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // CSLATODO: Check SessionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current SessionInfo - protected override object GetIdValue() - { - return MySessionInfoUnique; // Absolutely Unique ID - } - #endregion - #region Factory Methods - private static int _SessionInfoUnique = 0; - private static int SessionInfoUnique - { get { return ++_SessionInfoUnique; } } - private int _MySessionInfoUnique = SessionInfoUnique; - public int MySessionInfoUnique // Absolutely Unique ID - Info - { get { return _MySessionInfoUnique; } } - protected SessionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - 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; } } - ~SessionInfo() - { - _CountFinalized++; - } - public void Dispose() - { - if (_Disposed) return; - _CountDisposed++; - _Disposed = true; - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) return; - List listSessionInfo = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items - while (listSessionInfo.Contains(this)) listSessionInfo.Remove(this); // Remove the item from the list - if (listSessionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list - } - public virtual Session Get() - { - return _Editable = Session.Get(_SessionID); - } - public static void Refresh(Session tmp) - { - string key = tmp.SessionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (SessionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Session tmp) - { - _UserID = tmp.UserID; - _DTSDtart = tmp.DTSDtart; - _DTSEnd = tmp.DTSEnd; - _DTSActivity = tmp.DTSActivity; - _MachineName = tmp.MachineName; - _ProcessID = tmp.ProcessID; - _SessionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static SessionInfo Get(int sessionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Session"); - try - { - SessionInfo tmp = GetCachedByPrimaryKey(sessionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(sessionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up SessionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on SessionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal SessionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.Constructor", ex); - throw new DbCslaException("SessionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _SessionID; - public int SessionID - { get { return _SessionID; } } - public PKCriteria(int sessionID) - { - _SessionID = sessionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.ReadData", GetHashCode()); - try - { - _SessionID = dr.GetInt32("SessionID"); - _UserID = dr.GetString("UserID"); - _DTSDtart = dr.GetDateTime("DTSDtart"); - if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); - _DTSActivity = dr.GetDateTime("DTSActivity"); - _MachineName = dr.GetString("MachineName"); - _ProcessID = dr.GetInt32("ProcessID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("SessionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getSession"; - cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("SessionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - SessionInfoExtension _SessionInfoExtension = new SessionInfoExtension(); - [Serializable()] - partial class SessionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(SessionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class SessionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is SessionInfo) - { - // Return the ToString value - return ((SessionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void SessionInfoEvent(object sender); + /// + /// SessionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(SessionInfoConverter))] + public partial class SessionInfo : ReadOnlyBase, IDisposable + { + public event SessionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(SessionInfo sessionInfo) + { + if (!_CacheList.Contains(sessionInfo)) _CacheList.Add(sessionInfo); // In AddToCache + } + protected static void RemoveFromCache(SessionInfo sessionInfo) + { + while (_CacheList.Contains(sessionInfo)) _CacheList.Remove(sessionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + while (_CacheList.Count > 0) // Move SessionInfo(s) from temporary _CacheList to _CacheByPrimaryKey + { + SessionInfo tmp = _CacheList[0]; // Get the first SessionInfo + string pKey = tmp.SessionID.ToString(); + if (!_CacheByPrimaryKey.ContainsKey(pKey)) + { + _CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list + _CacheList.RemoveAt(0); // Remove the first SessionInfo + } + } + internal static void AddList(SessionInfoList lst) + { + foreach (SessionInfo item in lst) AddToCache(item); + } + protected static SessionInfo GetCachedByPrimaryKey(int sessionID) + { + ConvertListToDictionary(); + string key = sessionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Session _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _SessionID; + [System.ComponentModel.DataObjectField(true, true)] + public int SessionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SessionID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private DateTime _DTSDtart = new DateTime(); + public DateTime DTSDtart + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSDtart; + } + } + private DateTime? _DTSEnd; + public DateTime? DTSEnd + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSEnd; + } + } + private DateTime _DTSActivity = new DateTime(); + public DateTime DTSActivity + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTSActivity; + } + } + private string _MachineName = string.Empty; + public string MachineName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MachineName; + } + } + private int _ProcessID; + public int ProcessID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ProcessID; + } + } + // CSLATODO: Replace base SessionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current SessionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // CSLATODO: Check SessionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current SessionInfo + protected override object GetIdValue() + { + return MySessionInfoUnique; // Absolutely Unique ID + } + #endregion + #region Factory Methods + private static int _SessionInfoUnique = 0; + private static int SessionInfoUnique + { get { return ++_SessionInfoUnique; } } + private int _MySessionInfoUnique = SessionInfoUnique; + public int MySessionInfoUnique // Absolutely Unique ID - Info + { get { return _MySessionInfoUnique; } } + protected SessionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + 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; } } + ~SessionInfo() + { + _CountFinalized++; + } + public void Dispose() + { + if (_Disposed) return; + _CountDisposed++; + _Disposed = true; + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(SessionID.ToString())) return; + List listSessionInfo = _CacheByPrimaryKey[SessionID.ToString()]; // Get the list of items + while (listSessionInfo.Contains(this)) listSessionInfo.Remove(this); // Remove the item from the list + if (listSessionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(SessionID.ToString()); // remove the list + } + public virtual Session Get() + { + return _Editable = Session.Get(_SessionID); + } + public static void Refresh(Session tmp) + { + string key = tmp.SessionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (SessionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Session tmp) + { + _UserID = tmp.UserID; + _DTSDtart = tmp.DTSDtart; + _DTSEnd = tmp.DTSEnd; + _DTSActivity = tmp.DTSActivity; + _MachineName = tmp.MachineName; + _ProcessID = tmp.ProcessID; + _SessionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static SessionInfo Get(int sessionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Session"); + try + { + SessionInfo tmp = GetCachedByPrimaryKey(sessionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(sessionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up SessionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on SessionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal SessionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.Constructor", ex); + throw new DbCslaException("SessionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _SessionID; + public int SessionID + { get { return _SessionID; } } + public PKCriteria(int sessionID) + { + _SessionID = sessionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.ReadData", GetHashCode()); + try + { + _SessionID = dr.GetInt32("SessionID"); + _UserID = dr.GetString("UserID"); + _DTSDtart = dr.GetDateTime("DTSDtart"); + if (!dr.IsDBNull(dr.GetOrdinal("DTSEnd"))) _DTSEnd = dr.GetDateTime("DTSEnd"); + _DTSActivity = dr.GetDateTime("DTSActivity"); + _MachineName = dr.GetString("MachineName"); + _ProcessID = dr.GetInt32("ProcessID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("SessionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] SessionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getSession"; + cm.Parameters.AddWithValue("@SessionID", criteria.SessionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("SessionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("SessionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + SessionInfoExtension _SessionInfoExtension = new SessionInfoExtension(); + [Serializable()] + partial class SessionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(SessionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class SessionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is SessionInfo) + { + // Return the ToString value + return ((SessionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Annotation.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Annotation.cs index 5807d177..5b2cf069 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Annotation.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Annotation.cs @@ -20,1079 +20,1062 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Annotation Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AnnotationConverter))] - public partial class Annotation : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshAnnotations = new List(); - private void AddToRefreshList(List refreshAnnotations) - { - if (IsDirty) - refreshAnnotations.Add(this); - } - private void BuildRefreshList() - { - _RefreshAnnotations = new List(); - AddToRefreshList(_RefreshAnnotations); - } - private void ProcessRefreshList() - { - foreach (Annotation tmp in _RefreshAnnotations) - { - AnnotationInfo.Refresh(tmp); - if (tmp._MyAnnotationType != null) AnnotationTypeInfo.Refresh(tmp._MyAnnotationType); - if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Annotation annotation) - { - if (!_CacheList.Contains(annotation)) _CacheList.Add(annotation); // In AddToCache - } - protected static void RemoveFromCache(Annotation annotation) - { - while (_CacheList.Contains(annotation)) _CacheList.Remove(annotation); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Annotation tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString())) - { - _CacheByPrimaryKey[tmp.AnnotationID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.AnnotationID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Annotation tmp in remove) - RemoveFromCache(tmp); - } - protected static Annotation GetCachedByPrimaryKey(int annotationID) - { - ConvertListToDictionary(); - string key = annotationID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAnnotationID = -1; - public static int NextAnnotationID - { - get { return _nextAnnotationID--; } - } - private int _AnnotationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AnnotationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationID", true); - return _AnnotationID; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if (_MyItem != value) - { - _MyItem = value; - PropertyHasChanged(); - } - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; - return _TypeID; - } - } - private AnnotationType _MyAnnotationType; - public AnnotationType MyAnnotationType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAnnotationType", true); - if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID); - return _MyAnnotationType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyAnnotationType", true); - if (_MyAnnotationType != value) - { - _MyAnnotationType = value; - PropertyHasChanged(); - } - } - } - private string _RtfText = string.Empty; - public string RtfText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RtfText", true); - return _RtfText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("RtfText", true); - if (value == null) value = string.Empty; - if (_RtfText != value) - { - _RtfText = value; - PropertyHasChanged(); - } - } - } - private string _SearchText = string.Empty; - public string SearchText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SearchText", true); - return _SearchText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SearchText", true); - if (value == null) value = string.Empty; - if (_SearchText != value) - { - _SearchText = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } - } - // TODO: Replace base Annotation.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Annotation - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Annotation.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Annotation - protected override object GetIdValue() - { - return _AnnotationID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemRequired, "MyItem"); - ValidationRules.AddRule(MyAnnotationTypeRequired, "MyAnnotationType"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _AnnotationExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _AnnotationExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyItemRequired(Annotation target, Csla.Validation.RuleArgs e) - { - if (target._ItemID == 0 && target._MyItem == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyAnnotationTypeRequired(Annotation target, Csla.Validation.RuleArgs e) - { - if (target._TypeID == 0 && target._MyAnnotationType == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AnnotationID, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(TypeID, ""); - //AuthorizationRules.AllowRead(RtfText, ""); - //AuthorizationRules.AllowRead(SearchText, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(TypeID, ""); - //AuthorizationRules.AllowWrite(RtfText, ""); - //AuthorizationRules.AllowWrite(SearchText, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _AnnotationExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _AnnotationExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _AnnotationUnique = 0; - protected static int AnnotationUnique - { get { return ++_AnnotationUnique; } } - private int _MyAnnotationUnique = AnnotationUnique; - public int MyAnnotationUnique - { get { return _MyAnnotationUnique; } } - protected Annotation() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AnnotationID.ToString())) - { - List listAnnotation = _CacheByPrimaryKey[AnnotationID.ToString()]; // Get the list of items - while (listAnnotation.Contains(this)) listAnnotation.Remove(this); // Remove the item from the list - if (listAnnotation.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list - } - } - public static Annotation New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Annotation"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Annotation.New", ex); - } - } - public static Annotation New(Item myItem, AnnotationType myAnnotationType) - { - Annotation tmp = Annotation.New(); - tmp.MyItem = myItem; - tmp.MyAnnotationType = myAnnotationType; - return tmp; - } - public static Annotation New(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID) - { - Annotation tmp = Annotation.New(); - tmp.MyItem = myItem; - tmp.MyAnnotationType = myAnnotationType; - tmp.RtfText = rtfText; - tmp.SearchText = searchText; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Annotation MakeAnnotation(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID) - { - Annotation tmp = Annotation.New(myItem, myAnnotationType, rtfText, searchText, config, dts, userID); - if (tmp.IsSavable) - { - Annotation tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Annotation New(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config) - { - Annotation tmp = Annotation.New(); - tmp.MyItem = myItem; - tmp.MyAnnotationType = myAnnotationType; - tmp.RtfText = rtfText; - tmp.SearchText = searchText; - tmp.Config = config; - return tmp; - } - public static Annotation MakeAnnotation(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config) - { - Annotation tmp = Annotation.New(myItem, myAnnotationType, rtfText, searchText, config); - if (tmp.IsSavable) - { - Annotation tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Annotation Get(int annotationID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Annotation"); - try - { - Annotation tmp = GetCachedByPrimaryKey(annotationID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(annotationID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Annotation - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Annotation.Get", ex); - } - } - public static Annotation Get(SafeDataReader dr) - { - if (dr.Read()) return new Annotation(dr); - return null; - } - internal Annotation(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int annotationID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Annotation"); - try - { - DataPortal.Delete(new PKCriteria(annotationID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Annotation.Delete", ex); - } - } - public override Annotation Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Annotation"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Annotation"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Annotation"); - try - { - BuildRefreshList(); - Annotation annotation = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(annotation);//Refresh the item in AllList - ProcessRefreshList(); - return annotation; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _AnnotationID; - public int AnnotationID - { get { return _AnnotationID; } } - public PKCriteria(int annotationID) - { - _AnnotationID = annotationID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AnnotationID = NextAnnotationID; - // Database Defaults - _DTS = _AnnotationExtension.DefaultDTS; - _UserID = _AnnotationExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.ReadData", GetHashCode()); - try - { - _AnnotationID = dr.GetInt32("AnnotationID"); - _ItemID = dr.GetInt32("ItemID"); - _TypeID = dr.GetInt32("TypeID"); - _RtfText = dr.GetString("RtfText"); - _SearchText = dr.GetString("SearchText"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Annotation.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAnnotation"; - cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Annotation.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Annotation.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyAnnotationType != null) _MyAnnotationType.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAnnotation"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ItemID", ItemID); - cm.Parameters.AddWithValue("@TypeID", TypeID); - cm.Parameters.AddWithValue("@RtfText", _RtfText); - cm.Parameters.AddWithValue("@SearchText", _SearchText); - 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_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int); - param_AnnotationID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_AnnotationID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _AnnotationID = (int)cm.Parameters["@newAnnotationID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAnnotation"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - cm.Parameters.AddWithValue("@TypeID", myAnnotationType.TypeID); - cm.Parameters.AddWithValue("@RtfText", rtfText); - cm.Parameters.AddWithValue("@SearchText", searchText); - 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_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int); - param_AnnotationID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_AnnotationID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - annotationID = (int)cm.Parameters["@newAnnotationID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Add", ex); - throw new DbCslaException("Annotation.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Annotation.SQLUpdate", GetHashCode()); - try - { - if (_MyAnnotationType != null) _MyAnnotationType.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAnnotation"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); - cm.Parameters.AddWithValue("@ItemID", ItemID); - cm.Parameters.AddWithValue("@TypeID", TypeID); - cm.Parameters.AddWithValue("@RtfText", _RtfText); - cm.Parameters.AddWithValue("@SearchText", _SearchText); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID); - else - _LastChanged = Annotation.Update(cn, ref _AnnotationID, _MyItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int annotationID, Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAnnotation"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AnnotationID", annotationID); - cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - cm.Parameters.AddWithValue("@TypeID", myAnnotationType.TypeID); - cm.Parameters.AddWithValue("@RtfText", rtfText); - cm.Parameters.AddWithValue("@SearchText", searchText); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAnnotation"; - cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAnnotation"; - // Input PK Fields - cm.Parameters.AddWithValue("@AnnotationID", annotationID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Remove", ex); - throw new DbCslaException("Annotation.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int annotationID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(annotationID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Annotation.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _AnnotationID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int annotationID) - { - _AnnotationID = annotationID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsAnnotation"; - cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Execute", ex); - throw new DbCslaException("Annotation.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - AnnotationExtension _AnnotationExtension = new AnnotationExtension(); - [Serializable()] - partial class AnnotationExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class AnnotationConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Annotation) - { - // Return the ToString value - return ((Annotation)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Annotation Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationConverter))] + public partial class Annotation : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshAnnotations = new List(); + private void AddToRefreshList(List refreshAnnotations) + { + if (IsDirty) + refreshAnnotations.Add(this); + } + private void BuildRefreshList() + { + _RefreshAnnotations = new List(); + AddToRefreshList(_RefreshAnnotations); + } + private void ProcessRefreshList() + { + foreach (Annotation tmp in _RefreshAnnotations) + { + AnnotationInfo.Refresh(tmp); + if (tmp._MyAnnotationType != null) AnnotationTypeInfo.Refresh(tmp._MyAnnotationType); + if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Annotation annotation) + { + if (!_CacheList.Contains(annotation)) _CacheList.Add(annotation); // In AddToCache + } + protected static void RemoveFromCache(Annotation annotation) + { + while (_CacheList.Contains(annotation)) _CacheList.Remove(annotation); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Annotation tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString())) + { + _CacheByPrimaryKey[tmp.AnnotationID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.AnnotationID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Annotation tmp in remove) + RemoveFromCache(tmp); + } + protected static Annotation GetCachedByPrimaryKey(int annotationID) + { + ConvertListToDictionary(); + string key = annotationID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAnnotationID = -1; + public static int NextAnnotationID + { + get { return _nextAnnotationID--; } + } + private int _AnnotationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItem != value) + { + _MyItem = value; + PropertyHasChanged(); + } + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; + return _TypeID; + } + } + private AnnotationType _MyAnnotationType; + public AnnotationType MyAnnotationType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID); + return _MyAnnotationType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyAnnotationType != value) + { + _MyAnnotationType = value; + PropertyHasChanged(); + } + } + } + private string _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RtfText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_RtfText != value) + { + _RtfText = value; + PropertyHasChanged(); + } + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SearchText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_SearchText != value) + { + _SearchText = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } + } + // TODO: Replace base Annotation.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Annotation + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Annotation.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Annotation + protected override object GetIdValue() + { + return _AnnotationID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemRequired, "MyItem"); + ValidationRules.AddRule(MyAnnotationTypeRequired, "MyAnnotationType"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _AnnotationExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _AnnotationExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyItemRequired(Annotation target, Csla.Validation.RuleArgs e) + { + if (target._ItemID == 0 && target._MyItem == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyAnnotationTypeRequired(Annotation target, Csla.Validation.RuleArgs e) + { + if (target._TypeID == 0 && target._MyAnnotationType == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(AnnotationID, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowRead(RtfText, ""); + //AuthorizationRules.AllowRead(SearchText, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(TypeID, ""); + //AuthorizationRules.AllowWrite(RtfText, ""); + //AuthorizationRules.AllowWrite(SearchText, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _AnnotationExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _AnnotationExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _AnnotationUnique = 0; + protected static int AnnotationUnique + { get { return ++_AnnotationUnique; } } + private int _MyAnnotationUnique = AnnotationUnique; + public int MyAnnotationUnique + { get { return _MyAnnotationUnique; } } + protected Annotation() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AnnotationID.ToString())) + { + List listAnnotation = _CacheByPrimaryKey[AnnotationID.ToString()]; // Get the list of items + while (listAnnotation.Contains(this)) listAnnotation.Remove(this); // Remove the item from the list + if (listAnnotation.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list + } + } + public static Annotation New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Annotation"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Annotation.New", ex); + } + } + public static Annotation New(Item myItem, AnnotationType myAnnotationType) + { + Annotation tmp = Annotation.New(); + tmp.MyItem = myItem; + tmp.MyAnnotationType = myAnnotationType; + return tmp; + } + public static Annotation New(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID) + { + Annotation tmp = Annotation.New(); + tmp.MyItem = myItem; + tmp.MyAnnotationType = myAnnotationType; + tmp.RtfText = rtfText; + tmp.SearchText = searchText; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Annotation MakeAnnotation(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID) + { + Annotation tmp = Annotation.New(myItem, myAnnotationType, rtfText, searchText, config, dts, userID); + if (tmp.IsSavable) + { + Annotation tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Annotation New(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config) + { + Annotation tmp = Annotation.New(); + tmp.MyItem = myItem; + tmp.MyAnnotationType = myAnnotationType; + tmp.RtfText = rtfText; + tmp.SearchText = searchText; + tmp.Config = config; + return tmp; + } + public static Annotation MakeAnnotation(Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config) + { + Annotation tmp = Annotation.New(myItem, myAnnotationType, rtfText, searchText, config); + if (tmp.IsSavable) + { + Annotation tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Annotation Get(int annotationID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Annotation"); + try + { + Annotation tmp = GetCachedByPrimaryKey(annotationID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(annotationID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Annotation + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Annotation.Get", ex); + } + } + public static Annotation Get(SafeDataReader dr) + { + if (dr.Read()) return new Annotation(dr); + return null; + } + internal Annotation(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int annotationID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Annotation"); + try + { + DataPortal.Delete(new PKCriteria(annotationID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Annotation.Delete", ex); + } + } + public override Annotation Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Annotation"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Annotation"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Annotation"); + try + { + BuildRefreshList(); + Annotation annotation = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(annotation);//Refresh the item in AllList + ProcessRefreshList(); + return annotation; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _AnnotationID; + public int AnnotationID + { get { return _AnnotationID; } } + public PKCriteria(int annotationID) + { + _AnnotationID = annotationID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AnnotationID = NextAnnotationID; + // Database Defaults + _DTS = _AnnotationExtension.DefaultDTS; + _UserID = _AnnotationExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.ReadData", GetHashCode()); + try + { + _AnnotationID = dr.GetInt32("AnnotationID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Annotation.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotation"; + cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Annotation.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Annotation.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyAnnotationType != null) _MyAnnotationType.Update(); + if (_MyItem != null) _MyItem.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAnnotation"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", ItemID); + cm.Parameters.AddWithValue("@TypeID", TypeID); + cm.Parameters.AddWithValue("@RtfText", _RtfText); + cm.Parameters.AddWithValue("@SearchText", _SearchText); + 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_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int); + param_AnnotationID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AnnotationID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AnnotationID = (int)cm.Parameters["@newAnnotationID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAnnotation"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + cm.Parameters.AddWithValue("@TypeID", myAnnotationType.TypeID); + cm.Parameters.AddWithValue("@RtfText", rtfText); + cm.Parameters.AddWithValue("@SearchText", searchText); + 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_AnnotationID = new SqlParameter("@newAnnotationID", SqlDbType.Int); + param_AnnotationID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AnnotationID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + annotationID = (int)cm.Parameters["@newAnnotationID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Add", ex); + throw new DbCslaException("Annotation.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Annotation.SQLUpdate", GetHashCode()); + try + { + if (_MyAnnotationType != null) _MyAnnotationType.Update(); + if (_MyItem != null) _MyItem.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotation"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); + cm.Parameters.AddWithValue("@ItemID", ItemID); + cm.Parameters.AddWithValue("@TypeID", TypeID); + cm.Parameters.AddWithValue("@RtfText", _RtfText); + cm.Parameters.AddWithValue("@SearchText", _SearchText); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Annotation.Add(cn, ref _AnnotationID, _MyItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID); + else + _LastChanged = Annotation.Update(cn, ref _AnnotationID, _MyItem, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int annotationID, Item myItem, AnnotationType myAnnotationType, string rtfText, string searchText, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotation"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AnnotationID", annotationID); + cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + cm.Parameters.AddWithValue("@TypeID", myAnnotationType.TypeID); + cm.Parameters.AddWithValue("@RtfText", rtfText); + cm.Parameters.AddWithValue("@SearchText", searchText); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotation"; + cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotation"; + // Input PK Fields + cm.Parameters.AddWithValue("@AnnotationID", annotationID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.Remove", ex); + throw new DbCslaException("Annotation.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int annotationID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(annotationID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Annotation.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _AnnotationID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int annotationID) + { + _AnnotationID = annotationID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Annotation.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsAnnotation"; + cm.Parameters.AddWithValue("@AnnotationID", _AnnotationID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Annotation.DataPortal_Execute", ex); + throw new DbCslaException("Annotation.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + AnnotationExtension _AnnotationExtension = new AnnotationExtension(); + [Serializable()] + partial class AnnotationExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class AnnotationConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Annotation) + { + // Return the ToString value + return ((Annotation)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationInfo.cs index 8e72df2b..93229620 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationInfo.cs @@ -19,469 +19,459 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void AnnotationInfoEvent(object sender); - /// - /// AnnotationInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AnnotationInfoConverter))] - public partial class AnnotationInfo : ReadOnlyBase, IDisposable - { - public event AnnotationInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AnnotationInfo annotationInfo) - { - if (!_CacheList.Contains(annotationInfo)) _CacheList.Add(annotationInfo); // In AddToCache - } - protected static void RemoveFromCache(AnnotationInfo annotationInfo) - { - while (_CacheList.Contains(annotationInfo)) _CacheList.Remove(annotationInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (AnnotationInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString())) - { - _CacheByPrimaryKey[tmp.AnnotationID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.AnnotationID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (AnnotationInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(AnnotationInfoList lst) - { - foreach (AnnotationInfo item in lst) AddToCache(item); - } - protected static AnnotationInfo GetCachedByPrimaryKey(int annotationID) - { - ConvertListToDictionary(); - string key = annotationID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Annotation _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _AnnotationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AnnotationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationID", true); - return _AnnotationID; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private ItemInfo _MyItem; - public ItemInfo MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID); - return _MyItem; - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; - return _TypeID; - } - } - private AnnotationTypeInfo _MyAnnotationType; - public AnnotationTypeInfo MyAnnotationType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAnnotationType", true); - if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationTypeInfo.Get(_TypeID); - return _MyAnnotationType; - } - } - private string _RtfText = string.Empty; - public string RtfText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RtfText", true); - return _RtfText; - } - } - private string _SearchText = string.Empty; - public string SearchText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SearchText", true); - return _SearchText; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // TODO: Replace base AnnotationInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AnnotationInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check AnnotationInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AnnotationInfo - protected override object GetIdValue() - { - return _AnnotationID; - } - #endregion - #region Factory Methods - private static int _AnnotationInfoUnique = 0; - private static int AnnotationInfoUnique - { get { return ++_AnnotationInfoUnique; } } - private int _MyAnnotationInfoUnique = AnnotationInfoUnique; - public int MyAnnotationInfoUnique - { get { return _MyAnnotationInfoUnique; } } - protected AnnotationInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AnnotationID.ToString())) return; - List listAnnotationInfo = _CacheByPrimaryKey[AnnotationID.ToString()]; // Get the list of items - while (listAnnotationInfo.Contains(this)) listAnnotationInfo.Remove(this); // Remove the item from the list - if (listAnnotationInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list - } - public virtual Annotation Get() - { - return _Editable = Annotation.Get(_AnnotationID); - } - public static void Refresh(Annotation tmp) - { - string key = tmp.AnnotationID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Annotation tmp) - { - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) MyItem.RefreshItemAnnotations(); // 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.RefreshItemAnnotations(); // Update List for new value - if (_TypeID != tmp.TypeID) - { - if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value - _TypeID = tmp.TypeID; // Update the value - } - _MyAnnotationType = null; // Reset list so that the next line gets a new list - if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for new value - _RtfText = tmp.RtfText; - _SearchText = tmp.SearchText; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _AnnotationInfoExtension.Refresh(this); - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - if(_MyAnnotationType != null) - { - _MyAnnotationType.Dispose();// Dispose related value - _MyAnnotationType = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(AnnotationTypeAnnotation tmp) - { - string key = tmp.AnnotationID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(AnnotationTypeAnnotation tmp) - { - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) MyItem.RefreshItemAnnotations(); // 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.RefreshItemAnnotations(); // Update List for new value - _RtfText = tmp.RtfText; - _SearchText = tmp.SearchText; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _AnnotationInfoExtension.Refresh(this); - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - if(_MyAnnotationType != null) - { - _MyAnnotationType.Dispose();// Dispose related value - _MyAnnotationType = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ItemAnnotation tmp) - { - string key = tmp.AnnotationID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemAnnotation tmp) - { - if (_TypeID != tmp.TypeID) - { - if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value - _TypeID = tmp.TypeID; // Update the value - } - _MyAnnotationType = null; // Reset list so that the next line gets a new list - if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for new value - _RtfText = tmp.RtfText; - _SearchText = tmp.SearchText; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _AnnotationInfoExtension.Refresh(this); - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - if(_MyAnnotationType != null) - { - _MyAnnotationType.Dispose();// Dispose related value - _MyAnnotationType = null;// Reset related value - } - OnChange();// raise an event - } - public static AnnotationInfo Get(int annotationID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Annotation"); - try - { - AnnotationInfo tmp = GetCachedByPrimaryKey(annotationID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(annotationID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AnnotationInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal AnnotationInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationInfo.Constructor", ex); - throw new DbCslaException("AnnotationInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _AnnotationID; - public int AnnotationID - { get { return _AnnotationID; } } - public PKCriteria(int annotationID) - { - _AnnotationID = annotationID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.ReadData", GetHashCode()); - try - { - _AnnotationID = dr.GetInt32("AnnotationID"); - _ItemID = dr.GetInt32("ItemID"); - _TypeID = dr.GetInt32("TypeID"); - _RtfText = dr.GetString("RtfText"); - _SearchText = dr.GetString("SearchText"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAnnotation"; - cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - AnnotationInfoExtension _AnnotationInfoExtension = new AnnotationInfoExtension(); - [Serializable()] - partial class AnnotationInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(AnnotationInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class AnnotationInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AnnotationInfo) - { - // Return the ToString value - return ((AnnotationInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void AnnotationInfoEvent(object sender); + /// + /// AnnotationInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationInfoConverter))] + public partial class AnnotationInfo : ReadOnlyBase, IDisposable + { + public event AnnotationInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AnnotationInfo annotationInfo) + { + if (!_CacheList.Contains(annotationInfo)) _CacheList.Add(annotationInfo); // In AddToCache + } + protected static void RemoveFromCache(AnnotationInfo annotationInfo) + { + while (_CacheList.Contains(annotationInfo)) _CacheList.Remove(annotationInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AnnotationInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.AnnotationID.ToString())) + { + _CacheByPrimaryKey[tmp.AnnotationID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.AnnotationID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (AnnotationInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(AnnotationInfoList lst) + { + foreach (AnnotationInfo item in lst) AddToCache(item); + } + protected static AnnotationInfo GetCachedByPrimaryKey(int annotationID) + { + ConvertListToDictionary(); + string key = annotationID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Annotation _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _AnnotationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationID; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private ItemInfo _MyItem; + public ItemInfo MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID); + return _MyItem; + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; + return _TypeID; + } + } + private AnnotationTypeInfo _MyAnnotationType; + public AnnotationTypeInfo MyAnnotationType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationTypeInfo.Get(_TypeID); + return _MyAnnotationType; + } + } + private string _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RtfText; + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SearchText; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // TODO: Replace base AnnotationInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check AnnotationInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AnnotationInfo + protected override object GetIdValue() + { + return _AnnotationID; + } + #endregion + #region Factory Methods + private static int _AnnotationInfoUnique = 0; + private static int AnnotationInfoUnique + { get { return ++_AnnotationInfoUnique; } } + private int _MyAnnotationInfoUnique = AnnotationInfoUnique; + public int MyAnnotationInfoUnique + { get { return _MyAnnotationInfoUnique; } } + protected AnnotationInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AnnotationID.ToString())) return; + List listAnnotationInfo = _CacheByPrimaryKey[AnnotationID.ToString()]; // Get the list of items + while (listAnnotationInfo.Contains(this)) listAnnotationInfo.Remove(this); // Remove the item from the list + if (listAnnotationInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AnnotationID.ToString()); // remove the list + } + public virtual Annotation Get() + { + return _Editable = Annotation.Get(_AnnotationID); + } + public static void Refresh(Annotation tmp) + { + string key = tmp.AnnotationID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Annotation tmp) + { + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) MyItem.RefreshItemAnnotations(); // 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.RefreshItemAnnotations(); // Update List for new value + if (_TypeID != tmp.TypeID) + { + if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value + _TypeID = tmp.TypeID; // Update the value + } + _MyAnnotationType = null; // Reset list so that the next line gets a new list + if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for new value + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AnnotationInfoExtension.Refresh(this); + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + if (_MyAnnotationType != null) + { + _MyAnnotationType.Dispose();// Dispose related value + _MyAnnotationType = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(AnnotationTypeAnnotation tmp) + { + string key = tmp.AnnotationID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(AnnotationTypeAnnotation tmp) + { + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) MyItem.RefreshItemAnnotations(); // 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.RefreshItemAnnotations(); // Update List for new value + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AnnotationInfoExtension.Refresh(this); + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + if (_MyAnnotationType != null) + { + _MyAnnotationType.Dispose();// Dispose related value + _MyAnnotationType = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ItemAnnotation tmp) + { + string key = tmp.AnnotationID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AnnotationInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemAnnotation tmp) + { + if (_TypeID != tmp.TypeID) + { + if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for old value + _TypeID = tmp.TypeID; // Update the value + } + _MyAnnotationType = null; // Reset list so that the next line gets a new list + if (MyAnnotationType != null) MyAnnotationType.RefreshAnnotationTypeAnnotations(); // Update List for new value + _RtfText = tmp.RtfText; + _SearchText = tmp.SearchText; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AnnotationInfoExtension.Refresh(this); + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + if (_MyAnnotationType != null) + { + _MyAnnotationType.Dispose();// Dispose related value + _MyAnnotationType = null;// Reset related value + } + OnChange();// raise an event + } + public static AnnotationInfo Get(int annotationID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Annotation"); + try + { + AnnotationInfo tmp = GetCachedByPrimaryKey(annotationID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(annotationID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal AnnotationInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationInfo.Constructor", ex); + throw new DbCslaException("AnnotationInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _AnnotationID; + public int AnnotationID + { get { return _AnnotationID; } } + public PKCriteria(int annotationID) + { + _AnnotationID = annotationID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.ReadData", GetHashCode()); + try + { + _AnnotationID = dr.GetInt32("AnnotationID"); + _ItemID = dr.GetInt32("ItemID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotation"; + cm.Parameters.AddWithValue("@AnnotationID", criteria.AnnotationID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + AnnotationInfoExtension _AnnotationInfoExtension = new AnnotationInfoExtension(); + [Serializable()] + partial class AnnotationInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(AnnotationInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class AnnotationInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationInfo) + { + // Return the ToString value + return ((AnnotationInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationType.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationType.cs index ece9a2e5..adb76aa2 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationType.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationType.cs @@ -20,1094 +20,1083 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// AnnotationType Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AnnotationTypeConverter))] - public partial class AnnotationType : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshAnnotationTypes = new List(); - private List _RefreshAnnotationTypeAnnotations = new List(); - private void AddToRefreshList(List refreshAnnotationTypes, List refreshAnnotationTypeAnnotations) - { - if (IsDirty) - refreshAnnotationTypes.Add(this); - if (_AnnotationTypeAnnotations != null && _AnnotationTypeAnnotations.IsDirty) - { - foreach (AnnotationTypeAnnotation tmp in _AnnotationTypeAnnotations) - { - if (tmp.IsDirty) refreshAnnotationTypeAnnotations.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshAnnotationTypes = new List(); - _RefreshAnnotationTypeAnnotations = new List(); - AddToRefreshList(_RefreshAnnotationTypes, _RefreshAnnotationTypeAnnotations); - } - private void ProcessRefreshList() - { - foreach (AnnotationType tmp in _RefreshAnnotationTypes) - { - AnnotationTypeInfo.Refresh(tmp); - } - foreach (AnnotationTypeAnnotation tmp in _RefreshAnnotationTypeAnnotations) - { - AnnotationInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AnnotationType annotationType) - { - if (!_CacheList.Contains(annotationType)) _CacheList.Add(annotationType); // In AddToCache - } - protected static void RemoveFromCache(AnnotationType annotationType) - { - while (_CacheList.Contains(annotationType)) _CacheList.Remove(annotationType); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByName = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (AnnotationType tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.TypeID.ToString())) - { - _CacheByPrimaryKey[tmp.TypeID.ToString()] = new List(); // Add new list for PrimaryKey - _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name - } - _CacheByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list - _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index - remove.Add(tmp); - } - foreach (AnnotationType tmp in remove) - RemoveFromCache(tmp); - } - protected static AnnotationType GetCachedByPrimaryKey(int typeID) - { - ConvertListToDictionary(); - string key = typeID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static AnnotationType GetCachedByName(string name) - { - ConvertListToDictionary(); - string key = name.ToString(); - if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextTypeID = -1; - public static int NextTypeID - { - get { return _nextTypeID--; } - } - private int _TypeID; - [System.ComponentModel.DataObjectField(true, true)] - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - return _TypeID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _AnnotationTypeAnnotationCount = 0; - /// - /// Count of AnnotationTypeAnnotations for this AnnotationType - /// - public int AnnotationTypeAnnotationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationTypeAnnotationCount", true); - return _AnnotationTypeAnnotationCount; - } - } - private AnnotationTypeAnnotations _AnnotationTypeAnnotations = null; - /// - /// Related Field - /// - [TypeConverter(typeof(AnnotationTypeAnnotationsConverter))] - public AnnotationTypeAnnotations AnnotationTypeAnnotations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationTypeAnnotations", true); - if (_AnnotationTypeAnnotationCount > 0 && _AnnotationTypeAnnotations == null) - _AnnotationTypeAnnotations = AnnotationTypeAnnotations.GetByTypeID(TypeID); - else if (_AnnotationTypeAnnotations == null) - _AnnotationTypeAnnotations = AnnotationTypeAnnotations.New(); - return _AnnotationTypeAnnotations; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_AnnotationTypeAnnotations == null ? false : _AnnotationTypeAnnotations.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_AnnotationTypeAnnotations == null ? true : _AnnotationTypeAnnotations.IsValid); } - } - // TODO: Replace base AnnotationType.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AnnotationType - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check AnnotationType.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AnnotationType - protected override object GetIdValue() - { - return _TypeID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_AnnotationTypeAnnotations != null && (hasBrokenRules = _AnnotationTypeAnnotations.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _AnnotationTypeExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _AnnotationTypeExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(TypeID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _AnnotationTypeExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _AnnotationTypeExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _AnnotationTypeAnnotationCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _AnnotationTypeUnique = 0; - protected static int AnnotationTypeUnique - { get { return ++_AnnotationTypeUnique; } } - private int _MyAnnotationTypeUnique = AnnotationTypeUnique; - public int MyAnnotationTypeUnique - { get { return _MyAnnotationTypeUnique; } } - protected AnnotationType() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(TypeID.ToString())) - { - List listAnnotationType = _CacheByPrimaryKey[TypeID.ToString()]; // Get the list of items - while (listAnnotationType.Contains(this)) listAnnotationType.Remove(this); // Remove the item from the list - if (listAnnotationType.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByName.Keys) - if (_CacheByName[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listAnnotationType = _CacheByName[myKey]; // Get the list of items - listAnnotationType.Remove(this); // Remove the item from the list - if (listAnnotationType.Count == 0) //If there are no items left in the list - _CacheByName.Remove(myKey); // remove the list - } - } - public static AnnotationType New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a AnnotationType"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationType.New", ex); - } - } - public static AnnotationType New(string name) - { - AnnotationType tmp = AnnotationType.New(); - tmp.Name = name; - return tmp; - } - public static AnnotationType New(string name, string config, DateTime dts, string userID) - { - AnnotationType tmp = AnnotationType.New(); - tmp.Name = name; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static AnnotationType MakeAnnotationType(string name, string config, DateTime dts, string userID) - { - AnnotationType tmp = AnnotationType.New(name, config, dts, userID); - if (tmp.IsSavable) - { - AnnotationType tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static AnnotationType New(string name, string config) - { - AnnotationType tmp = AnnotationType.New(); - tmp.Name = name; - tmp.Config = config; - return tmp; - } - public static AnnotationType MakeAnnotationType(string name, string config) - { - AnnotationType tmp = AnnotationType.New(name, config); - if (tmp.IsSavable) - { - AnnotationType tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static AnnotationType Get(int typeID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); - try - { - AnnotationType tmp = GetCachedByPrimaryKey(typeID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(typeID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AnnotationType - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationType.Get", ex); - } - } - public static AnnotationType GetByName(string name) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); - try - { - AnnotationType tmp = GetCachedByName(name); - if (tmp == null) - { - tmp = DataPortal.Fetch(new NameCriteria(name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AnnotationType - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationType.GetByName", ex); - } - } - public static AnnotationType Get(SafeDataReader dr) - { - if (dr.Read()) return new AnnotationType(dr); - return null; - } - internal AnnotationType(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int typeID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a AnnotationType"); - try - { - DataPortal.Delete(new PKCriteria(typeID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationType.Delete", ex); - } - } - public override AnnotationType Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a AnnotationType"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a AnnotationType"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a AnnotationType"); - try - { - BuildRefreshList(); - AnnotationType annotationType = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(annotationType);//Refresh the item in AllList - ProcessRefreshList(); - return annotationType; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _TypeID; - public int TypeID - { get { return _TypeID; } } - public PKCriteria(int typeID) - { - _TypeID = typeID; - } - } - [Serializable()] - private class NameCriteria - { - private string _Name; - public string Name - { get { return _Name; } } - public NameCriteria(string name) - { - _Name = name; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _TypeID = NextTypeID; - // Database Defaults - _DTS = _AnnotationTypeExtension.DefaultDTS; - _UserID = _AnnotationTypeExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.ReadData", GetHashCode()); - try - { - _TypeID = dr.GetInt32("TypeID"); - _Name = dr.GetString("Name"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _AnnotationTypeAnnotationCount = dr.GetInt32("AnnotationCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationType.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAnnotationType"; - cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _AnnotationTypeAnnotations = AnnotationTypeAnnotations.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationType.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAnnotationTypeByName"; - cm.Parameters.AddWithValue("@Name", criteria.Name); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationType.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationType.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAnnotationType"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", _Name); - 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_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int); - param_TypeID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_TypeID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _TypeID = (int)cm.Parameters["@newTypeID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAnnotationType"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", name); - 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_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int); - param_TypeID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_TypeID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - typeID = (int)cm.Parameters["@newTypeID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.Add", ex); - throw new DbCslaException("AnnotationType.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAnnotationType"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@TypeID", _TypeID); - cm.Parameters.AddWithValue("@Name", _Name); - 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); - // TODO: 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 (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = AnnotationType.Add(cn, ref _TypeID, _Name, _Config, _DTS, _UserID); - else - _LastChanged = AnnotationType.Update(cn, ref _TypeID, _Name, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_AnnotationTypeAnnotations != null) _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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAnnotationType"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TypeID", typeID); - cm.Parameters.AddWithValue("@Name", name); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAnnotationType"; - cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAnnotationType"; - // Input PK Fields - cm.Parameters.AddWithValue("@TypeID", typeID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.Remove", ex); - throw new DbCslaException("AnnotationType.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int typeID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(typeID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationType.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _TypeID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int typeID) - { - _TypeID = typeID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsAnnotationType"; - cm.Parameters.AddWithValue("@TypeID", _TypeID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Execute", ex); - throw new DbCslaException("AnnotationType.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - AnnotationTypeExtension _AnnotationTypeExtension = new AnnotationTypeExtension(); - [Serializable()] - partial class AnnotationTypeExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class AnnotationTypeConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AnnotationType) - { - // Return the ToString value - return ((AnnotationType)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// AnnotationType Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationTypeConverter))] + public partial class AnnotationType : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshAnnotationTypes = new List(); + private List _RefreshAnnotationTypeAnnotations = new List(); + private void AddToRefreshList(List refreshAnnotationTypes, List refreshAnnotationTypeAnnotations) + { + if (IsDirty) + refreshAnnotationTypes.Add(this); + if (_AnnotationTypeAnnotations != null && _AnnotationTypeAnnotations.IsDirty) + { + foreach (AnnotationTypeAnnotation tmp in _AnnotationTypeAnnotations) + { + if (tmp.IsDirty) refreshAnnotationTypeAnnotations.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshAnnotationTypes = new List(); + _RefreshAnnotationTypeAnnotations = new List(); + AddToRefreshList(_RefreshAnnotationTypes, _RefreshAnnotationTypeAnnotations); + } + private void ProcessRefreshList() + { + foreach (AnnotationType tmp in _RefreshAnnotationTypes) + { + AnnotationTypeInfo.Refresh(tmp); + } + foreach (AnnotationTypeAnnotation tmp in _RefreshAnnotationTypeAnnotations) + { + AnnotationInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AnnotationType annotationType) + { + if (!_CacheList.Contains(annotationType)) _CacheList.Add(annotationType); // In AddToCache + } + protected static void RemoveFromCache(AnnotationType annotationType) + { + while (_CacheList.Contains(annotationType)) _CacheList.Remove(annotationType); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByName = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AnnotationType tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.TypeID.ToString())) + { + _CacheByPrimaryKey[tmp.TypeID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name + } + _CacheByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index + remove.Add(tmp); + } + foreach (AnnotationType tmp in remove) + RemoveFromCache(tmp); + } + protected static AnnotationType GetCachedByPrimaryKey(int typeID) + { + ConvertListToDictionary(); + string key = typeID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static AnnotationType GetCachedByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextTypeID = -1; + public static int NextTypeID + { + get { return _nextTypeID--; } + } + private int _TypeID; + [System.ComponentModel.DataObjectField(true, true)] + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TypeID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _AnnotationTypeAnnotationCount = 0; + /// + /// Count of AnnotationTypeAnnotations for this AnnotationType + /// + public int AnnotationTypeAnnotationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationTypeAnnotationCount; + } + } + private AnnotationTypeAnnotations _AnnotationTypeAnnotations = null; + /// + /// Related Field + /// + [TypeConverter(typeof(AnnotationTypeAnnotationsConverter))] + public AnnotationTypeAnnotations AnnotationTypeAnnotations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_AnnotationTypeAnnotationCount > 0 && _AnnotationTypeAnnotations == null) + _AnnotationTypeAnnotations = AnnotationTypeAnnotations.GetByTypeID(TypeID); + else if (_AnnotationTypeAnnotations == null) + _AnnotationTypeAnnotations = AnnotationTypeAnnotations.New(); + return _AnnotationTypeAnnotations; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_AnnotationTypeAnnotations == null ? false : _AnnotationTypeAnnotations.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_AnnotationTypeAnnotations == null ? true : _AnnotationTypeAnnotations.IsValid); } + } + // TODO: Replace base AnnotationType.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationType + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check AnnotationType.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AnnotationType + protected override object GetIdValue() + { + return _TypeID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_AnnotationTypeAnnotations != null && (hasBrokenRules = _AnnotationTypeAnnotations.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _AnnotationTypeExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _AnnotationTypeExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _AnnotationTypeExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _AnnotationTypeExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _AnnotationTypeAnnotationCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _AnnotationTypeUnique = 0; + protected static int AnnotationTypeUnique + { get { return ++_AnnotationTypeUnique; } } + private int _MyAnnotationTypeUnique = AnnotationTypeUnique; + public int MyAnnotationTypeUnique + { get { return _MyAnnotationTypeUnique; } } + protected AnnotationType() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(TypeID.ToString())) + { + List listAnnotationType = _CacheByPrimaryKey[TypeID.ToString()]; // Get the list of items + while (listAnnotationType.Contains(this)) listAnnotationType.Remove(this); // Remove the item from the list + if (listAnnotationType.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByName.Keys) + if (_CacheByName[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listAnnotationType = _CacheByName[myKey]; // Get the list of items + listAnnotationType.Remove(this); // Remove the item from the list + if (listAnnotationType.Count == 0) //If there are no items left in the list + _CacheByName.Remove(myKey); // remove the list + } + } + public static AnnotationType New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a AnnotationType"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationType.New", ex); + } + } + public static AnnotationType New(string name) + { + AnnotationType tmp = AnnotationType.New(); + tmp.Name = name; + return tmp; + } + public static AnnotationType New(string name, string config, DateTime dts, string userID) + { + AnnotationType tmp = AnnotationType.New(); + tmp.Name = name; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static AnnotationType MakeAnnotationType(string name, string config, DateTime dts, string userID) + { + AnnotationType tmp = AnnotationType.New(name, config, dts, userID); + if (tmp.IsSavable) + { + AnnotationType tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static AnnotationType New(string name, string config) + { + AnnotationType tmp = AnnotationType.New(); + tmp.Name = name; + tmp.Config = config; + return tmp; + } + public static AnnotationType MakeAnnotationType(string name, string config) + { + AnnotationType tmp = AnnotationType.New(name, config); + if (tmp.IsSavable) + { + AnnotationType tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static AnnotationType Get(int typeID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); + try + { + AnnotationType tmp = GetCachedByPrimaryKey(typeID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(typeID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationType + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationType.Get", ex); + } + } + public static AnnotationType GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); + try + { + AnnotationType tmp = GetCachedByName(name); + if (tmp == null) + { + tmp = DataPortal.Fetch(new NameCriteria(name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationType + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationType.GetByName", ex); + } + } + public static AnnotationType Get(SafeDataReader dr) + { + if (dr.Read()) return new AnnotationType(dr); + return null; + } + internal AnnotationType(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int typeID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a AnnotationType"); + try + { + DataPortal.Delete(new PKCriteria(typeID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationType.Delete", ex); + } + } + public override AnnotationType Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a AnnotationType"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a AnnotationType"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a AnnotationType"); + try + { + BuildRefreshList(); + AnnotationType annotationType = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(annotationType);//Refresh the item in AllList + ProcessRefreshList(); + return annotationType; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _TypeID; + public int TypeID + { get { return _TypeID; } } + public PKCriteria(int typeID) + { + _TypeID = typeID; + } + } + [Serializable()] + private class NameCriteria + { + private string _Name; + public string Name + { get { return _Name; } } + public NameCriteria(string name) + { + _Name = name; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _TypeID = NextTypeID; + // Database Defaults + _DTS = _AnnotationTypeExtension.DefaultDTS; + _UserID = _AnnotationTypeExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.ReadData", GetHashCode()); + try + { + _TypeID = dr.GetInt32("TypeID"); + _Name = dr.GetString("Name"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _AnnotationTypeAnnotationCount = dr.GetInt32("AnnotationCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationType.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationType"; + cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _AnnotationTypeAnnotations = AnnotationTypeAnnotations.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationType.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationTypeByName"; + cm.Parameters.AddWithValue("@Name", criteria.Name); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationType.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationType.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAnnotationType"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + 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_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int); + param_TypeID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_TypeID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _TypeID = (int)cm.Parameters["@newTypeID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAnnotationType"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", name); + 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_TypeID = new SqlParameter("@newTypeID", SqlDbType.Int); + param_TypeID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_TypeID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + typeID = (int)cm.Parameters["@newTypeID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.Add", ex); + throw new DbCslaException("AnnotationType.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotationType"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@TypeID", _TypeID); + cm.Parameters.AddWithValue("@Name", _Name); + 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); + // TODO: 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 (_AnnotationTypeAnnotations != null) _AnnotationTypeAnnotations.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = AnnotationType.Add(cn, ref _TypeID, _Name, _Config, _DTS, _UserID); + else + _LastChanged = AnnotationType.Update(cn, ref _TypeID, _Name, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_AnnotationTypeAnnotations != null) _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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAnnotationType"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TypeID", typeID); + cm.Parameters.AddWithValue("@Name", name); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotationType"; + cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAnnotationType"; + // Input PK Fields + cm.Parameters.AddWithValue("@TypeID", typeID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.Remove", ex); + throw new DbCslaException("AnnotationType.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int typeID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(typeID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationType.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _TypeID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int typeID) + { + _TypeID = typeID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationType.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsAnnotationType"; + cm.Parameters.AddWithValue("@TypeID", _TypeID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationType.DataPortal_Execute", ex); + throw new DbCslaException("AnnotationType.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + AnnotationTypeExtension _AnnotationTypeExtension = new AnnotationTypeExtension(); + [Serializable()] + partial class AnnotationTypeExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class AnnotationTypeConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationType) + { + // Return the ToString value + return ((AnnotationType)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeAnnotation.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeAnnotation.cs index 29e65140..4a9d793c 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeAnnotation.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeAnnotation.cs @@ -19,509 +19,490 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// AnnotationTypeAnnotation Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AnnotationTypeAnnotationConverter))] - public partial class AnnotationTypeAnnotation : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _AnnotationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AnnotationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationID", true); - if (_MyAnnotation != null) _AnnotationID = _MyAnnotation.AnnotationID; - return _AnnotationID; - } - } - private Annotation _MyAnnotation; - [System.ComponentModel.DataObjectField(true, true)] - public Annotation MyAnnotation - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAnnotation", true); - if (_MyAnnotation == null && _AnnotationID != 0) _MyAnnotation = Annotation.Get(_AnnotationID); - return _MyAnnotation; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if (_MyItem != value) - { - _MyItem = value; - PropertyHasChanged(); - } - } - } - private string _RtfText = string.Empty; - public string RtfText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RtfText", true); - return _RtfText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("RtfText", true); - if (value == null) value = string.Empty; - if (_RtfText != value) - { - _RtfText = value; - PropertyHasChanged(); - } - } - } - private string _SearchText = string.Empty; - public string SearchText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SearchText", true); - return _SearchText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SearchText", true); - if (value == null) value = string.Empty; - if (_SearchText != value) - { - _SearchText = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int? _Item_PreviousID; - public int? Item_PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_PreviousID", true); - return _Item_PreviousID; - } - } - private int _Item_ContentID; - public int Item_ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ContentID", true); - return _Item_ContentID; - } - } - private DateTime _Item_DTS = new DateTime(); - public DateTime Item_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_DTS", true); - return _Item_DTS; - } - } - private string _Item_UserID = string.Empty; - public string Item_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_UserID", true); - return _Item_UserID; - } - } - // TODO: Check AnnotationTypeAnnotation.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AnnotationTypeAnnotation - protected override object GetIdValue() - { - return _AnnotationID; - } - // TODO: Replace base AnnotationTypeAnnotation.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AnnotationTypeAnnotation - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemRequired, "MyItem"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyItemRequired(AnnotationTypeAnnotation target, Csla.Validation.RuleArgs e) - { - if (target._ItemID == 0 && target._MyItem == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AnnotationID, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowRead(RtfText, ""); - //AuthorizationRules.AllowWrite(RtfText, ""); - //AuthorizationRules.AllowRead(SearchText, ""); - //AuthorizationRules.AllowWrite(SearchText, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static AnnotationTypeAnnotation New(Item myItem) - { - return new AnnotationTypeAnnotation(myItem); - } - internal static AnnotationTypeAnnotation Get(SafeDataReader dr) - { - return new AnnotationTypeAnnotation(dr); - } - public AnnotationTypeAnnotation() - { - MarkAsChild(); - _AnnotationID = Annotation.NextAnnotationID; - _DTS = _AnnotationTypeAnnotationExtension.DefaultDTS; - _UserID = _AnnotationTypeAnnotationExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private AnnotationTypeAnnotation(Item myItem) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _AnnotationTypeAnnotationExtension.DefaultDTS; - _UserID = _AnnotationTypeAnnotationExtension.DefaultUserID; - _MyItem = myItem; - ValidationRules.CheckRules(); - } - internal AnnotationTypeAnnotation(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeAnnotation.FetchDR", GetHashCode()); - try - { - _AnnotationID = dr.GetInt32("AnnotationID"); - _ItemID = dr.GetInt32("ItemID"); - _RtfText = dr.GetString("RtfText"); - _SearchText = dr.GetString("SearchText"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Item_PreviousID = (int?)dr.GetValue("Item_PreviousID"); - _Item_ContentID = dr.GetInt32("Item_ContentID"); - _Item_DTS = dr.GetDateTime("Item_DTS"); - _Item_UserID = dr.GetString("Item_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeAnnotation.FetchDR", ex); - throw new DbCslaException("AnnotationTypeAnnotation.Fetch", ex); - } - MarkOld(); - } - internal void Insert(AnnotationType myAnnotationType) - { - // 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); - MarkOld(); - } - internal void Update(AnnotationType myAnnotationType) - { - // 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, myAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(AnnotationType myAnnotationType) - { - // 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"]; - Annotation.Remove(cn, _AnnotationID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - AnnotationTypeAnnotationExtension _AnnotationTypeAnnotationExtension = new AnnotationTypeAnnotationExtension(); - [Serializable()] - partial class AnnotationTypeAnnotationExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class AnnotationTypeAnnotationConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AnnotationTypeAnnotation) - { - // Return the ToString value - return ((AnnotationTypeAnnotation)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// AnnotationTypeAnnotation Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationTypeAnnotationConverter))] + public partial class AnnotationTypeAnnotation : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _AnnotationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotation != null) _AnnotationID = _MyAnnotation.AnnotationID; + return _AnnotationID; + } + } + private Annotation _MyAnnotation; + [System.ComponentModel.DataObjectField(true, true)] + public Annotation MyAnnotation + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotation == null && _AnnotationID != 0) _MyAnnotation = Annotation.Get(_AnnotationID); + return _MyAnnotation; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItem != value) + { + _MyItem = value; + PropertyHasChanged(); + } + } + } + private string _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RtfText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_RtfText != value) + { + _RtfText = value; + PropertyHasChanged(); + } + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SearchText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_SearchText != value) + { + _SearchText = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int? _Item_PreviousID; + public int? Item_PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_PreviousID; + } + } + private int _Item_ContentID; + public int Item_ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ContentID; + } + } + private DateTime _Item_DTS = new DateTime(); + public DateTime Item_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_DTS; + } + } + private string _Item_UserID = string.Empty; + public string Item_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_UserID; + } + } + // TODO: Check AnnotationTypeAnnotation.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AnnotationTypeAnnotation + protected override object GetIdValue() + { + return _AnnotationID; + } + // TODO: Replace base AnnotationTypeAnnotation.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationTypeAnnotation + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemRequired, "MyItem"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyItemRequired(AnnotationTypeAnnotation target, Csla.Validation.RuleArgs e) + { + if (target._ItemID == 0 && target._MyItem == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(AnnotationID, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowRead(RtfText, ""); + //AuthorizationRules.AllowWrite(RtfText, ""); + //AuthorizationRules.AllowRead(SearchText, ""); + //AuthorizationRules.AllowWrite(SearchText, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static AnnotationTypeAnnotation New(Item myItem) + { + return new AnnotationTypeAnnotation(myItem); + } + internal static AnnotationTypeAnnotation Get(SafeDataReader dr) + { + return new AnnotationTypeAnnotation(dr); + } + public AnnotationTypeAnnotation() + { + MarkAsChild(); + _AnnotationID = Annotation.NextAnnotationID; + _DTS = _AnnotationTypeAnnotationExtension.DefaultDTS; + _UserID = _AnnotationTypeAnnotationExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private AnnotationTypeAnnotation(Item myItem) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _AnnotationTypeAnnotationExtension.DefaultDTS; + _UserID = _AnnotationTypeAnnotationExtension.DefaultUserID; + _MyItem = myItem; + ValidationRules.CheckRules(); + } + internal AnnotationTypeAnnotation(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeAnnotation.FetchDR", GetHashCode()); + try + { + _AnnotationID = dr.GetInt32("AnnotationID"); + _ItemID = dr.GetInt32("ItemID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Item_PreviousID = (int?)dr.GetValue("Item_PreviousID"); + _Item_ContentID = dr.GetInt32("Item_ContentID"); + _Item_DTS = dr.GetDateTime("Item_DTS"); + _Item_UserID = dr.GetString("Item_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeAnnotation.FetchDR", ex); + throw new DbCslaException("AnnotationTypeAnnotation.Fetch", ex); + } + MarkOld(); + } + internal void Insert(AnnotationType myAnnotationType) + { + // 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); + MarkOld(); + } + internal void Update(AnnotationType myAnnotationType) + { + // 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, myAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(AnnotationType myAnnotationType) + { + // 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"]; + Annotation.Remove(cn, _AnnotationID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + AnnotationTypeAnnotationExtension _AnnotationTypeAnnotationExtension = new AnnotationTypeAnnotationExtension(); + [Serializable()] + partial class AnnotationTypeAnnotationExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class AnnotationTypeAnnotationConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationTypeAnnotation) + { + // Return the ToString value + return ((AnnotationTypeAnnotation)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeInfo.cs index 65afcb9c..65643f64 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AnnotationTypeInfo.cs @@ -19,353 +19,346 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void AnnotationTypeInfoEvent(object sender); - /// - /// AnnotationTypeInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AnnotationTypeInfoConverter))] - public partial class AnnotationTypeInfo : ReadOnlyBase, IDisposable - { - public event AnnotationTypeInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AnnotationTypeInfo annotationTypeInfo) - { - if (!_CacheList.Contains(annotationTypeInfo)) _CacheList.Add(annotationTypeInfo); // In AddToCache - } - protected static void RemoveFromCache(AnnotationTypeInfo annotationTypeInfo) - { - while (_CacheList.Contains(annotationTypeInfo)) _CacheList.Remove(annotationTypeInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (AnnotationTypeInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.TypeID.ToString())) - { - _CacheByPrimaryKey[tmp.TypeID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (AnnotationTypeInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(AnnotationTypeInfoList lst) - { - foreach (AnnotationTypeInfo item in lst) AddToCache(item); - } - protected static AnnotationTypeInfo GetCachedByPrimaryKey(int typeID) - { - ConvertListToDictionary(); - string key = typeID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected AnnotationType _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _TypeID; - [System.ComponentModel.DataObjectField(true, true)] - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - return _TypeID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _AnnotationTypeAnnotationCount = 0; - /// - /// Count of AnnotationTypeAnnotations for this AnnotationType - /// - public int AnnotationTypeAnnotationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationTypeAnnotationCount", true); - return _AnnotationTypeAnnotationCount; - } - } - private AnnotationInfoList _AnnotationTypeAnnotations = null; - [TypeConverter(typeof(AnnotationInfoListConverter))] - public AnnotationInfoList AnnotationTypeAnnotations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationTypeAnnotations", true); - if (_AnnotationTypeAnnotationCount < 0 || (_AnnotationTypeAnnotationCount > 0 && _AnnotationTypeAnnotations == null)) - _AnnotationTypeAnnotations = AnnotationInfoList.GetByTypeID(_TypeID); - if (_AnnotationTypeAnnotationCount < 0) - _AnnotationTypeAnnotationCount = _AnnotationTypeAnnotations.Count; - return _AnnotationTypeAnnotations; - } - } - public void RefreshAnnotationTypeAnnotations() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_TypeID.ToString())) - foreach (AnnotationTypeInfo tmp in _CacheByPrimaryKey[_TypeID.ToString()]) - tmp._AnnotationTypeAnnotationCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base AnnotationTypeInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AnnotationTypeInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check AnnotationTypeInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AnnotationTypeInfo - protected override object GetIdValue() - { - return _TypeID; - } - #endregion - #region Factory Methods - private static int _AnnotationTypeInfoUnique = 0; - private static int AnnotationTypeInfoUnique - { get { return ++_AnnotationTypeInfoUnique; } } - private int _MyAnnotationTypeInfoUnique = AnnotationTypeInfoUnique; - public int MyAnnotationTypeInfoUnique - { get { return _MyAnnotationTypeInfoUnique; } } - protected AnnotationTypeInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(TypeID.ToString())) return; - List listAnnotationTypeInfo = _CacheByPrimaryKey[TypeID.ToString()]; // Get the list of items - while (listAnnotationTypeInfo.Contains(this)) listAnnotationTypeInfo.Remove(this); // Remove the item from the list - if (listAnnotationTypeInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list - } - public virtual AnnotationType Get() - { - return _Editable = AnnotationType.Get(_TypeID); - } - public static void Refresh(AnnotationType tmp) - { - string key = tmp.TypeID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AnnotationTypeInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(AnnotationType tmp) - { - _Name = tmp.Name; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _AnnotationTypeInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static AnnotationTypeInfo Get(int typeID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); - try - { - AnnotationTypeInfo tmp = GetCachedByPrimaryKey(typeID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(typeID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AnnotationTypeInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AnnotationTypeInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal AnnotationTypeInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeInfo.Constructor", ex); - throw new DbCslaException("AnnotationTypeInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _TypeID; - public int TypeID - { get { return _TypeID; } } - public PKCriteria(int typeID) - { - _TypeID = typeID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.ReadData", GetHashCode()); - try - { - _TypeID = dr.GetInt32("TypeID"); - _Name = dr.GetString("Name"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _AnnotationTypeAnnotationCount = dr.GetInt32("AnnotationCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationTypeInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAnnotationType"; - cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AnnotationTypeInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - AnnotationTypeInfoExtension _AnnotationTypeInfoExtension = new AnnotationTypeInfoExtension(); - [Serializable()] - partial class AnnotationTypeInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(AnnotationTypeInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class AnnotationTypeInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AnnotationTypeInfo) - { - // Return the ToString value - return ((AnnotationTypeInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void AnnotationTypeInfoEvent(object sender); + /// + /// AnnotationTypeInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AnnotationTypeInfoConverter))] + public partial class AnnotationTypeInfo : ReadOnlyBase, IDisposable + { + public event AnnotationTypeInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AnnotationTypeInfo annotationTypeInfo) + { + if (!_CacheList.Contains(annotationTypeInfo)) _CacheList.Add(annotationTypeInfo); // In AddToCache + } + protected static void RemoveFromCache(AnnotationTypeInfo annotationTypeInfo) + { + while (_CacheList.Contains(annotationTypeInfo)) _CacheList.Remove(annotationTypeInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AnnotationTypeInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.TypeID.ToString())) + { + _CacheByPrimaryKey[tmp.TypeID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.TypeID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (AnnotationTypeInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(AnnotationTypeInfoList lst) + { + foreach (AnnotationTypeInfo item in lst) AddToCache(item); + } + protected static AnnotationTypeInfo GetCachedByPrimaryKey(int typeID) + { + ConvertListToDictionary(); + string key = typeID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected AnnotationType _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _TypeID; + [System.ComponentModel.DataObjectField(true, true)] + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TypeID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _AnnotationTypeAnnotationCount = 0; + /// + /// Count of AnnotationTypeAnnotations for this AnnotationType + /// + public int AnnotationTypeAnnotationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationTypeAnnotationCount; + } + } + private AnnotationInfoList _AnnotationTypeAnnotations = null; + [TypeConverter(typeof(AnnotationInfoListConverter))] + public AnnotationInfoList AnnotationTypeAnnotations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_AnnotationTypeAnnotationCount < 0 || (_AnnotationTypeAnnotationCount > 0 && _AnnotationTypeAnnotations == null)) + _AnnotationTypeAnnotations = AnnotationInfoList.GetByTypeID(_TypeID); + if (_AnnotationTypeAnnotationCount < 0) + _AnnotationTypeAnnotationCount = _AnnotationTypeAnnotations.Count; + return _AnnotationTypeAnnotations; + } + } + public void RefreshAnnotationTypeAnnotations() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_TypeID.ToString())) + foreach (AnnotationTypeInfo tmp in _CacheByPrimaryKey[_TypeID.ToString()]) + tmp._AnnotationTypeAnnotationCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base AnnotationTypeInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AnnotationTypeInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check AnnotationTypeInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AnnotationTypeInfo + protected override object GetIdValue() + { + return _TypeID; + } + #endregion + #region Factory Methods + private static int _AnnotationTypeInfoUnique = 0; + private static int AnnotationTypeInfoUnique + { get { return ++_AnnotationTypeInfoUnique; } } + private int _MyAnnotationTypeInfoUnique = AnnotationTypeInfoUnique; + public int MyAnnotationTypeInfoUnique + { get { return _MyAnnotationTypeInfoUnique; } } + protected AnnotationTypeInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(TypeID.ToString())) return; + List listAnnotationTypeInfo = _CacheByPrimaryKey[TypeID.ToString()]; // Get the list of items + while (listAnnotationTypeInfo.Contains(this)) listAnnotationTypeInfo.Remove(this); // Remove the item from the list + if (listAnnotationTypeInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(TypeID.ToString()); // remove the list + } + public virtual AnnotationType Get() + { + return _Editable = AnnotationType.Get(_TypeID); + } + public static void Refresh(AnnotationType tmp) + { + string key = tmp.TypeID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AnnotationTypeInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(AnnotationType tmp) + { + _Name = tmp.Name; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _AnnotationTypeInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static AnnotationTypeInfo Get(int typeID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a AnnotationType"); + try + { + AnnotationTypeInfo tmp = GetCachedByPrimaryKey(typeID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(typeID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AnnotationTypeInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AnnotationTypeInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal AnnotationTypeInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeInfo.Constructor", ex); + throw new DbCslaException("AnnotationTypeInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _TypeID; + public int TypeID + { get { return _TypeID; } } + public PKCriteria(int typeID) + { + _TypeID = typeID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.ReadData", GetHashCode()); + try + { + _TypeID = dr.GetInt32("TypeID"); + _Name = dr.GetString("Name"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _AnnotationTypeAnnotationCount = dr.GetInt32("AnnotationCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationTypeInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AnnotationTypeInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAnnotationType"; + cm.Parameters.AddWithValue("@TypeID", criteria.TypeID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AnnotationTypeInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AnnotationTypeInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + AnnotationTypeInfoExtension _AnnotationTypeInfoExtension = new AnnotationTypeInfoExtension(); + [Serializable()] + partial class AnnotationTypeInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(AnnotationTypeInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class AnnotationTypeInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AnnotationTypeInfo) + { + // Return the ToString value + return ((AnnotationTypeInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Assignment.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Assignment.cs index ac944a23..c62380cd 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Assignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Assignment.cs @@ -20,1148 +20,1130 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Assignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AssignmentConverter))] - public partial class Assignment : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshAssignments = new List(); - private void AddToRefreshList(List refreshAssignments) - { - if (IsDirty) - refreshAssignments.Add(this); - } - private void BuildRefreshList() - { - _RefreshAssignments = new List(); - AddToRefreshList(_RefreshAssignments); - } - private void ProcessRefreshList() - { - foreach (Assignment tmp in _RefreshAssignments) - { - AssignmentInfo.Refresh(tmp); - if (tmp._MyFolder != null) FolderInfo.Refresh(tmp._MyFolder); - if (tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup); - if (tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Assignment assignment) - { - if (!_CacheList.Contains(assignment)) _CacheList.Add(assignment); // In AddToCache - } - protected static void RemoveFromCache(Assignment assignment) - { - while (_CacheList.Contains(assignment)) _CacheList.Remove(assignment); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Assignment tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.AID.ToString())) - { - _CacheByPrimaryKey[tmp.AID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Assignment tmp in remove) - RemoveFromCache(tmp); - } - protected static Assignment GetCachedByPrimaryKey(int aid) - { - ConvertListToDictionary(); - string key = aid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextAID = -1; - public static int NextAID - { - get { return _nextAID--; } - } - private int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - return _AID; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - PropertyHasChanged(); - } - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private Role _MyRole; - public Role MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); - return _MyRole; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRole", true); - if (_MyRole != value) - { - _MyRole = value; - PropertyHasChanged(); - } - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyRole == null ? false : _MyRole.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyRole == null ? true : _MyRole.IsValid); } - } - // TODO: Replace base Assignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Assignment - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Assignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Assignment - protected override object GetIdValue() - { - return _AID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule(MyRoleRequired, "MyRole"); - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _AssignmentExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _AssignmentExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool StartDateValid(Assignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(Assignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyGroupRequired(Assignment target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyRoleRequired(Assignment target, Csla.Validation.RuleArgs e) - { - if (target._RID == 0 && target._MyRole == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyFolderRequired(Assignment target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AID, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowWrite(RID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _AssignmentExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _AssignmentExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _AssignmentUnique = 0; - protected static int AssignmentUnique - { get { return ++_AssignmentUnique; } } - private int _MyAssignmentUnique = AssignmentUnique; - public int MyAssignmentUnique - { get { return _MyAssignmentUnique; } } - protected Assignment() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(AID.ToString())) - { - List listAssignment = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items - while (listAssignment.Contains(this)) listAssignment.Remove(this); // Remove the item from the list - if (listAssignment.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(AID.ToString()); // remove the list - } - } - public static Assignment New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Assignment"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Assignment.New", ex); - } - } - public static Assignment New(Group myGroup, Role myRole, Folder myFolder) - { - Assignment tmp = Assignment.New(); - tmp.MyGroup = myGroup; - tmp.MyRole = myRole; - tmp.MyFolder = myFolder; - return tmp; - } - public static Assignment New(Group myGroup, Role myRole, Folder myFolder, string startDate, string endDate, DateTime dts, string usrID) - { - Assignment tmp = Assignment.New(); - tmp.MyGroup = myGroup; - tmp.MyRole = myRole; - tmp.MyFolder = myFolder; - tmp.StartDate = startDate; - tmp.EndDate = endDate; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Assignment MakeAssignment(Group myGroup, Role myRole, Folder myFolder, string startDate, string endDate, DateTime dts, string usrID) - { - Assignment tmp = Assignment.New(myGroup, myRole, myFolder, startDate, endDate, dts, usrID); - if (tmp.IsSavable) - { - Assignment tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Assignment New(Group myGroup, Role myRole, Folder myFolder, string endDate) - { - Assignment tmp = Assignment.New(); - tmp.MyGroup = myGroup; - tmp.MyRole = myRole; - tmp.MyFolder = myFolder; - tmp.EndDate = endDate; - return tmp; - } - public static Assignment MakeAssignment(Group myGroup, Role myRole, Folder myFolder, string endDate) - { - Assignment tmp = Assignment.New(myGroup, myRole, myFolder, endDate); - if (tmp.IsSavable) - { - Assignment tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Assignment Get(int aid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Assignment"); - try - { - Assignment tmp = GetCachedByPrimaryKey(aid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(aid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Assignment - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Assignment.Get", ex); - } - } - public static Assignment Get(SafeDataReader dr) - { - if (dr.Read()) return new Assignment(dr); - return null; - } - internal Assignment(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int aid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Assignment"); - try - { - DataPortal.Delete(new PKCriteria(aid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Assignment.Delete", ex); - } - } - public override Assignment Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Assignment"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Assignment"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Assignment"); - try - { - BuildRefreshList(); - Assignment assignment = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(assignment);//Refresh the item in AllList - ProcessRefreshList(); - return assignment; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _AID; - public int AID - { get { return _AID; } } - public PKCriteria(int aid) - { - _AID = aid; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _AID = NextAID; - // Database Defaults - _StartDate = _AssignmentExtension.DefaultStartDate; - _DTS = _AssignmentExtension.DefaultDTS; - _UsrID = _AssignmentExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.ReadData", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _GID = dr.GetInt32("GID"); - _RID = dr.GetInt32("RID"); - _FolderID = dr.GetInt32("FolderID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Assignment.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAssignment"; - cm.Parameters.AddWithValue("@AID", criteria.AID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Assignment.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Assignment.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyFolder != null) _MyFolder.Update(); - if (_MyGroup != null) _MyGroup.Update(); - if (_MyRole != null) _MyRole.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAssignment"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@GID", GID); - cm.Parameters.AddWithValue("@RID", RID); - cm.Parameters.AddWithValue("@FolderID", FolderID); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UsrID", _UsrID); - // Output Calculated Columns - SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int); - param_AID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_AID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _AID = (int)cm.Parameters["@newAID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAssignment"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@GID", myGroup.GID); - cm.Parameters.AddWithValue("@RID", myRole.RID); - cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UsrID", usrID); - // Output Calculated Columns - SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int); - param_AID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_AID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - aid = (int)cm.Parameters["@newAID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.Add", ex); - throw new DbCslaException("Assignment.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Assignment.SQLUpdate", GetHashCode()); - try - { - if (_MyFolder != null) _MyFolder.Update(); - if (_MyGroup != null) _MyGroup.Update(); - if (_MyRole != null) _MyRole.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAssignment"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@AID", _AID); - cm.Parameters.AddWithValue("@GID", GID); - cm.Parameters.AddWithValue("@RID", RID); - cm.Parameters.AddWithValue("@FolderID", FolderID); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID); - else - _LastChanged = Assignment.Update(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int aid, Group myGroup, Role myRole, Folder myFolder, SmartDate startDate, SmartDate endDate, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAssignment"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@AID", aid); - cm.Parameters.AddWithValue("@GID", myGroup.GID); - cm.Parameters.AddWithValue("@RID", myRole.RID); - cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAssignment"; - cm.Parameters.AddWithValue("@AID", criteria.AID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAssignment"; - // Input PK Fields - cm.Parameters.AddWithValue("@AID", aid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.Remove", ex); - throw new DbCslaException("Assignment.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int aid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(aid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Assignment.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _AID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int aid) - { - _AID = aid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsAssignment"; - cm.Parameters.AddWithValue("@AID", _AID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Execute", ex); - throw new DbCslaException("Assignment.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - AssignmentExtension _AssignmentExtension = new AssignmentExtension(); - [Serializable()] - partial class AssignmentExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class AssignmentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Assignment) - { - // Return the ToString value - return ((Assignment)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Assignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AssignmentConverter))] + public partial class Assignment : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshAssignments = new List(); + private void AddToRefreshList(List refreshAssignments) + { + if (IsDirty) + refreshAssignments.Add(this); + } + private void BuildRefreshList() + { + _RefreshAssignments = new List(); + AddToRefreshList(_RefreshAssignments); + } + private void ProcessRefreshList() + { + foreach (Assignment tmp in _RefreshAssignments) + { + AssignmentInfo.Refresh(tmp); + if (tmp._MyFolder != null) FolderInfo.Refresh(tmp._MyFolder); + if (tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup); + if (tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Assignment assignment) + { + if (!_CacheList.Contains(assignment)) _CacheList.Add(assignment); // In AddToCache + } + protected static void RemoveFromCache(Assignment assignment) + { + while (_CacheList.Contains(assignment)) _CacheList.Remove(assignment); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Assignment tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.AID.ToString())) + { + _CacheByPrimaryKey[tmp.AID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Assignment tmp in remove) + RemoveFromCache(tmp); + } + protected static Assignment GetCachedByPrimaryKey(int aid) + { + ConvertListToDictionary(); + string key = aid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextAID = -1; + public static int NextAID + { + get { return _nextAID--; } + } + private int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AID; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + PropertyHasChanged(); + } + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private Role _MyRole; + public Role MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); + return _MyRole; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRole != value) + { + _MyRole = value; + PropertyHasChanged(); + } + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyRole == null ? false : _MyRole.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyRole == null ? true : _MyRole.IsValid); } + } + // TODO: Replace base Assignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Assignment + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Assignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Assignment + protected override object GetIdValue() + { + return _AID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule(MyRoleRequired, "MyRole"); + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _AssignmentExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _AssignmentExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool StartDateValid(Assignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(Assignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyGroupRequired(Assignment target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyRoleRequired(Assignment target, Csla.Validation.RuleArgs e) + { + if (target._RID == 0 && target._MyRole == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyFolderRequired(Assignment target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(AID, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowWrite(RID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _AssignmentExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _AssignmentExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _AssignmentUnique = 0; + protected static int AssignmentUnique + { get { return ++_AssignmentUnique; } } + private int _MyAssignmentUnique = AssignmentUnique; + public int MyAssignmentUnique + { get { return _MyAssignmentUnique; } } + protected Assignment() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(AID.ToString())) + { + List listAssignment = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items + while (listAssignment.Contains(this)) listAssignment.Remove(this); // Remove the item from the list + if (listAssignment.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(AID.ToString()); // remove the list + } + } + public static Assignment New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Assignment"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Assignment.New", ex); + } + } + public static Assignment New(Group myGroup, Role myRole, Folder myFolder) + { + Assignment tmp = Assignment.New(); + tmp.MyGroup = myGroup; + tmp.MyRole = myRole; + tmp.MyFolder = myFolder; + return tmp; + } + public static Assignment New(Group myGroup, Role myRole, Folder myFolder, string startDate, string endDate, DateTime dts, string usrID) + { + Assignment tmp = Assignment.New(); + tmp.MyGroup = myGroup; + tmp.MyRole = myRole; + tmp.MyFolder = myFolder; + tmp.StartDate = startDate; + tmp.EndDate = endDate; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Assignment MakeAssignment(Group myGroup, Role myRole, Folder myFolder, string startDate, string endDate, DateTime dts, string usrID) + { + Assignment tmp = Assignment.New(myGroup, myRole, myFolder, startDate, endDate, dts, usrID); + if (tmp.IsSavable) + { + Assignment tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Assignment New(Group myGroup, Role myRole, Folder myFolder, string endDate) + { + Assignment tmp = Assignment.New(); + tmp.MyGroup = myGroup; + tmp.MyRole = myRole; + tmp.MyFolder = myFolder; + tmp.EndDate = endDate; + return tmp; + } + public static Assignment MakeAssignment(Group myGroup, Role myRole, Folder myFolder, string endDate) + { + Assignment tmp = Assignment.New(myGroup, myRole, myFolder, endDate); + if (tmp.IsSavable) + { + Assignment tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Assignment Get(int aid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Assignment"); + try + { + Assignment tmp = GetCachedByPrimaryKey(aid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(aid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Assignment + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Assignment.Get", ex); + } + } + public static Assignment Get(SafeDataReader dr) + { + if (dr.Read()) return new Assignment(dr); + return null; + } + internal Assignment(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int aid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Assignment"); + try + { + DataPortal.Delete(new PKCriteria(aid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Assignment.Delete", ex); + } + } + public override Assignment Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Assignment"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Assignment"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Assignment"); + try + { + BuildRefreshList(); + Assignment assignment = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(assignment);//Refresh the item in AllList + ProcessRefreshList(); + return assignment; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _AID; + public int AID + { get { return _AID; } } + public PKCriteria(int aid) + { + _AID = aid; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _AID = NextAID; + // Database Defaults + _StartDate = _AssignmentExtension.DefaultStartDate; + _DTS = _AssignmentExtension.DefaultDTS; + _UsrID = _AssignmentExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.ReadData", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _GID = dr.GetInt32("GID"); + _RID = dr.GetInt32("RID"); + _FolderID = dr.GetInt32("FolderID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Assignment.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignment"; + cm.Parameters.AddWithValue("@AID", criteria.AID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Assignment.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Assignment.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyFolder != null) _MyFolder.Update(); + if (_MyGroup != null) _MyGroup.Update(); + if (_MyRole != null) _MyRole.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAssignment"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@GID", GID); + cm.Parameters.AddWithValue("@RID", RID); + cm.Parameters.AddWithValue("@FolderID", FolderID); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UsrID", _UsrID); + // Output Calculated Columns + SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int); + param_AID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _AID = (int)cm.Parameters["@newAID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAssignment"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@GID", myGroup.GID); + cm.Parameters.AddWithValue("@RID", myRole.RID); + cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UsrID", usrID); + // Output Calculated Columns + SqlParameter param_AID = new SqlParameter("@newAID", SqlDbType.Int); + param_AID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_AID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + aid = (int)cm.Parameters["@newAID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.Add", ex); + throw new DbCslaException("Assignment.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Assignment.SQLUpdate", GetHashCode()); + try + { + if (_MyFolder != null) _MyFolder.Update(); + if (_MyGroup != null) _MyGroup.Update(); + if (_MyRole != null) _MyRole.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAssignment"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@AID", _AID); + cm.Parameters.AddWithValue("@GID", GID); + cm.Parameters.AddWithValue("@RID", RID); + cm.Parameters.AddWithValue("@FolderID", FolderID); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Assignment.Add(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID); + else + _LastChanged = Assignment.Update(cn, ref _AID, _MyGroup, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int aid, Group myGroup, Role myRole, Folder myFolder, SmartDate startDate, SmartDate endDate, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAssignment"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@AID", aid); + cm.Parameters.AddWithValue("@GID", myGroup.GID); + cm.Parameters.AddWithValue("@RID", myRole.RID); + cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAssignment"; + cm.Parameters.AddWithValue("@AID", criteria.AID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAssignment"; + // Input PK Fields + cm.Parameters.AddWithValue("@AID", aid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.Remove", ex); + throw new DbCslaException("Assignment.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int aid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(aid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Assignment.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _AID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int aid) + { + _AID = aid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Assignment.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsAssignment"; + cm.Parameters.AddWithValue("@AID", _AID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Assignment.DataPortal_Execute", ex); + throw new DbCslaException("Assignment.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + AssignmentExtension _AssignmentExtension = new AssignmentExtension(); + [Serializable()] + partial class AssignmentExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class AssignmentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Assignment) + { + // Return the ToString value + return ((Assignment)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AssignmentInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AssignmentInfo.cs index 2ebb9017..28b4bbd4 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/AssignmentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/AssignmentInfo.cs @@ -19,560 +19,549 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void AssignmentInfoEvent(object sender); - /// - /// AssignmentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(AssignmentInfoConverter))] - public partial class AssignmentInfo : ReadOnlyBase, IDisposable - { - public event AssignmentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(AssignmentInfo assignmentInfo) - { - if (!_CacheList.Contains(assignmentInfo)) _CacheList.Add(assignmentInfo); // In AddToCache - } - protected static void RemoveFromCache(AssignmentInfo assignmentInfo) - { - while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (AssignmentInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.AID.ToString())) - { - _CacheByPrimaryKey[tmp.AID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (AssignmentInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(AssignmentInfoList lst) - { - foreach (AssignmentInfo item in lst) AddToCache(item); - } - protected static AssignmentInfo GetCachedByPrimaryKey(int aid) - { - ConvertListToDictionary(); - string key = aid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Assignment _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - return _AID; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private GroupInfo _MyGroup; - public GroupInfo MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); - return _MyGroup; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private RoleInfo _MyRole; - public RoleInfo MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); - return _MyRole; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private FolderInfo _MyFolder; - public FolderInfo MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); - return _MyFolder; - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - // TODO: Replace base AssignmentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AssignmentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check AssignmentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AssignmentInfo - protected override object GetIdValue() - { - return _AID; - } - #endregion - #region Factory Methods - private static int _AssignmentInfoUnique = 0; - private static int AssignmentInfoUnique - { get { return ++_AssignmentInfoUnique; } } - private int _MyAssignmentInfoUnique = AssignmentInfoUnique; - public int MyAssignmentInfoUnique - { get { return _MyAssignmentInfoUnique; } } - protected AssignmentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(AID.ToString())) return; - List listAssignmentInfo = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items - while (listAssignmentInfo.Contains(this)) listAssignmentInfo.Remove(this); // Remove the item from the list - if (listAssignmentInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(AID.ToString()); // remove the list - } - public virtual Assignment Get() - { - return _Editable = Assignment.Get(_AID); - } - public static void Refresh(Assignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Assignment tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - if(_MyGroup != null) - { - _MyGroup.Dispose();// Dispose related value - _MyGroup = null;// Reset related value - } - if(_MyRole != null) - { - _MyRole.Dispose();// Dispose related value - _MyRole = null;// Reset related value - } - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(FolderAssignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FolderAssignment tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - if(_MyGroup != null) - { - _MyGroup.Dispose();// Dispose related value - _MyGroup = null;// Reset related value - } - if(_MyRole != null) - { - _MyRole.Dispose();// Dispose related value - _MyRole = null;// Reset related value - } - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(GroupAssignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(GroupAssignment tmp) - { - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - if(_MyGroup != null) - { - _MyGroup.Dispose();// Dispose related value - _MyGroup = null;// Reset related value - } - if(_MyRole != null) - { - _MyRole.Dispose();// Dispose related value - _MyRole = null;// Reset related value - } - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(RoleAssignment tmp) - { - string key = tmp.AID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RoleAssignment tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _AssignmentInfoExtension.Refresh(this); - if(_MyGroup != null) - { - _MyGroup.Dispose();// Dispose related value - _MyGroup = null;// Reset related value - } - if(_MyRole != null) - { - _MyRole.Dispose();// Dispose related value - _MyRole = null;// Reset related value - } - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - OnChange();// raise an event - } - public static AssignmentInfo Get(int aid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Assignment"); - try - { - AssignmentInfo tmp = GetCachedByPrimaryKey(aid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(aid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up AssignmentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on AssignmentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal AssignmentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.Constructor", ex); - throw new DbCslaException("AssignmentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _AID; - public int AID - { get { return _AID; } } - public PKCriteria(int aid) - { - _AID = aid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.ReadData", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _GID = dr.GetInt32("GID"); - _RID = dr.GetInt32("RID"); - _FolderID = dr.GetInt32("FolderID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AssignmentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAssignment"; - cm.Parameters.AddWithValue("@AID", criteria.AID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("AssignmentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - AssignmentInfoExtension _AssignmentInfoExtension = new AssignmentInfoExtension(); - [Serializable()] - partial class AssignmentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(AssignmentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class AssignmentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is AssignmentInfo) - { - // Return the ToString value - return ((AssignmentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void AssignmentInfoEvent(object sender); + /// + /// AssignmentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(AssignmentInfoConverter))] + public partial class AssignmentInfo : ReadOnlyBase, IDisposable + { + public event AssignmentInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(AssignmentInfo assignmentInfo) + { + if (!_CacheList.Contains(assignmentInfo)) _CacheList.Add(assignmentInfo); // In AddToCache + } + protected static void RemoveFromCache(AssignmentInfo assignmentInfo) + { + while (_CacheList.Contains(assignmentInfo)) _CacheList.Remove(assignmentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (AssignmentInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.AID.ToString())) + { + _CacheByPrimaryKey[tmp.AID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.AID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (AssignmentInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(AssignmentInfoList lst) + { + foreach (AssignmentInfo item in lst) AddToCache(item); + } + protected static AssignmentInfo GetCachedByPrimaryKey(int aid) + { + ConvertListToDictionary(); + string key = aid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Assignment _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AID; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private GroupInfo _MyGroup; + public GroupInfo MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); + return _MyGroup; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private RoleInfo _MyRole; + public RoleInfo MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); + return _MyRole; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private FolderInfo _MyFolder; + public FolderInfo MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); + return _MyFolder; + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + // TODO: Replace base AssignmentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AssignmentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check AssignmentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AssignmentInfo + protected override object GetIdValue() + { + return _AID; + } + #endregion + #region Factory Methods + private static int _AssignmentInfoUnique = 0; + private static int AssignmentInfoUnique + { get { return ++_AssignmentInfoUnique; } } + private int _MyAssignmentInfoUnique = AssignmentInfoUnique; + public int MyAssignmentInfoUnique + { get { return _MyAssignmentInfoUnique; } } + protected AssignmentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(AID.ToString())) return; + List listAssignmentInfo = _CacheByPrimaryKey[AID.ToString()]; // Get the list of items + while (listAssignmentInfo.Contains(this)) listAssignmentInfo.Remove(this); // Remove the item from the list + if (listAssignmentInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(AID.ToString()); // remove the list + } + public virtual Assignment Get() + { + return _Editable = Assignment.Get(_AID); + } + public static void Refresh(Assignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Assignment tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + if (_MyGroup != null) + { + _MyGroup.Dispose();// Dispose related value + _MyGroup = null;// Reset related value + } + if (_MyRole != null) + { + _MyRole.Dispose();// Dispose related value + _MyRole = null;// Reset related value + } + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(FolderAssignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FolderAssignment tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + if (_MyGroup != null) + { + _MyGroup.Dispose();// Dispose related value + _MyGroup = null;// Reset related value + } + if (_MyRole != null) + { + _MyRole.Dispose();// Dispose related value + _MyRole = null;// Reset related value + } + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(GroupAssignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(GroupAssignment tmp) + { + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRoleAssignments(); // Update List for new value + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + if (_MyGroup != null) + { + _MyGroup.Dispose();// Dispose related value + _MyGroup = null;// Reset related value + } + if (_MyRole != null) + { + _MyRole.Dispose();// Dispose related value + _MyRole = null;// Reset related value + } + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(RoleAssignment tmp) + { + string key = tmp.AID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (AssignmentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RoleAssignment tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupAssignments(); // Update List for new value + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) MyFolder.RefreshFolderAssignments(); // 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.RefreshFolderAssignments(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _AssignmentInfoExtension.Refresh(this); + if (_MyGroup != null) + { + _MyGroup.Dispose();// Dispose related value + _MyGroup = null;// Reset related value + } + if (_MyRole != null) + { + _MyRole.Dispose();// Dispose related value + _MyRole = null;// Reset related value + } + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + OnChange();// raise an event + } + public static AssignmentInfo Get(int aid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Assignment"); + try + { + AssignmentInfo tmp = GetCachedByPrimaryKey(aid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(aid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up AssignmentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on AssignmentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal AssignmentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.Constructor", ex); + throw new DbCslaException("AssignmentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _AID; + public int AID + { get { return _AID; } } + public PKCriteria(int aid) + { + _AID = aid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.ReadData", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _GID = dr.GetInt32("GID"); + _RID = dr.GetInt32("RID"); + _FolderID = dr.GetInt32("FolderID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AssignmentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] AssignmentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignment"; + cm.Parameters.AddWithValue("@AID", criteria.AID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("AssignmentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("AssignmentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + AssignmentInfoExtension _AssignmentInfoExtension = new AssignmentInfoExtension(); + [Serializable()] + partial class AssignmentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(AssignmentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class AssignmentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is AssignmentInfo) + { + // Return the ToString value + return ((AssignmentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Connection.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Connection.cs index b573ada2..5744f913 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Connection.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Connection.cs @@ -20,1188 +20,1171 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Connection Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ConnectionConverter))] - public partial class Connection : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshConnections = new List(); - private List _RefreshConnectionFolders = new List(); - private void AddToRefreshList(List refreshConnections, List refreshConnectionFolders) - { - if (IsDirty) - refreshConnections.Add(this); - if (_ConnectionFolders != null && _ConnectionFolders.IsDirty) - { - foreach (ConnectionFolder tmp in _ConnectionFolders) - { - if (tmp.IsDirty) refreshConnectionFolders.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshConnections = new List(); - _RefreshConnectionFolders = new List(); - AddToRefreshList(_RefreshConnections, _RefreshConnectionFolders); - } - private void ProcessRefreshList() - { - foreach (Connection tmp in _RefreshConnections) - { - ConnectionInfo.Refresh(tmp); - } - foreach (ConnectionFolder tmp in _RefreshConnectionFolders) - { - FolderInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Connection connection) - { - if (!_CacheList.Contains(connection)) _CacheList.Add(connection); // In AddToCache - } - protected static void RemoveFromCache(Connection connection) - { - while (_CacheList.Contains(connection)) _CacheList.Remove(connection); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByName = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Connection tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.DBID.ToString())) - { - _CacheByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey - _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name - } - _CacheByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list - _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index - remove.Add(tmp); - } - foreach (Connection tmp in remove) - RemoveFromCache(tmp); - } - protected static Connection GetCachedByPrimaryKey(int dbid) - { - ConvertListToDictionary(); - string key = dbid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Connection GetCachedByName(string name) - { - ConvertListToDictionary(); - string key = name.ToString(); - if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextDBID = -1; - public static int NextDBID - { - get { return _nextDBID--; } - } - private int _DBID; - [System.ComponentModel.DataObjectField(true, true)] - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - return _DBID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ConnectionString = string.Empty; - public string ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionString", true); - return _ConnectionString; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ConnectionString", true); - if (value == null) value = string.Empty; - if (_ConnectionString != value) - { - _ConnectionString = value; - PropertyHasChanged(); - } - } - } - private int _ServerType; - /// - /// 0 SQL Server - /// - public int ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ServerType", true); - return _ServerType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ServerType", true); - if (_ServerType != value) - { - _ServerType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ConnectionFolderCount = 0; - /// - /// Count of ConnectionFolders for this Connection - /// - public int ConnectionFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolderCount", true); - return _ConnectionFolderCount; - } - } - private ConnectionFolders _ConnectionFolders = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ConnectionFoldersConverter))] - public ConnectionFolders ConnectionFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolders", true); - if (_ConnectionFolderCount > 0 && _ConnectionFolders == null) - _ConnectionFolders = ConnectionFolders.GetByDBID(DBID); - else if (_ConnectionFolders == null) - _ConnectionFolders = ConnectionFolders.New(); - return _ConnectionFolders; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_ConnectionFolders == null ? false : _ConnectionFolders.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ConnectionFolders == null ? true : _ConnectionFolders.IsValid); } - } - // TODO: Replace base Connection.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Connection - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Connection.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Connection - protected override object GetIdValue() - { - return _DBID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ConnectionFolders != null && (hasBrokenRules = _ConnectionFolders.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConnectionString", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ConnectionExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ConnectionExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DBID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ConnectionString, ""); - //AuthorizationRules.AllowRead(ServerType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ConnectionString, ""); - //AuthorizationRules.AllowWrite(ServerType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _ConnectionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ConnectionExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ConnectionFolderCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ConnectionUnique = 0; - protected static int ConnectionUnique - { get { return ++_ConnectionUnique; } } - private int _MyConnectionUnique = ConnectionUnique; - public int MyConnectionUnique - { get { return _MyConnectionUnique; } } - protected Connection() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DBID.ToString())) - { - List listConnection = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items - while (listConnection.Contains(this)) listConnection.Remove(this); // Remove the item from the list - if (listConnection.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByName.Keys) - if (_CacheByName[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listConnection = _CacheByName[myKey]; // Get the list of items - listConnection.Remove(this); // Remove the item from the list - if (listConnection.Count == 0) //If there are no items left in the list - _CacheByName.Remove(myKey); // remove the list - } - } - public static Connection New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Connection"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.New", ex); - } - } - public static Connection New(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) - { - Connection tmp = Connection.New(); - tmp.Name = name; - tmp.Title = title; - tmp.ConnectionString = connectionString; - tmp.ServerType = serverType; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Connection MakeConnection(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) - { - Connection tmp = Connection.New(name, title, connectionString, serverType, config, dts, usrID); - if (tmp.IsSavable) - { - Connection tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Connection New(string name, string title, string connectionString, string config) - { - Connection tmp = Connection.New(); - tmp.Name = name; - tmp.Title = title; - tmp.ConnectionString = connectionString; - tmp.Config = config; - return tmp; - } - public static Connection MakeConnection(string name, string title, string connectionString, string config) - { - Connection tmp = Connection.New(name, title, connectionString, config); - if (tmp.IsSavable) - { - Connection tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Connection Get(int dbid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Connection"); - try - { - Connection tmp = GetCachedByPrimaryKey(dbid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(dbid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Connection - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.Get", ex); - } - } - public static Connection GetByName(string name) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Connection"); - try - { - Connection tmp = GetCachedByName(name); - if (tmp == null) - { - tmp = DataPortal.Fetch(new NameCriteria(name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Connection - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.GetByName", ex); - } - } - public static Connection Get(SafeDataReader dr) - { - if (dr.Read()) return new Connection(dr); - return null; - } - internal Connection(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int dbid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Connection"); - try - { - DataPortal.Delete(new PKCriteria(dbid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.Delete", ex); - } - } - public override Connection Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Connection"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Connection"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Connection"); - try - { - BuildRefreshList(); - Connection connection = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(connection);//Refresh the item in AllList - ProcessRefreshList(); - return connection; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DBID; - public int DBID - { get { return _DBID; } } - public PKCriteria(int dbid) - { - _DBID = dbid; - } - } - [Serializable()] - private class NameCriteria - { - private string _Name; - public string Name - { get { return _Name; } } - public NameCriteria(string name) - { - _Name = name; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _DBID = NextDBID; - // Database Defaults - _ServerType = _ConnectionExtension.DefaultServerType; - _DTS = _ConnectionExtension.DefaultDTS; - _UsrID = _ConnectionExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.ReadData", GetHashCode()); - try - { - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ConnectionString = dr.GetString("ConnectionString"); - _ServerType = dr.GetInt32("ServerType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ConnectionFolderCount = dr.GetInt32("FolderCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getConnection"; - cm.Parameters.AddWithValue("@DBID", criteria.DBID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ConnectionFolders = ConnectionFolders.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getConnectionByName"; - cm.Parameters.AddWithValue("@Name", criteria.Name); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Connection.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addConnection"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); - cm.Parameters.AddWithValue("@ServerType", _ServerType); - 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); - param_DBID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_DBID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _DBID = (int)cm.Parameters["@newDBID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_ConnectionFolders != null) _ConnectionFolders.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addConnection"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - cm.Parameters.AddWithValue("@ConnectionString", connectionString); - cm.Parameters.AddWithValue("@ServerType", serverType); - 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); - param_DBID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_DBID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - dbid = (int)cm.Parameters["@newDBID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Add", ex); - throw new DbCslaException("Connection.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateConnection"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@DBID", _DBID); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); - cm.Parameters.AddWithValue("@ServerType", _ServerType); - 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); - // TODO: 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 (_ConnectionFolders != null) _ConnectionFolders.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Connection.Add(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID); - else - _LastChanged = Connection.Update(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - if (_ConnectionFolders != null) _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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateConnection"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DBID", dbid); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - cm.Parameters.AddWithValue("@ConnectionString", connectionString); - cm.Parameters.AddWithValue("@ServerType", serverType); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteConnection"; - cm.Parameters.AddWithValue("@DBID", criteria.DBID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteConnection"; - // Input PK Fields - cm.Parameters.AddWithValue("@DBID", dbid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Remove", ex); - throw new DbCslaException("Connection.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int dbid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(dbid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Connection.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DBID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int dbid) - { - _DBID = dbid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsConnection"; - cm.Parameters.AddWithValue("@DBID", _DBID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Execute", ex); - throw new DbCslaException("Connection.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ConnectionExtension _ConnectionExtension = new ConnectionExtension(); - [Serializable()] - partial class ConnectionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultServerType - { - get { return 1; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ConnectionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Connection) - { - // Return the ToString value - return ((Connection)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Connection Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionConverter))] + public partial class Connection : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshConnections = new List(); + private List _RefreshConnectionFolders = new List(); + private void AddToRefreshList(List refreshConnections, List refreshConnectionFolders) + { + if (IsDirty) + refreshConnections.Add(this); + if (_ConnectionFolders != null && _ConnectionFolders.IsDirty) + { + foreach (ConnectionFolder tmp in _ConnectionFolders) + { + if (tmp.IsDirty) refreshConnectionFolders.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshConnections = new List(); + _RefreshConnectionFolders = new List(); + AddToRefreshList(_RefreshConnections, _RefreshConnectionFolders); + } + private void ProcessRefreshList() + { + foreach (Connection tmp in _RefreshConnections) + { + ConnectionInfo.Refresh(tmp); + } + foreach (ConnectionFolder tmp in _RefreshConnectionFolders) + { + FolderInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Connection connection) + { + if (!_CacheList.Contains(connection)) _CacheList.Add(connection); // In AddToCache + } + protected static void RemoveFromCache(Connection connection) + { + while (_CacheList.Contains(connection)) _CacheList.Remove(connection); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByName = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Connection tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.DBID.ToString())) + { + _CacheByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name + } + _CacheByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index + remove.Add(tmp); + } + foreach (Connection tmp in remove) + RemoveFromCache(tmp); + } + protected static Connection GetCachedByPrimaryKey(int dbid) + { + ConvertListToDictionary(); + string key = dbid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Connection GetCachedByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextDBID = -1; + public static int NextDBID + { + get { return _nextDBID--; } + } + private int _DBID; + [System.ComponentModel.DataObjectField(true, true)] + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ConnectionString = string.Empty; + public string ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConnectionString; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ConnectionString != value) + { + _ConnectionString = value; + PropertyHasChanged(); + } + } + } + private int _ServerType; + /// + /// 0 SQL Server + /// + public int ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ServerType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ServerType != value) + { + _ServerType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ConnectionFolderCount = 0; + /// + /// Count of ConnectionFolders for this Connection + /// + public int ConnectionFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConnectionFolderCount; + } + } + private ConnectionFolders _ConnectionFolders = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ConnectionFoldersConverter))] + public ConnectionFolders ConnectionFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ConnectionFolderCount > 0 && _ConnectionFolders == null) + _ConnectionFolders = ConnectionFolders.GetByDBID(DBID); + else if (_ConnectionFolders == null) + _ConnectionFolders = ConnectionFolders.New(); + return _ConnectionFolders; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_ConnectionFolders == null ? false : _ConnectionFolders.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ConnectionFolders == null ? true : _ConnectionFolders.IsValid); } + } + // TODO: Replace base Connection.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Connection + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Connection.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Connection + protected override object GetIdValue() + { + return _DBID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ConnectionFolders != null && (hasBrokenRules = _ConnectionFolders.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConnectionString", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ConnectionExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ConnectionExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(DBID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(ConnectionString, ""); + //AuthorizationRules.AllowRead(ServerType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(ConnectionString, ""); + //AuthorizationRules.AllowWrite(ServerType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _ConnectionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ConnectionExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ConnectionFolderCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ConnectionUnique = 0; + protected static int ConnectionUnique + { get { return ++_ConnectionUnique; } } + private int _MyConnectionUnique = ConnectionUnique; + public int MyConnectionUnique + { get { return _MyConnectionUnique; } } + protected Connection() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DBID.ToString())) + { + List listConnection = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items + while (listConnection.Contains(this)) listConnection.Remove(this); // Remove the item from the list + if (listConnection.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByName.Keys) + if (_CacheByName[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listConnection = _CacheByName[myKey]; // Get the list of items + listConnection.Remove(this); // Remove the item from the list + if (listConnection.Count == 0) //If there are no items left in the list + _CacheByName.Remove(myKey); // remove the list + } + } + public static Connection New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Connection"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.New", ex); + } + } + public static Connection New(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) + { + Connection tmp = Connection.New(); + tmp.Name = name; + tmp.Title = title; + tmp.ConnectionString = connectionString; + tmp.ServerType = serverType; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Connection MakeConnection(string name, string title, string connectionString, int serverType, string config, DateTime dts, string usrID) + { + Connection tmp = Connection.New(name, title, connectionString, serverType, config, dts, usrID); + if (tmp.IsSavable) + { + Connection tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Connection New(string name, string title, string connectionString, string config) + { + Connection tmp = Connection.New(); + tmp.Name = name; + tmp.Title = title; + tmp.ConnectionString = connectionString; + tmp.Config = config; + return tmp; + } + public static Connection MakeConnection(string name, string title, string connectionString, string config) + { + Connection tmp = Connection.New(name, title, connectionString, config); + if (tmp.IsSavable) + { + Connection tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Connection Get(int dbid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Connection"); + try + { + Connection tmp = GetCachedByPrimaryKey(dbid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dbid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Connection + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.Get", ex); + } + } + public static Connection GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Connection"); + try + { + Connection tmp = GetCachedByName(name); + if (tmp == null) + { + tmp = DataPortal.Fetch(new NameCriteria(name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Connection + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.GetByName", ex); + } + } + public static Connection Get(SafeDataReader dr) + { + if (dr.Read()) return new Connection(dr); + return null; + } + internal Connection(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int dbid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Connection"); + try + { + DataPortal.Delete(new PKCriteria(dbid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.Delete", ex); + } + } + public override Connection Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Connection"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Connection"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Connection"); + try + { + BuildRefreshList(); + Connection connection = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(connection);//Refresh the item in AllList + ProcessRefreshList(); + return connection; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DBID; + public int DBID + { get { return _DBID; } } + public PKCriteria(int dbid) + { + _DBID = dbid; + } + } + [Serializable()] + private class NameCriteria + { + private string _Name; + public string Name + { get { return _Name; } } + public NameCriteria(string name) + { + _Name = name; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _DBID = NextDBID; + // Database Defaults + _ServerType = _ConnectionExtension.DefaultServerType; + _DTS = _ConnectionExtension.DefaultDTS; + _UsrID = _ConnectionExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.ReadData", GetHashCode()); + try + { + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ConnectionString = dr.GetString("ConnectionString"); + _ServerType = dr.GetInt32("ServerType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ConnectionFolderCount = dr.GetInt32("FolderCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnection"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ConnectionFolders = ConnectionFolders.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnectionByName"; + cm.Parameters.AddWithValue("@Name", criteria.Name); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Connection.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addConnection"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); + cm.Parameters.AddWithValue("@ServerType", _ServerType); + 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); + param_DBID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_DBID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _DBID = (int)cm.Parameters["@newDBID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_ConnectionFolders != null) _ConnectionFolders.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addConnection"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + cm.Parameters.AddWithValue("@ConnectionString", connectionString); + cm.Parameters.AddWithValue("@ServerType", serverType); + 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_DBID = new SqlParameter("@newDBID", SqlDbType.Int); + param_DBID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_DBID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + dbid = (int)cm.Parameters["@newDBID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Add", ex); + throw new DbCslaException("Connection.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateConnection"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@DBID", _DBID); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + cm.Parameters.AddWithValue("@ConnectionString", _ConnectionString); + cm.Parameters.AddWithValue("@ServerType", _ServerType); + 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); + // TODO: 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 (_ConnectionFolders != null) _ConnectionFolders.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Connection.Add(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID); + else + _LastChanged = Connection.Update(cn, ref _DBID, _Name, _Title, _ConnectionString, _ServerType, _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + if (_ConnectionFolders != null) _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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateConnection"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DBID", dbid); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + cm.Parameters.AddWithValue("@ConnectionString", connectionString); + cm.Parameters.AddWithValue("@ServerType", serverType); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteConnection"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteConnection"; + // Input PK Fields + cm.Parameters.AddWithValue("@DBID", dbid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.Remove", ex); + throw new DbCslaException("Connection.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int dbid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(dbid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Connection.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DBID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int dbid) + { + _DBID = dbid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Connection.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsConnection"; + cm.Parameters.AddWithValue("@DBID", _DBID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Connection.DataPortal_Execute", ex); + throw new DbCslaException("Connection.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ConnectionExtension _ConnectionExtension = new ConnectionExtension(); + [Serializable()] + partial class ConnectionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultServerType + { + get { return 1; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ConnectionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Connection) + { + // Return the ToString value + return ((Connection)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionFolder.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionFolder.cs index 26988cde..14a2e92b 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionFolder.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionFolder.cs @@ -19,568 +19,546 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ConnectionFolder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ConnectionFolderConverter))] - public partial class ConnectionFolder : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _FolderID; - [System.ComponentModel.DataObjectField(true, true)] - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - [System.ComponentModel.DataObjectField(true, true)] - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private Folder _MyParent; - public Folder MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ShortName", true); - if (value == null) value = string.Empty; - if (_ShortName != value) - { - _ShortName = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ManualOrder", true); - if (_ManualOrder != value) - { - _ManualOrder = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check ConnectionFolder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ConnectionFolder - protected override object GetIdValue() - { - return _FolderID; - } - // TODO: Replace base ConnectionFolder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ConnectionFolder - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ShortName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool MyFolderRequired(ConnectionFolder target, Csla.Validation.RuleArgs e) - { - if (target._ParentID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ShortName, ""); - //AuthorizationRules.AllowWrite(ShortName, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowRead(ManualOrder, ""); - //AuthorizationRules.AllowWrite(ManualOrder, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ConnectionFolder New(Folder myParent, string name, string shortName) - { - return new ConnectionFolder(myParent, name, shortName); - } - internal static ConnectionFolder Get(SafeDataReader dr) - { - return new ConnectionFolder(dr); - } - public ConnectionFolder() - { - MarkAsChild(); - _FolderID = Folder.NextFolderID; - _ParentID = _ConnectionFolderExtension.DefaultParentID; - _DTS = _ConnectionFolderExtension.DefaultDTS; - _UsrID = _ConnectionFolderExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private ConnectionFolder(Folder myParent, string name, string shortName) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _ParentID = _ConnectionFolderExtension.DefaultParentID; - _DTS = _ConnectionFolderExtension.DefaultDTS; - _UsrID = _ConnectionFolderExtension.DefaultUsrID; - _MyParent = myParent; - _Name = name; - _ShortName = shortName; - ValidationRules.CheckRules(); - } - internal ConnectionFolder(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionFolder.FetchDR", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _FormatID = (int?)dr.GetValue("FormatID"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionFolder.FetchDR", ex); - throw new DbCslaException("ConnectionFolder.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Connection myConnection) - { - // 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); - MarkOld(); - } - internal void Update(Connection myConnection) - { - // 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, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Connection myConnection) - { - // 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"]; - Folder.Remove(cn, _FolderID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ConnectionFolderExtension _ConnectionFolderExtension = new ConnectionFolderExtension(); - [Serializable()] - partial class ConnectionFolderExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ConnectionFolderConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ConnectionFolder) - { - // Return the ToString value - return ((ConnectionFolder)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ConnectionFolder Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionFolderConverter))] + public partial class ConnectionFolder : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _FolderID; + [System.ComponentModel.DataObjectField(true, true)] + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + [System.ComponentModel.DataObjectField(true, true)] + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private Folder _MyParent; + public Folder MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ShortName != value) + { + _ShortName = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ManualOrder != value) + { + _ManualOrder = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check ConnectionFolder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ConnectionFolder + protected override object GetIdValue() + { + return _FolderID; + } + // TODO: Replace base ConnectionFolder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ConnectionFolder + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ShortName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool MyFolderRequired(ConnectionFolder target, Csla.Validation.RuleArgs e) + { + if (target._ParentID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ShortName, ""); + //AuthorizationRules.AllowWrite(ShortName, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ConnectionFolder New(Folder myParent, string name, string shortName) + { + return new ConnectionFolder(myParent, name, shortName); + } + internal static ConnectionFolder Get(SafeDataReader dr) + { + return new ConnectionFolder(dr); + } + public ConnectionFolder() + { + MarkAsChild(); + _FolderID = Folder.NextFolderID; + _ParentID = _ConnectionFolderExtension.DefaultParentID; + _DTS = _ConnectionFolderExtension.DefaultDTS; + _UsrID = _ConnectionFolderExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private ConnectionFolder(Folder myParent, string name, string shortName) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _ParentID = _ConnectionFolderExtension.DefaultParentID; + _DTS = _ConnectionFolderExtension.DefaultDTS; + _UsrID = _ConnectionFolderExtension.DefaultUsrID; + _MyParent = myParent; + _Name = name; + _ShortName = shortName; + ValidationRules.CheckRules(); + } + internal ConnectionFolder(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionFolder.FetchDR", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionFolder.FetchDR", ex); + throw new DbCslaException("ConnectionFolder.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Connection myConnection) + { + // 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); + MarkOld(); + } + internal void Update(Connection myConnection) + { + // 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, Folder.Get(_ParentID), myConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Connection myConnection) + { + // 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"]; + Folder.Remove(cn, _FolderID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ConnectionFolderExtension _ConnectionFolderExtension = new ConnectionFolderExtension(); + [Serializable()] + partial class ConnectionFolderExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ConnectionFolderConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ConnectionFolder) + { + // Return the ToString value + return ((ConnectionFolder)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionInfo.cs index b4c793b5..74808061 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ConnectionInfo.cs @@ -19,392 +19,382 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ConnectionInfoEvent(object sender); - /// - /// ConnectionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ConnectionInfoConverter))] - public partial class ConnectionInfo : ReadOnlyBase, IDisposable - { - public event ConnectionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ConnectionInfo connectionInfo) - { - if (!_CacheList.Contains(connectionInfo)) _CacheList.Add(connectionInfo); // In AddToCache - } - protected static void RemoveFromCache(ConnectionInfo connectionInfo) - { - while (_CacheList.Contains(connectionInfo)) _CacheList.Remove(connectionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ConnectionInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.DBID.ToString())) - { - _CacheByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ConnectionInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(ConnectionInfoList lst) - { - foreach (ConnectionInfo item in lst) AddToCache(item); - } - protected static ConnectionInfo GetCachedByPrimaryKey(int dbid) - { - ConvertListToDictionary(); - string key = dbid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Connection _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _DBID; - [System.ComponentModel.DataObjectField(true, true)] - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - return _DBID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private string _ConnectionString = string.Empty; - public string ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionString", true); - return _ConnectionString; - } - } - private int _ServerType; - /// - /// 0 SQL Server - /// - public int ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ServerType", true); - return _ServerType; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _ConnectionFolderCount = 0; - /// - /// Count of ConnectionFolders for this Connection - /// - public int ConnectionFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolderCount", true); - return _ConnectionFolderCount; - } - } - private FolderInfoList _ConnectionFolders = null; - [TypeConverter(typeof(FolderInfoListConverter))] - public FolderInfoList ConnectionFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ConnectionFolders", true); - if (_ConnectionFolderCount < 0 || (_ConnectionFolderCount > 0 && _ConnectionFolders == null)) - _ConnectionFolders = FolderInfoList.GetByDBID(_DBID); - if (_ConnectionFolderCount < 0) - _ConnectionFolderCount = _ConnectionFolders.Count; - return _ConnectionFolders; - } - } - public void RefreshConnectionFolders() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_DBID.ToString())) - foreach (ConnectionInfo tmp in _CacheByPrimaryKey[_DBID.ToString()]) - tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base ConnectionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ConnectionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ConnectionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ConnectionInfo - protected override object GetIdValue() - { - return _DBID; - } - #endregion - #region Factory Methods - private static int _ConnectionInfoUnique = 0; - private static int ConnectionInfoUnique - { get { return ++_ConnectionInfoUnique; } } - private int _MyConnectionInfoUnique = ConnectionInfoUnique; - public int MyConnectionInfoUnique - { get { return _MyConnectionInfoUnique; } } - protected ConnectionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DBID.ToString())) return; - List listConnectionInfo = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items - while (listConnectionInfo.Contains(this)) listConnectionInfo.Remove(this); // Remove the item from the list - if (listConnectionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list - } - public virtual Connection Get() - { - return _Editable = Connection.Get(_DBID); - } - public static void Refresh(Connection tmp) - { - string key = tmp.DBID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ConnectionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Connection tmp) - { - _Name = tmp.Name; - _Title = tmp.Title; - _ConnectionString = tmp.ConnectionString; - _ServerType = tmp.ServerType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _ConnectionInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static ConnectionInfo Get(int dbid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Connection"); - try - { - ConnectionInfo tmp = GetCachedByPrimaryKey(dbid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(dbid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ConnectionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ConnectionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ConnectionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.Constructor", ex); - throw new DbCslaException("ConnectionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DBID; - public int DBID - { get { return _DBID; } } - public PKCriteria(int dbid) - { - _DBID = dbid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.ReadData", GetHashCode()); - try - { - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ConnectionString = dr.GetString("ConnectionString"); - _ServerType = dr.GetInt32("ServerType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _ConnectionFolderCount = dr.GetInt32("FolderCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ConnectionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getConnection"; - cm.Parameters.AddWithValue("@DBID", criteria.DBID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ConnectionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ConnectionInfoExtension _ConnectionInfoExtension = new ConnectionInfoExtension(); - [Serializable()] - partial class ConnectionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ConnectionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ConnectionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ConnectionInfo) - { - // Return the ToString value - return ((ConnectionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ConnectionInfoEvent(object sender); + /// + /// ConnectionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ConnectionInfoConverter))] + public partial class ConnectionInfo : ReadOnlyBase, IDisposable + { + public event ConnectionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ConnectionInfo connectionInfo) + { + if (!_CacheList.Contains(connectionInfo)) _CacheList.Add(connectionInfo); // In AddToCache + } + protected static void RemoveFromCache(ConnectionInfo connectionInfo) + { + while (_CacheList.Contains(connectionInfo)) _CacheList.Remove(connectionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ConnectionInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.DBID.ToString())) + { + _CacheByPrimaryKey[tmp.DBID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.DBID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ConnectionInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(ConnectionInfoList lst) + { + foreach (ConnectionInfo item in lst) AddToCache(item); + } + protected static ConnectionInfo GetCachedByPrimaryKey(int dbid) + { + ConvertListToDictionary(); + string key = dbid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Connection _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _DBID; + [System.ComponentModel.DataObjectField(true, true)] + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private string _ConnectionString = string.Empty; + public string ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConnectionString; + } + } + private int _ServerType; + /// + /// 0 SQL Server + /// + public int ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ServerType; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _ConnectionFolderCount = 0; + /// + /// Count of ConnectionFolders for this Connection + /// + public int ConnectionFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ConnectionFolderCount; + } + } + private FolderInfoList _ConnectionFolders = null; + [TypeConverter(typeof(FolderInfoListConverter))] + public FolderInfoList ConnectionFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ConnectionFolderCount < 0 || (_ConnectionFolderCount > 0 && _ConnectionFolders == null)) + _ConnectionFolders = FolderInfoList.GetByDBID(_DBID); + if (_ConnectionFolderCount < 0) + _ConnectionFolderCount = _ConnectionFolders.Count; + return _ConnectionFolders; + } + } + public void RefreshConnectionFolders() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_DBID.ToString())) + foreach (ConnectionInfo tmp in _CacheByPrimaryKey[_DBID.ToString()]) + tmp._ConnectionFolderCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base ConnectionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ConnectionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ConnectionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ConnectionInfo + protected override object GetIdValue() + { + return _DBID; + } + #endregion + #region Factory Methods + private static int _ConnectionInfoUnique = 0; + private static int ConnectionInfoUnique + { get { return ++_ConnectionInfoUnique; } } + private int _MyConnectionInfoUnique = ConnectionInfoUnique; + public int MyConnectionInfoUnique + { get { return _MyConnectionInfoUnique; } } + protected ConnectionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DBID.ToString())) return; + List listConnectionInfo = _CacheByPrimaryKey[DBID.ToString()]; // Get the list of items + while (listConnectionInfo.Contains(this)) listConnectionInfo.Remove(this); // Remove the item from the list + if (listConnectionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(DBID.ToString()); // remove the list + } + public virtual Connection Get() + { + return _Editable = Connection.Get(_DBID); + } + public static void Refresh(Connection tmp) + { + string key = tmp.DBID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ConnectionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Connection tmp) + { + _Name = tmp.Name; + _Title = tmp.Title; + _ConnectionString = tmp.ConnectionString; + _ServerType = tmp.ServerType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _ConnectionInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static ConnectionInfo Get(int dbid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Connection"); + try + { + ConnectionInfo tmp = GetCachedByPrimaryKey(dbid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(dbid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ConnectionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ConnectionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ConnectionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.Constructor", ex); + throw new DbCslaException("ConnectionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DBID; + public int DBID + { get { return _DBID; } } + public PKCriteria(int dbid) + { + _DBID = dbid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.ReadData", GetHashCode()); + try + { + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ConnectionString = dr.GetString("ConnectionString"); + _ServerType = dr.GetInt32("ServerType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _ConnectionFolderCount = dr.GetInt32("FolderCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ConnectionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ConnectionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnection"; + cm.Parameters.AddWithValue("@DBID", criteria.DBID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ConnectionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ConnectionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ConnectionInfoExtension _ConnectionInfoExtension = new ConnectionInfoExtension(); + [Serializable()] + partial class ConnectionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ConnectionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ConnectionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ConnectionInfo) + { + // Return the ToString value + return ((ConnectionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Content.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Content.cs index 1e2b701e..2dc2d6f6 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Content.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Content.cs @@ -20,1391 +20,1361 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Content Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentConverter))] - public partial class Content : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshContents = new List(); - private List _RefreshContentDetails = new List(); - private List _RefreshContentItems = new List(); - private List _RefreshContentParts = new List(); - private List _RefreshContentRoUsages = new List(); - private List _RefreshContentTransitions = new List(); - private void AddToRefreshList(List refreshContents, List refreshContentDetails, List refreshContentItems, List refreshContentParts, List refreshContentRoUsages, List refreshContentTransitions) - { - if (IsDirty) - refreshContents.Add(this); - if (_ContentDetails != null && _ContentDetails.IsDirty) - { - foreach (ContentDetail tmp in _ContentDetails) - { - if (tmp.IsDirty) refreshContentDetails.Add(tmp); - } - } - if (_ContentItems != null && _ContentItems.IsDirty) - { - foreach (ContentItem tmp in _ContentItems) - { - if (tmp.IsDirty) refreshContentItems.Add(tmp); - } - } - if (_ContentParts != null && _ContentParts.IsDirty) - { - foreach (ContentPart tmp in _ContentParts) - { - if (tmp.IsDirty) refreshContentParts.Add(tmp); - } - } - if (_ContentRoUsages != null && _ContentRoUsages.IsDirty) - { - foreach (ContentRoUsage tmp in _ContentRoUsages) - { - if (tmp.IsDirty) refreshContentRoUsages.Add(tmp); - } - } - if (_ContentTransitions != null && _ContentTransitions.IsDirty) - { - foreach (ContentTransition tmp in _ContentTransitions) - { - if (tmp.IsDirty) refreshContentTransitions.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshContents = new List(); - _RefreshContentDetails = new List(); - _RefreshContentItems = new List(); - _RefreshContentParts = new List(); - _RefreshContentRoUsages = new List(); - _RefreshContentTransitions = new List(); - AddToRefreshList(_RefreshContents, _RefreshContentDetails, _RefreshContentItems, _RefreshContentParts, _RefreshContentRoUsages, _RefreshContentTransitions); - } - private void ProcessRefreshList() - { - foreach (Content tmp in _RefreshContents) - { - ContentInfo.Refresh(tmp); - if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); - } - foreach (ContentDetail tmp in _RefreshContentDetails) - { - DetailInfo.Refresh(tmp); - } - foreach (ContentItem tmp in _RefreshContentItems) - { - ItemInfo.Refresh(tmp); - } - foreach (ContentPart tmp in _RefreshContentParts) - { - PartInfo.Refresh(this, tmp); - } - foreach (ContentRoUsage tmp in _RefreshContentRoUsages) - { - RoUsageInfo.Refresh(tmp); - } - foreach (ContentTransition tmp in _RefreshContentTransitions) - { - TransitionInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Content content) - { - if (!_CacheList.Contains(content)) _CacheList.Add(content); // In AddToCache - } - protected static void RemoveFromCache(Content content) - { - while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Content tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Content tmp in remove) - RemoveFromCache(tmp); - } - protected static Content GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextContentID = -1; - public static int NextContentID - { - get { return _nextContentID--; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private string _Number = string.Empty; - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Number", true); - if (value == null) value = string.Empty; - if (_Number != value) - { - _Number = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private int? _Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Type", true); - if (_Type != value) - { - _Type = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ContentDetailCount = 0; - /// - /// Count of ContentDetails for this Content - /// - public int ContentDetailCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetailCount", true); - return _ContentDetailCount; - } - } - private ContentDetails _ContentDetails = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentDetailsConverter))] - public ContentDetails ContentDetails - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetails", true); - if (_ContentDetailCount > 0 && _ContentDetails == null) - _ContentDetails = ContentDetails.GetByContentID(ContentID); - else if (_ContentDetails == null) - _ContentDetails = ContentDetails.New(); - return _ContentDetails; - } - } - private int _ContentEntryCount = 0; - /// - /// Count of ContentEntries for this Content - /// - public int ContentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentEntryCount", true); - return _ContentEntryCount; - } - } - private Entry _MyEntry = null; - /// - /// Related Field - /// - [TypeConverter(typeof(EntryConverter))] - public Entry MyEntry - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyEntry", true); - if (_MyEntry == null) _MyEntry = Entry.New(this); - return _MyEntry; - } - } - private int _ContentItemCount = 0; - /// - /// Count of ContentItems for this Content - /// - public int ContentItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItemCount", true); - return _ContentItemCount; - } - } - private ContentItems _ContentItems = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentItemsConverter))] - public ContentItems ContentItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItems", true); - if (_ContentItemCount > 0 && _ContentItems == null) - _ContentItems = ContentItems.GetByContentID(ContentID); - else if (_ContentItems == null) - _ContentItems = ContentItems.New(); - return _ContentItems; - } - } - private int _ContentPartCount = 0; - /// - /// Count of ContentParts for this Content - /// - public int ContentPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentPartCount", true); - return _ContentPartCount; - } - } - private ContentParts _ContentParts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentPartsConverter))] - public ContentParts ContentParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentParts", true); - if (_ContentPartCount > 0 && _ContentParts == null) - _ContentParts = ContentParts.GetByContentID(ContentID); - else if (_ContentParts == null) - _ContentParts = ContentParts.New(); - return _ContentParts; - } - } - private int _ContentRoUsageCount = 0; - /// - /// Count of ContentRoUsages for this Content - /// - public int ContentRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsageCount", true); - return _ContentRoUsageCount; - } - } - private ContentRoUsages _ContentRoUsages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentRoUsagesConverter))] - public ContentRoUsages ContentRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsages", true); - if (_ContentRoUsageCount > 0 && _ContentRoUsages == null) - _ContentRoUsages = ContentRoUsages.GetByContentID(ContentID); - else if (_ContentRoUsages == null) - _ContentRoUsages = ContentRoUsages.New(); - return _ContentRoUsages; - } - } - private int _ContentTransitionCount = 0; - /// - /// Count of ContentTransitions for this Content - /// - public int ContentTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitionCount", true); - return _ContentTransitionCount; - } - } - private ContentTransitions _ContentTransitions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ContentTransitionsConverter))] - public ContentTransitions ContentTransitions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitions", true); - if (_ContentTransitionCount > 0 && _ContentTransitions == null) - _ContentTransitions = ContentTransitions.GetByFromID(ContentID); - else if (_ContentTransitions == null) - _ContentTransitions = ContentTransitions.New(); - return _ContentTransitions; - } - } - private int _ContentZContentCount = 0; - /// - /// Count of ContentZContents for this Content - /// - public int ContentZContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentZContentCount", true); - return _ContentZContentCount; - } - } - private ZContent _MyZContent = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ZContentConverter))] - public ZContent MyZContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZContent", true); - if (_MyZContent == null) _MyZContent = ZContent.New(this); - return _MyZContent; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_ContentDetails == null ? false : _ContentDetails.IsDirty) || (_MyEntry == null ? false : _MyEntry.IsDirty) || (_ContentItems == null ? false : _ContentItems.IsDirty) || (_ContentParts == null ? false : _ContentParts.IsDirty) || (_ContentRoUsages == null ? false : _ContentRoUsages.IsDirty) || (_ContentTransitions == null ? false : _ContentTransitions.IsDirty) || (_MyZContent == null ? false : _MyZContent.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ContentDetails == null ? true : _ContentDetails.IsValid) && (_MyEntry == null ? true : _MyEntry.IsValid) && (_ContentItems == null ? true : _ContentItems.IsValid) && (_ContentParts == null ? true : _ContentParts.IsValid) && (_ContentRoUsages == null ? true : _ContentRoUsages.IsValid) && (_ContentTransitions == null ? true : _ContentTransitions.IsValid) && (_MyZContent == null ? true : _MyZContent.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid); } - } - // TODO: Replace base Content.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Content - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Content.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Content - protected override object GetIdValue() - { - return _ContentID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ContentItems != null && (hasBrokenRules = _ContentItems.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentDetails != null && (hasBrokenRules = _ContentDetails.HasBrokenRules) != null) return hasBrokenRules; - if (_MyEntry != null && (hasBrokenRules = _MyEntry.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentParts != null && (hasBrokenRules = _ContentParts.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentRoUsages != null && (hasBrokenRules = _ContentRoUsages.HasBrokenRules) != null) return hasBrokenRules; - if (_ContentTransitions != null && (hasBrokenRules = _ContentTransitions.HasBrokenRules) != null) return hasBrokenRules; - if (_MyZContent != null && (hasBrokenRules = _MyZContent.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 30)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ContentExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ContentExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(Number, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowRead(Type, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(Number, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowWrite(Type, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ContentExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ContentExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ContentDetailCount; - usedByCount += _ContentEntryCount; - usedByCount += _ContentItemCount; - usedByCount += _ContentPartCount; - usedByCount += _ContentRoUsageCount; - usedByCount += _ContentTransitionCount; - usedByCount += _ContentZContentCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ContentUnique = 0; - protected static int ContentUnique - { get { return ++_ContentUnique; } } - private int _MyContentUnique = ContentUnique; - public int MyContentUnique - { get { return _MyContentUnique; } } - protected Content() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listContent.Contains(this)) listContent.Remove(this); // Remove the item from the list - if (listContent.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static Content New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Content"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.New", ex); - } - } - public static Content New(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) - { - Content tmp = Content.New(); - tmp.Number = number; - tmp.Text = text; - tmp.Type = type; - tmp.MyFormat = myFormat; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Content MakeContent(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) - { - Content tmp = Content.New(number, text, type, myFormat, config, dts, userID); - if (tmp.IsSavable) - { - Content tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Content New(string number, string text, int? type, Format myFormat, string config) - { - Content tmp = Content.New(); - tmp.Number = number; - tmp.Text = text; - tmp.Type = type; - tmp.MyFormat = myFormat; - tmp.Config = config; - return tmp; - } - public static Content MakeContent(string number, string text, int? type, Format myFormat, string config) - { - Content tmp = Content.New(number, text, type, myFormat, config); - if (tmp.IsSavable) - { - Content tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Content Get(int contentID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Content"); - try - { - Content tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Content - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.Get", ex); - } - } - public static Content Get(SafeDataReader dr) - { - if (dr.Read()) return new Content(dr); - return null; - } - internal Content(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int contentID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Content"); - try - { - DataPortal.Delete(new PKCriteria(contentID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.Delete", ex); - } - } - public override Content Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Content"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Content"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Content"); - try - { - BuildRefreshList(); - Content content = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(content);//Refresh the item in AllList - ProcessRefreshList(); - return content; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ContentID = NextContentID; - // Database Defaults - _DTS = _ContentExtension.DefaultDTS; - _UserID = _ContentExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ContentDetailCount = dr.GetInt32("DetailCount"); - _ContentEntryCount = dr.GetInt32("EntryCount"); - _ContentItemCount = dr.GetInt32("ItemCount"); - _ContentPartCount = dr.GetInt32("PartCount"); - _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); - _ContentTransitionCount = dr.GetInt32("TransitionCount"); - _ContentZContentCount = dr.GetInt32("ZContentCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Content.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ContentDetails = ContentDetails.Get(dr); - // load child objects - dr.NextResult(); - _MyEntry = Entry.Get(dr); - // load child objects - dr.NextResult(); - _ContentItems = ContentItems.Get(dr); - // load child objects - dr.NextResult(); - _ContentParts = ContentParts.Get(dr); - // load child objects - dr.NextResult(); - _ContentRoUsages = ContentRoUsages.Get(dr); - // load child objects - dr.NextResult(); - _ContentTransitions = ContentTransitions.Get(dr); - // load child objects - dr.NextResult(); - _MyZContent = ZContent.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Content.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Content.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyFormat != null) _MyFormat.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); - param_ContentID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ContentID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _ContentID = (int)cm.Parameters["@newContentID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_ContentItems != null) _ContentItems.Update(this); - if (_ContentDetails != null) _ContentDetails.Update(this); - if (_MyEntry != null) _MyEntry.Update(this); - if (_ContentParts != null) _ContentParts.Update(this); - if (_ContentRoUsages != null) _ContentRoUsages.Update(this); - if (_ContentTransitions != null) _ContentTransitions.Update(this); - if (_MyZContent != null) _MyZContent.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); - param_ContentID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ContentID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - contentID = (int)cm.Parameters["@newContentID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Add", ex); - throw new DbCslaException("Content.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Content.SQLUpdate", GetHashCode()); - try - { - if (_MyFormat != null) _MyFormat.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateContent"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@Number", _Number); - cm.Parameters.AddWithValue("@Text", _Text); - cm.Parameters.AddWithValue("@Type", _Type); - 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); - // TODO: 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 (_ContentItems != null) _ContentItems.Update(this); - if (_ContentDetails != null) _ContentDetails.Update(this); - if (_MyEntry != null) _MyEntry.Update(this); - if (_ContentParts != null) _ContentParts.Update(this); - if (_ContentRoUsages != null) _ContentRoUsages.Update(this); - if (_ContentTransitions != null) _ContentTransitions.Update(this); - if (_MyZContent != null) _MyZContent.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID); - else - _LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_ContentItems != null) _ContentItems.Update(this); - if (_ContentDetails != null) _ContentDetails.Update(this); - if (_MyEntry != null) _MyEntry.Update(this); - if (_ContentParts != null) _ContentParts.Update(this); - if (_ContentRoUsages != null) _ContentRoUsages.Update(this); - if (_ContentTransitions != null) _ContentTransitions.Update(this); - if (_MyZContent != null) _MyZContent.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int contentID, string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@Number", number); - cm.Parameters.AddWithValue("@Text", text); - cm.Parameters.AddWithValue("@Type", type); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteContent"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Remove", ex); - throw new DbCslaException("Content.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Content.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsContent"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Execute", ex); - throw new DbCslaException("Content.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ContentExtension _ContentExtension = new ContentExtension(); - [Serializable()] - partial class ContentExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Content) - { - // Return the ToString value - return ((Content)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Content Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentConverter))] + public partial class Content : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshContents = new List(); + private List _RefreshContentDetails = new List(); + private List _RefreshContentItems = new List(); + private List _RefreshContentParts = new List(); + private List _RefreshContentRoUsages = new List(); + private List _RefreshContentTransitions = new List(); + private void AddToRefreshList(List refreshContents, List refreshContentDetails, List refreshContentItems, List refreshContentParts, List refreshContentRoUsages, List refreshContentTransitions) + { + if (IsDirty) + refreshContents.Add(this); + if (_ContentDetails != null && _ContentDetails.IsDirty) + { + foreach (ContentDetail tmp in _ContentDetails) + { + if (tmp.IsDirty) refreshContentDetails.Add(tmp); + } + } + if (_ContentItems != null && _ContentItems.IsDirty) + { + foreach (ContentItem tmp in _ContentItems) + { + if (tmp.IsDirty) refreshContentItems.Add(tmp); + } + } + if (_ContentParts != null && _ContentParts.IsDirty) + { + foreach (ContentPart tmp in _ContentParts) + { + if (tmp.IsDirty) refreshContentParts.Add(tmp); + } + } + if (_ContentRoUsages != null && _ContentRoUsages.IsDirty) + { + foreach (ContentRoUsage tmp in _ContentRoUsages) + { + if (tmp.IsDirty) refreshContentRoUsages.Add(tmp); + } + } + if (_ContentTransitions != null && _ContentTransitions.IsDirty) + { + foreach (ContentTransition tmp in _ContentTransitions) + { + if (tmp.IsDirty) refreshContentTransitions.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshContents = new List(); + _RefreshContentDetails = new List(); + _RefreshContentItems = new List(); + _RefreshContentParts = new List(); + _RefreshContentRoUsages = new List(); + _RefreshContentTransitions = new List(); + AddToRefreshList(_RefreshContents, _RefreshContentDetails, _RefreshContentItems, _RefreshContentParts, _RefreshContentRoUsages, _RefreshContentTransitions); + } + private void ProcessRefreshList() + { + foreach (Content tmp in _RefreshContents) + { + ContentInfo.Refresh(tmp); + if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); + } + foreach (ContentDetail tmp in _RefreshContentDetails) + { + DetailInfo.Refresh(tmp); + } + foreach (ContentItem tmp in _RefreshContentItems) + { + ItemInfo.Refresh(tmp); + } + foreach (ContentPart tmp in _RefreshContentParts) + { + PartInfo.Refresh(this, tmp); + } + foreach (ContentRoUsage tmp in _RefreshContentRoUsages) + { + RoUsageInfo.Refresh(tmp); + } + foreach (ContentTransition tmp in _RefreshContentTransitions) + { + TransitionInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Content content) + { + if (!_CacheList.Contains(content)) _CacheList.Add(content); // In AddToCache + } + protected static void RemoveFromCache(Content content) + { + while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Content tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Content tmp in remove) + RemoveFromCache(tmp); + } + protected static Content GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextContentID = -1; + public static int NextContentID + { + get { return _nextContentID--; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Number != value) + { + _Number = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private int? _Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Type != value) + { + _Type = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ContentDetailCount = 0; + /// + /// Count of ContentDetails for this Content + /// + public int ContentDetailCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentDetailCount; + } + } + private ContentDetails _ContentDetails = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentDetailsConverter))] + public ContentDetails ContentDetails + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentDetailCount > 0 && _ContentDetails == null) + _ContentDetails = ContentDetails.GetByContentID(ContentID); + else if (_ContentDetails == null) + _ContentDetails = ContentDetails.New(); + return _ContentDetails; + } + } + private int _ContentEntryCount = 0; + /// + /// Count of ContentEntries for this Content + /// + public int ContentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentEntryCount; + } + } + private Entry _MyEntry = null; + /// + /// Related Field + /// + [TypeConverter(typeof(EntryConverter))] + public Entry MyEntry + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyEntry == null) _MyEntry = Entry.New(this); + return _MyEntry; + } + } + private int _ContentItemCount = 0; + /// + /// Count of ContentItems for this Content + /// + public int ContentItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentItemCount; + } + } + private ContentItems _ContentItems = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentItemsConverter))] + public ContentItems ContentItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentItemCount > 0 && _ContentItems == null) + _ContentItems = ContentItems.GetByContentID(ContentID); + else if (_ContentItems == null) + _ContentItems = ContentItems.New(); + return _ContentItems; + } + } + private int _ContentPartCount = 0; + /// + /// Count of ContentParts for this Content + /// + public int ContentPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentPartCount; + } + } + private ContentParts _ContentParts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentPartsConverter))] + public ContentParts ContentParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentPartCount > 0 && _ContentParts == null) + _ContentParts = ContentParts.GetByContentID(ContentID); + else if (_ContentParts == null) + _ContentParts = ContentParts.New(); + return _ContentParts; + } + } + private int _ContentRoUsageCount = 0; + /// + /// Count of ContentRoUsages for this Content + /// + public int ContentRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentRoUsageCount; + } + } + private ContentRoUsages _ContentRoUsages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentRoUsagesConverter))] + public ContentRoUsages ContentRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentRoUsageCount > 0 && _ContentRoUsages == null) + _ContentRoUsages = ContentRoUsages.GetByContentID(ContentID); + else if (_ContentRoUsages == null) + _ContentRoUsages = ContentRoUsages.New(); + return _ContentRoUsages; + } + } + private int _ContentTransitionCount = 0; + /// + /// Count of ContentTransitions for this Content + /// + public int ContentTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentTransitionCount; + } + } + private ContentTransitions _ContentTransitions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ContentTransitionsConverter))] + public ContentTransitions ContentTransitions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentTransitionCount > 0 && _ContentTransitions == null) + _ContentTransitions = ContentTransitions.GetByFromID(ContentID); + else if (_ContentTransitions == null) + _ContentTransitions = ContentTransitions.New(); + return _ContentTransitions; + } + } + private int _ContentZContentCount = 0; + /// + /// Count of ContentZContents for this Content + /// + public int ContentZContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentZContentCount; + } + } + private ZContent _MyZContent = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ZContentConverter))] + public ZContent MyZContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyZContent == null) _MyZContent = ZContent.New(this); + return _MyZContent; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_ContentDetails == null ? false : _ContentDetails.IsDirty) || (_MyEntry == null ? false : _MyEntry.IsDirty) || (_ContentItems == null ? false : _ContentItems.IsDirty) || (_ContentParts == null ? false : _ContentParts.IsDirty) || (_ContentRoUsages == null ? false : _ContentRoUsages.IsDirty) || (_ContentTransitions == null ? false : _ContentTransitions.IsDirty) || (_MyZContent == null ? false : _MyZContent.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ContentDetails == null ? true : _ContentDetails.IsValid) && (_MyEntry == null ? true : _MyEntry.IsValid) && (_ContentItems == null ? true : _ContentItems.IsValid) && (_ContentParts == null ? true : _ContentParts.IsValid) && (_ContentRoUsages == null ? true : _ContentRoUsages.IsValid) && (_ContentTransitions == null ? true : _ContentTransitions.IsValid) && (_MyZContent == null ? true : _MyZContent.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid); } + } + // TODO: Replace base Content.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Content + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Content.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Content + protected override object GetIdValue() + { + return _ContentID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ContentItems != null && (hasBrokenRules = _ContentItems.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentDetails != null && (hasBrokenRules = _ContentDetails.HasBrokenRules) != null) return hasBrokenRules; + if (_MyEntry != null && (hasBrokenRules = _MyEntry.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentParts != null && (hasBrokenRules = _ContentParts.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentRoUsages != null && (hasBrokenRules = _ContentRoUsages.HasBrokenRules) != null) return hasBrokenRules; + if (_ContentTransitions != null && (hasBrokenRules = _ContentTransitions.HasBrokenRules) != null) return hasBrokenRules; + if (_MyZContent != null && (hasBrokenRules = _MyZContent.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 30)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ContentExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ContentExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(Number, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowRead(Type, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(Number, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowWrite(Type, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ContentExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ContentExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ContentDetailCount; + usedByCount += _ContentEntryCount; + usedByCount += _ContentItemCount; + usedByCount += _ContentPartCount; + usedByCount += _ContentRoUsageCount; + usedByCount += _ContentTransitionCount; + usedByCount += _ContentZContentCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ContentUnique = 0; + protected static int ContentUnique + { get { return ++_ContentUnique; } } + private int _MyContentUnique = ContentUnique; + public int MyContentUnique + { get { return _MyContentUnique; } } + protected Content() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listContent.Contains(this)) listContent.Remove(this); // Remove the item from the list + if (listContent.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static Content New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Content"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.New", ex); + } + } + public static Content New(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) + { + Content tmp = Content.New(); + tmp.Number = number; + tmp.Text = text; + tmp.Type = type; + tmp.MyFormat = myFormat; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Content MakeContent(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID) + { + Content tmp = Content.New(number, text, type, myFormat, config, dts, userID); + if (tmp.IsSavable) + { + Content tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Content New(string number, string text, int? type, Format myFormat, string config) + { + Content tmp = Content.New(); + tmp.Number = number; + tmp.Text = text; + tmp.Type = type; + tmp.MyFormat = myFormat; + tmp.Config = config; + return tmp; + } + public static Content MakeContent(string number, string text, int? type, Format myFormat, string config) + { + Content tmp = Content.New(number, text, type, myFormat, config); + if (tmp.IsSavable) + { + Content tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Content Get(int contentID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Content"); + try + { + Content tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Content + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.Get", ex); + } + } + public static Content Get(SafeDataReader dr) + { + if (dr.Read()) return new Content(dr); + return null; + } + internal Content(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int contentID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Content"); + try + { + DataPortal.Delete(new PKCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.Delete", ex); + } + } + public override Content Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Content"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Content"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Content"); + try + { + BuildRefreshList(); + Content content = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(content);//Refresh the item in AllList + ProcessRefreshList(); + return content; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ContentID = NextContentID; + // Database Defaults + _DTS = _ContentExtension.DefaultDTS; + _UserID = _ContentExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ContentDetailCount = dr.GetInt32("DetailCount"); + _ContentEntryCount = dr.GetInt32("EntryCount"); + _ContentItemCount = dr.GetInt32("ItemCount"); + _ContentPartCount = dr.GetInt32("PartCount"); + _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); + _ContentTransitionCount = dr.GetInt32("TransitionCount"); + _ContentZContentCount = dr.GetInt32("ZContentCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Content.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ContentDetails = ContentDetails.Get(dr); + // load child objects + dr.NextResult(); + _MyEntry = Entry.Get(dr); + // load child objects + dr.NextResult(); + _ContentItems = ContentItems.Get(dr); + // load child objects + dr.NextResult(); + _ContentParts = ContentParts.Get(dr); + // load child objects + dr.NextResult(); + _ContentRoUsages = ContentRoUsages.Get(dr); + // load child objects + dr.NextResult(); + _ContentTransitions = ContentTransitions.Get(dr); + // load child objects + dr.NextResult(); + _MyZContent = ZContent.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Content.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Content.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyFormat != null) _MyFormat.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); + param_ContentID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ContentID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _ContentID = (int)cm.Parameters["@newContentID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_ContentItems != null) _ContentItems.Update(this); + if (_ContentDetails != null) _ContentDetails.Update(this); + if (_MyEntry != null) _MyEntry.Update(this); + if (_ContentParts != null) _ContentParts.Update(this); + if (_ContentRoUsages != null) _ContentRoUsages.Update(this); + if (_ContentTransitions != null) _ContentTransitions.Update(this); + if (_MyZContent != null) _MyZContent.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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_ContentID = new SqlParameter("@newContentID", SqlDbType.Int); + param_ContentID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ContentID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + contentID = (int)cm.Parameters["@newContentID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Add", ex); + throw new DbCslaException("Content.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Content.SQLUpdate", GetHashCode()); + try + { + if (_MyFormat != null) _MyFormat.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateContent"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@Number", _Number); + cm.Parameters.AddWithValue("@Text", _Text); + cm.Parameters.AddWithValue("@Type", _Type); + 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); + // TODO: 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 (_ContentItems != null) _ContentItems.Update(this); + if (_ContentDetails != null) _ContentDetails.Update(this); + if (_MyEntry != null) _MyEntry.Update(this); + if (_ContentParts != null) _ContentParts.Update(this); + if (_ContentRoUsages != null) _ContentRoUsages.Update(this); + if (_ContentTransitions != null) _ContentTransitions.Update(this); + if (_MyZContent != null) _MyZContent.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID); + else + _LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_ContentItems != null) _ContentItems.Update(this); + if (_ContentDetails != null) _ContentDetails.Update(this); + if (_MyEntry != null) _MyEntry.Update(this); + if (_ContentParts != null) _ContentParts.Update(this); + if (_ContentRoUsages != null) _ContentRoUsages.Update(this); + if (_ContentTransitions != null) _ContentTransitions.Update(this); + if (_MyZContent != null) _MyZContent.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int contentID, string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@Number", number); + cm.Parameters.AddWithValue("@Text", text); + cm.Parameters.AddWithValue("@Type", type); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteContent"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Remove", ex); + throw new DbCslaException("Content.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Content.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsContent"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Execute", ex); + throw new DbCslaException("Content.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ContentExtension _ContentExtension = new ContentExtension(); + [Serializable()] + partial class ContentExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Content) + { + // Return the ToString value + return ((Content)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentDetail.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentDetail.cs index 1f71e42f..fd8a3418 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentDetail.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentDetail.cs @@ -19,410 +19,398 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentDetail Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentDetailConverter))] - public partial class ContentDetail : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _DetailID; - [System.ComponentModel.DataObjectField(true, true)] - public int DetailID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DetailID", true); - if (_MyDetail != null) _DetailID = _MyDetail.DetailID; - return _DetailID; - } - } - private Detail _MyDetail; - [System.ComponentModel.DataObjectField(true, true)] - public Detail MyDetail - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDetail", true); - if (_MyDetail == null && _DetailID != 0) _MyDetail = Detail.Get(_DetailID); - return _MyDetail; - } - } - private int _ItemType; - public int ItemType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemType", true); - return _ItemType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemType", true); - if (_ItemType != value) - { - _ItemType = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check ContentDetail.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentDetail - protected override object GetIdValue() - { - return _DetailID; - } - // TODO: Replace base ContentDetail.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentDetail - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Text"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DetailID, ""); - //AuthorizationRules.AllowRead(ItemType, ""); - //AuthorizationRules.AllowWrite(ItemType, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ContentDetail New(int itemType, string text) - { - return new ContentDetail(itemType, text); - } - internal static ContentDetail Get(SafeDataReader dr) - { - return new ContentDetail(dr); - } - public ContentDetail() - { - MarkAsChild(); - _DetailID = Detail.NextDetailID; - _DTS = _ContentDetailExtension.DefaultDTS; - _UserID = _ContentDetailExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentDetail(int itemType, string text) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ContentDetailExtension.DefaultDTS; - _UserID = _ContentDetailExtension.DefaultUserID; - _ItemType = itemType; - _Text = text; - ValidationRules.CheckRules(); - } - internal ContentDetail(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentDetail.FetchDR", GetHashCode()); - try - { - _DetailID = dr.GetInt32("DetailID"); - _ItemType = dr.GetInt32("ItemType"); - _Text = dr.GetString("Text"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentDetail.FetchDR", ex); - throw new DbCslaException("ContentDetail.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Detail.Add(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Detail.Update(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Detail.Remove(cn, _DetailID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentDetailExtension _ContentDetailExtension = new ContentDetailExtension(); - [Serializable()] - partial class ContentDetailExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentDetailConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentDetail) - { - // Return the ToString value - return ((ContentDetail)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentDetail Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentDetailConverter))] + public partial class ContentDetail : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _DetailID; + [System.ComponentModel.DataObjectField(true, true)] + public int DetailID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDetail != null) _DetailID = _MyDetail.DetailID; + return _DetailID; + } + } + private Detail _MyDetail; + [System.ComponentModel.DataObjectField(true, true)] + public Detail MyDetail + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDetail == null && _DetailID != 0) _MyDetail = Detail.Get(_DetailID); + return _MyDetail; + } + } + private int _ItemType; + public int ItemType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemType != value) + { + _ItemType = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check ContentDetail.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentDetail + protected override object GetIdValue() + { + return _DetailID; + } + // TODO: Replace base ContentDetail.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentDetail + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Text"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(DetailID, ""); + //AuthorizationRules.AllowRead(ItemType, ""); + //AuthorizationRules.AllowWrite(ItemType, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ContentDetail New(int itemType, string text) + { + return new ContentDetail(itemType, text); + } + internal static ContentDetail Get(SafeDataReader dr) + { + return new ContentDetail(dr); + } + public ContentDetail() + { + MarkAsChild(); + _DetailID = Detail.NextDetailID; + _DTS = _ContentDetailExtension.DefaultDTS; + _UserID = _ContentDetailExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentDetail(int itemType, string text) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ContentDetailExtension.DefaultDTS; + _UserID = _ContentDetailExtension.DefaultUserID; + _ItemType = itemType; + _Text = text; + ValidationRules.CheckRules(); + } + internal ContentDetail(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentDetail.FetchDR", GetHashCode()); + try + { + _DetailID = dr.GetInt32("DetailID"); + _ItemType = dr.GetInt32("ItemType"); + _Text = dr.GetString("Text"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentDetail.FetchDR", ex); + throw new DbCslaException("ContentDetail.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Detail.Add(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Detail.Update(cn, ref _DetailID, myContent, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Detail.Remove(cn, _DetailID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentDetailExtension _ContentDetailExtension = new ContentDetailExtension(); + [Serializable()] + partial class ContentDetailExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentDetailConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentDetail) + { + // Return the ToString value + return ((ContentDetail)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentInfo.cs index c2aad309..13462b31 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentInfo.cs @@ -19,667 +19,644 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ContentInfoEvent(object sender); - /// - /// ContentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentInfoConverter))] - public partial class ContentInfo : ReadOnlyBase, IDisposable - { - public event ContentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ContentInfo contentInfo) - { - if (!_CacheList.Contains(contentInfo)) _CacheList.Add(contentInfo); // In AddToCache - } - protected static void RemoveFromCache(ContentInfo contentInfo) - { - while (_CacheList.Contains(contentInfo)) _CacheList.Remove(contentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ContentInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ContentInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(ContentInfoList lst) - { - foreach (ContentInfo item in lst) AddToCache(item); - } - protected static ContentInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Content _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - return _ContentID; - } - } - private string _Number = string.Empty; - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - } - private int? _Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private FormatInfo _MyFormat; - public FormatInfo MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); - return _MyFormat; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ContentDetailCount = 0; - /// - /// Count of ContentDetails for this Content - /// - public int ContentDetailCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetailCount", true); - return _ContentDetailCount; - } - } - private DetailInfoList _ContentDetails = null; - [TypeConverter(typeof(DetailInfoListConverter))] - public DetailInfoList ContentDetails - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentDetails", true); - if (_ContentDetailCount < 0 || (_ContentDetailCount > 0 && _ContentDetails == null)) - _ContentDetails = DetailInfoList.GetByContentID(_ContentID); - if (_ContentDetailCount < 0) - _ContentDetailCount = _ContentDetails.Count; - return _ContentDetails; - } - } - public void RefreshContentDetails() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentDetailCount = -1; // This will cause the data to be requeried - } - private int _ContentEntryCount = 0; - /// - /// Count of ContentEntries for this Content - /// - public int ContentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentEntryCount", true); - return _ContentEntryCount; - } - } - private EntryInfo _MyEntry = null; - [TypeConverter(typeof(EntryInfoConverter))] - public EntryInfo MyEntry - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyEntry", true); - if (_ContentEntryCount != 0 && _MyEntry == null) - { - _MyEntry = EntryInfo.Get(_ContentID); - _ContentEntryCount = _MyEntry == null ? 0 : 1; - } - return _MyEntry; - } - } - private int _ContentItemCount = 0; - /// - /// Count of ContentItems for this Content - /// - public int ContentItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItemCount", true); - return _ContentItemCount; - } - } - private ItemInfoList _ContentItems = null; - [TypeConverter(typeof(ItemInfoListConverter))] - public ItemInfoList ContentItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentItems", true); - if (_ContentItemCount < 0 || (_ContentItemCount > 0 && _ContentItems == null)) - _ContentItems = ItemInfoList.GetByContentID(_ContentID); - if (_ContentItemCount < 0) - _ContentItemCount = _ContentItems.Count; - return _ContentItems; - } - } - public void RefreshContentItems() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentItemCount = -1; // This will cause the data to be requeried - } - private int _ContentPartCount = 0; - /// - /// Count of ContentParts for this Content - /// - public int ContentPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentPartCount", true); - return _ContentPartCount; - } - } - private PartInfoList _ContentParts = null; - [TypeConverter(typeof(PartInfoListConverter))] - public PartInfoList ContentParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentParts", true); - if (_ContentPartCount < 0 || (_ContentPartCount > 0 && _ContentParts == null)) - _ContentParts = PartInfoList.GetByContentID(_ContentID); - if (_ContentPartCount < 0) - _ContentPartCount = _ContentParts.Count; - return _ContentParts; - } - } - public void RefreshContentParts() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentPartCount = -1; // This will cause the data to be requeried - } - private int _ContentRoUsageCount = 0; - /// - /// Count of ContentRoUsages for this Content - /// - public int ContentRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsageCount", true); - return _ContentRoUsageCount; - } - } - private RoUsageInfoList _ContentRoUsages = null; - [TypeConverter(typeof(RoUsageInfoListConverter))] - public RoUsageInfoList ContentRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentRoUsages", true); - if (_ContentRoUsageCount < 0 || (_ContentRoUsageCount > 0 && _ContentRoUsages == null)) - _ContentRoUsages = RoUsageInfoList.GetByContentID(_ContentID); - if (_ContentRoUsageCount < 0) - _ContentRoUsageCount = _ContentRoUsages.Count; - return _ContentRoUsages; - } - } - public void RefreshContentRoUsages() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentRoUsageCount = -1; // This will cause the data to be requeried - } - private int _ContentTransitionCount = 0; - /// - /// Count of ContentTransitions for this Content - /// - public int ContentTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitionCount", true); - return _ContentTransitionCount; - } - } - private TransitionInfoList _ContentTransitions = null; - [TypeConverter(typeof(TransitionInfoListConverter))] - public TransitionInfoList ContentTransitions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentTransitions", true); - if (_ContentTransitionCount < 0 || (_ContentTransitionCount > 0 && _ContentTransitions == null)) - _ContentTransitions = TransitionInfoList.GetByFromID(_ContentID); - if (_ContentTransitionCount < 0) - _ContentTransitionCount = _ContentTransitions.Count; - return _ContentTransitions; - } - } - public void RefreshContentTransitions() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) - foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) - tmp._ContentTransitionCount = -1; // This will cause the data to be requeried - } - private int _ContentZContentCount = 0; - /// - /// Count of ContentZContents for this Content - /// - public int ContentZContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentZContentCount", true); - return _ContentZContentCount; - } - } - private ZContentInfo _MyZContent = null; - [TypeConverter(typeof(ZContentInfoConverter))] - public ZContentInfo MyZContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZContent", true); - if (_ContentZContentCount != 0 && _MyZContent == null) - { - _MyZContent = ZContentInfo.Get(_ContentID); - _ContentZContentCount = _MyZContent == null ? 0 : 1; - } - return _MyZContent; - } - } - // TODO: Replace base ContentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ContentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentInfo - protected override object GetIdValue() - { - return _ContentID; - } - #endregion - #region Factory Methods - private static int _ContentInfoUnique = 0; - private static int ContentInfoUnique - { get { return ++_ContentInfoUnique; } } - private int _MyContentInfoUnique = ContentInfoUnique; - public int MyContentInfoUnique - { get { return _MyContentInfoUnique; } } - protected ContentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listContentInfo.Contains(this)) listContentInfo.Remove(this); // Remove the item from the list - if (listContentInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - public virtual Content Get() - { - return _Editable = Content.Get(_ContentID); - } - public static void Refresh(Content tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Content tmp) - { - _Number = tmp.Number; - _Text = tmp.Text; - _Type = tmp.Type; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) MyFormat.RefreshFormatContents(); // 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.RefreshFormatContents(); // Update List for new value - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ContentInfoExtension.Refresh(this); - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - if(_MyEntry != null) - { - _MyEntry.Dispose();// Dispose related value - _MyEntry = null;// Reset related value - } - _ContentEntryCount = -1;// Reset Count - if(_MyZContent != null) - { - _MyZContent.Dispose();// Dispose related value - _MyZContent = null;// Reset related value - } - _ContentZContentCount = -1;// Reset Count - OnChange();// raise an event - } - public static void Refresh(FormatContent tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FormatContent tmp) - { - _Number = tmp.Number; - _Text = tmp.Text; - _Type = tmp.Type; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ContentInfoExtension.Refresh(this); - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - if(_MyEntry != null) - { - _MyEntry.Dispose();// Dispose related value - _MyEntry = null;// Reset related value - } - _ContentEntryCount = -1;// Reset Count - if(_MyZContent != null) - { - _MyZContent.Dispose();// Dispose related value - _MyZContent = null;// Reset related value - } - _ContentZContentCount = -1;// Reset Count - OnChange();// raise an event - } - public static ContentInfo Get(int contentID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Content"); - try - { - ContentInfo tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ContentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ContentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ContentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.Constructor", ex); - throw new DbCslaException("ContentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _ContentDetailCount = dr.GetInt32("DetailCount"); - _ContentEntryCount = dr.GetInt32("EntryCount"); - _ContentItemCount = dr.GetInt32("ItemCount"); - _ContentPartCount = dr.GetInt32("PartCount"); - _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); - _ContentTransitionCount = dr.GetInt32("TransitionCount"); - _ContentZContentCount = dr.GetInt32("ZContentCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ContentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ContentInfoExtension _ContentInfoExtension = new ContentInfoExtension(); - [Serializable()] - partial class ContentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ContentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ContentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentInfo) - { - // Return the ToString value - return ((ContentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ContentInfoEvent(object sender); + /// + /// ContentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentInfoConverter))] + public partial class ContentInfo : ReadOnlyBase, IDisposable + { + public event ContentInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ContentInfo contentInfo) + { + if (!_CacheList.Contains(contentInfo)) _CacheList.Add(contentInfo); // In AddToCache + } + protected static void RemoveFromCache(ContentInfo contentInfo) + { + while (_CacheList.Contains(contentInfo)) _CacheList.Remove(contentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ContentInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ContentInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(ContentInfoList lst) + { + foreach (ContentInfo item in lst) AddToCache(item); + } + protected static ContentInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Content _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentID; + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + } + private int? _Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private FormatInfo _MyFormat; + public FormatInfo MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); + return _MyFormat; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ContentDetailCount = 0; + /// + /// Count of ContentDetails for this Content + /// + public int ContentDetailCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentDetailCount; + } + } + private DetailInfoList _ContentDetails = null; + [TypeConverter(typeof(DetailInfoListConverter))] + public DetailInfoList ContentDetails + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentDetailCount < 0 || (_ContentDetailCount > 0 && _ContentDetails == null)) + _ContentDetails = DetailInfoList.GetByContentID(_ContentID); + if (_ContentDetailCount < 0) + _ContentDetailCount = _ContentDetails.Count; + return _ContentDetails; + } + } + public void RefreshContentDetails() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentDetailCount = -1; // This will cause the data to be requeried + } + private int _ContentEntryCount = 0; + /// + /// Count of ContentEntries for this Content + /// + public int ContentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentEntryCount; + } + } + private EntryInfo _MyEntry = null; + [TypeConverter(typeof(EntryInfoConverter))] + public EntryInfo MyEntry + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentEntryCount != 0 && _MyEntry == null) + { + _MyEntry = EntryInfo.Get(_ContentID); + _ContentEntryCount = _MyEntry == null ? 0 : 1; + } + return _MyEntry; + } + } + private int _ContentItemCount = 0; + /// + /// Count of ContentItems for this Content + /// + public int ContentItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentItemCount; + } + } + private ItemInfoList _ContentItems = null; + [TypeConverter(typeof(ItemInfoListConverter))] + public ItemInfoList ContentItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentItemCount < 0 || (_ContentItemCount > 0 && _ContentItems == null)) + _ContentItems = ItemInfoList.GetByContentID(_ContentID); + if (_ContentItemCount < 0) + _ContentItemCount = _ContentItems.Count; + return _ContentItems; + } + } + public void RefreshContentItems() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentItemCount = -1; // This will cause the data to be requeried + } + private int _ContentPartCount = 0; + /// + /// Count of ContentParts for this Content + /// + public int ContentPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentPartCount; + } + } + private PartInfoList _ContentParts = null; + [TypeConverter(typeof(PartInfoListConverter))] + public PartInfoList ContentParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentPartCount < 0 || (_ContentPartCount > 0 && _ContentParts == null)) + _ContentParts = PartInfoList.GetByContentID(_ContentID); + if (_ContentPartCount < 0) + _ContentPartCount = _ContentParts.Count; + return _ContentParts; + } + } + public void RefreshContentParts() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentPartCount = -1; // This will cause the data to be requeried + } + private int _ContentRoUsageCount = 0; + /// + /// Count of ContentRoUsages for this Content + /// + public int ContentRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentRoUsageCount; + } + } + private RoUsageInfoList _ContentRoUsages = null; + [TypeConverter(typeof(RoUsageInfoListConverter))] + public RoUsageInfoList ContentRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentRoUsageCount < 0 || (_ContentRoUsageCount > 0 && _ContentRoUsages == null)) + _ContentRoUsages = RoUsageInfoList.GetByContentID(_ContentID); + if (_ContentRoUsageCount < 0) + _ContentRoUsageCount = _ContentRoUsages.Count; + return _ContentRoUsages; + } + } + public void RefreshContentRoUsages() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentRoUsageCount = -1; // This will cause the data to be requeried + } + private int _ContentTransitionCount = 0; + /// + /// Count of ContentTransitions for this Content + /// + public int ContentTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentTransitionCount; + } + } + private TransitionInfoList _ContentTransitions = null; + [TypeConverter(typeof(TransitionInfoListConverter))] + public TransitionInfoList ContentTransitions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentTransitionCount < 0 || (_ContentTransitionCount > 0 && _ContentTransitions == null)) + _ContentTransitions = TransitionInfoList.GetByFromID(_ContentID); + if (_ContentTransitionCount < 0) + _ContentTransitionCount = _ContentTransitions.Count; + return _ContentTransitions; + } + } + public void RefreshContentTransitions() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ContentID.ToString())) + foreach (ContentInfo tmp in _CacheByPrimaryKey[_ContentID.ToString()]) + tmp._ContentTransitionCount = -1; // This will cause the data to be requeried + } + private int _ContentZContentCount = 0; + /// + /// Count of ContentZContents for this Content + /// + public int ContentZContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ContentZContentCount; + } + } + private ZContentInfo _MyZContent = null; + [TypeConverter(typeof(ZContentInfoConverter))] + public ZContentInfo MyZContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ContentZContentCount != 0 && _MyZContent == null) + { + _MyZContent = ZContentInfo.Get(_ContentID); + _ContentZContentCount = _MyZContent == null ? 0 : 1; + } + return _MyZContent; + } + } + // TODO: Replace base ContentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ContentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentInfo + protected override object GetIdValue() + { + return _ContentID; + } + #endregion + #region Factory Methods + private static int _ContentInfoUnique = 0; + private static int ContentInfoUnique + { get { return ++_ContentInfoUnique; } } + private int _MyContentInfoUnique = ContentInfoUnique; + public int MyContentInfoUnique + { get { return _MyContentInfoUnique; } } + protected ContentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listContentInfo.Contains(this)) listContentInfo.Remove(this); // Remove the item from the list + if (listContentInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + public virtual Content Get() + { + return _Editable = Content.Get(_ContentID); + } + public static void Refresh(Content tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Content tmp) + { + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) MyFormat.RefreshFormatContents(); // 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.RefreshFormatContents(); // Update List for new value + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ContentInfoExtension.Refresh(this); + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + if (_MyEntry != null) + { + _MyEntry.Dispose();// Dispose related value + _MyEntry = null;// Reset related value + } + _ContentEntryCount = -1;// Reset Count + if (_MyZContent != null) + { + _MyZContent.Dispose();// Dispose related value + _MyZContent = null;// Reset related value + } + _ContentZContentCount = -1;// Reset Count + OnChange();// raise an event + } + public static void Refresh(FormatContent tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ContentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FormatContent tmp) + { + _Number = tmp.Number; + _Text = tmp.Text; + _Type = tmp.Type; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ContentInfoExtension.Refresh(this); + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + if (_MyEntry != null) + { + _MyEntry.Dispose();// Dispose related value + _MyEntry = null;// Reset related value + } + _ContentEntryCount = -1;// Reset Count + if (_MyZContent != null) + { + _MyZContent.Dispose();// Dispose related value + _MyZContent = null;// Reset related value + } + _ContentZContentCount = -1;// Reset Count + OnChange();// raise an event + } + public static ContentInfo Get(int contentID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Content"); + try + { + ContentInfo tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ContentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ContentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.Constructor", ex); + throw new DbCslaException("ContentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _ContentDetailCount = dr.GetInt32("DetailCount"); + _ContentEntryCount = dr.GetInt32("EntryCount"); + _ContentItemCount = dr.GetInt32("ItemCount"); + _ContentPartCount = dr.GetInt32("PartCount"); + _ContentRoUsageCount = dr.GetInt32("RoUsageCount"); + _ContentTransitionCount = dr.GetInt32("TransitionCount"); + _ContentZContentCount = dr.GetInt32("ZContentCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ContentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ContentInfoExtension _ContentInfoExtension = new ContentInfoExtension(); + [Serializable()] + partial class ContentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ContentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ContentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentInfo) + { + // Return the ToString value + return ((ContentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentItem.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentItem.cs index 13580ade..3b7aeb06 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentItem.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentItem.cs @@ -19,358 +19,349 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentItem Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentItemConverter))] - public partial class ContentItem : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ItemID; - [System.ComponentModel.DataObjectField(true, true)] - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - [System.ComponentModel.DataObjectField(true, true)] - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; - return _PreviousID; - } - } - private Item _MyPrevious; - public Item MyPrevious - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPrevious", true); - if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); - return _MyPrevious; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyPrevious", true); - if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyPrevious = value; - _PreviousID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check ContentItem.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentItem - protected override object GetIdValue() - { - return _ItemID; - } - // TODO: Replace base ContentItem.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentItem - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(PreviousID, ""); - //AuthorizationRules.AllowWrite(PreviousID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ContentItem New() - { - return new ContentItem(); - } - internal static ContentItem Get(SafeDataReader dr) - { - return new ContentItem(dr); - } - public ContentItem() - { - MarkAsChild(); - _ItemID = Item.NextItemID; - _DTS = _ContentItemExtension.DefaultDTS; - _UserID = _ContentItemExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - internal ContentItem(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentItem.FetchDR", GetHashCode()); - try - { - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentItem.FetchDR", ex); - throw new DbCslaException("ContentItem.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Item.Add(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Item.Update(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Item.Remove(cn, _ItemID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentItemExtension _ContentItemExtension = new ContentItemExtension(); - [Serializable()] - partial class ContentItemExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentItemConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentItem) - { - // Return the ToString value - return ((ContentItem)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentItem Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentItemConverter))] + public partial class ContentItem : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ItemID; + [System.ComponentModel.DataObjectField(true, true)] + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + [System.ComponentModel.DataObjectField(true, true)] + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; + return _PreviousID; + } + } + private Item _MyPrevious; + public Item MyPrevious + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); + return _MyPrevious; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyPrevious = value; + _PreviousID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check ContentItem.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentItem + protected override object GetIdValue() + { + return _ItemID; + } + // TODO: Replace base ContentItem.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentItem + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(PreviousID, ""); + //AuthorizationRules.AllowWrite(PreviousID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ContentItem New() + { + return new ContentItem(); + } + internal static ContentItem Get(SafeDataReader dr) + { + return new ContentItem(dr); + } + public ContentItem() + { + MarkAsChild(); + _ItemID = Item.NextItemID; + _DTS = _ContentItemExtension.DefaultDTS; + _UserID = _ContentItemExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + internal ContentItem(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentItem.FetchDR", GetHashCode()); + try + { + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentItem.FetchDR", ex); + throw new DbCslaException("ContentItem.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Item.Add(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Item.Update(cn, ref _ItemID, Item.Get((int)_PreviousID), myContent, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Item.Remove(cn, _ItemID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentItemExtension _ContentItemExtension = new ContentItemExtension(); + [Serializable()] + partial class ContentItemExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentItemConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentItem) + { + // Return the ToString value + return ((ContentItem)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentPart.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentPart.cs index 02f33bbe..71935b96 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentPart.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentPart.cs @@ -19,416 +19,404 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentPart Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentPartConverter))] - public partial class ContentPart : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if (_MyItem != value) - { - _MyItem = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int? _Item_PreviousID; - public int? Item_PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_PreviousID", true); - return _Item_PreviousID; - } - } - private int _Item_ContentID; - public int Item_ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ContentID", true); - return _Item_ContentID; - } - } - private DateTime _Item_DTS = new DateTime(); - public DateTime Item_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_DTS", true); - return _Item_DTS; - } - } - private string _Item_UserID = string.Empty; - public string Item_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_UserID", true); - return _Item_UserID; - } - } - // TODO: Check ContentPart.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentPart - protected override object GetIdValue() - { - return _FromType; - } - // TODO: Replace base ContentPart.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentPart - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemRequired, "MyItem"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyItemRequired(ContentPart target, Csla.Validation.RuleArgs e) - { - if (target._ItemID == 0 && target._MyItem == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(FromType, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ContentPart New(int fromType, Item myItem) - { - return new ContentPart(fromType, myItem); - } - internal static ContentPart Get(SafeDataReader dr) - { - return new ContentPart(dr); - } - public ContentPart() - { - MarkAsChild(); + /// + /// ContentPart Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentPartConverter))] + public partial class ContentPart : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItem != value) + { + _MyItem = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int? _Item_PreviousID; + public int? Item_PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_PreviousID; + } + } + private int _Item_ContentID; + public int Item_ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ContentID; + } + } + private DateTime _Item_DTS = new DateTime(); + public DateTime Item_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_DTS; + } + } + private string _Item_UserID = string.Empty; + public string Item_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_UserID; + } + } + // TODO: Check ContentPart.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentPart + protected override object GetIdValue() + { + return _FromType; + } + // TODO: Replace base ContentPart.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentPart + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyItem == null ? false : _MyItem.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemRequired, "MyItem"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyItemRequired(ContentPart target, Csla.Validation.RuleArgs e) + { + if (target._ItemID == 0 && target._MyItem == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(FromType, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ContentPart New(int fromType, Item myItem) + { + return new ContentPart(fromType, myItem); + } + internal static ContentPart Get(SafeDataReader dr) + { + return new ContentPart(dr); + } + public ContentPart() + { + MarkAsChild(); - _DTS = _ContentPartExtension.DefaultDTS; - _UserID = _ContentPartExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentPart(int fromType, Item myItem) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ContentPartExtension.DefaultDTS; - _UserID = _ContentPartExtension.DefaultUserID; - _FromType = fromType; - _MyItem = myItem; - ValidationRules.CheckRules(); - } - internal ContentPart(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentPart.FetchDR", GetHashCode()); - try - { - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Item_PreviousID = (int?)dr.GetValue("Item_PreviousID"); - _Item_ContentID = dr.GetInt32("Item_ContentID"); - _Item_DTS = dr.GetDateTime("Item_DTS"); - _Item_UserID = dr.GetString("Item_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentPart.FetchDR", ex); - throw new DbCslaException("ContentPart.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Part.Update(cn, myContent, _FromType, _MyItem, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Part.Remove(cn, myContent.ContentID, _FromType); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentPartExtension _ContentPartExtension = new ContentPartExtension(); - [Serializable()] - partial class ContentPartExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentPartConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentPart) - { - // Return the ToString value - return ((ContentPart)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _ContentPartExtension.DefaultDTS; + _UserID = _ContentPartExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentPart(int fromType, Item myItem) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ContentPartExtension.DefaultDTS; + _UserID = _ContentPartExtension.DefaultUserID; + _FromType = fromType; + _MyItem = myItem; + ValidationRules.CheckRules(); + } + internal ContentPart(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentPart.FetchDR", GetHashCode()); + try + { + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Item_PreviousID = (int?)dr.GetValue("Item_PreviousID"); + _Item_ContentID = dr.GetInt32("Item_ContentID"); + _Item_DTS = dr.GetDateTime("Item_DTS"); + _Item_UserID = dr.GetString("Item_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentPart.FetchDR", ex); + throw new DbCslaException("ContentPart.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Part.Add(cn, myContent, _FromType, _MyItem, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Part.Update(cn, myContent, _FromType, _MyItem, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Part.Remove(cn, myContent.ContentID, _FromType); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentPartExtension _ContentPartExtension = new ContentPartExtension(); + [Serializable()] + partial class ContentPartExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentPartConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentPart) + { + // Return the ToString value + return ((ContentPart)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentRoUsage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentRoUsage.cs index 1bc247e7..24726558 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentRoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentRoUsage.cs @@ -19,509 +19,491 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentRoUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentRoUsageConverter))] - public partial class ContentRoUsage : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; - return _ROUsageID; - } - } - private RoUsage _MyRoUsage; - [System.ComponentModel.DataObjectField(true, true)] - public RoUsage MyRoUsage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRoUsage", true); - if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); - return _MyRoUsage; - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - PropertyHasChanged(); - } - } - } - private string _RODb_ROName = string.Empty; - /// - /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion - /// - public string RODb_ROName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_ROName", true); - return _RODb_ROName; - } - } - private string _RODb_FolderPath = string.Empty; - /// - /// Path to the RO database - /// - public string RODb_FolderPath - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_FolderPath", true); - return _RODb_FolderPath; - } - } - private string _RODb_DBConnectionString = string.Empty; - /// - /// Connection String - Default could just be the full path and name of the database - /// - public string RODb_DBConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_DBConnectionString", true); - return _RODb_DBConnectionString; - } - } - private DateTime _RODb_DTS = new DateTime(); - public DateTime RODb_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_DTS", true); - return _RODb_DTS; - } - } - private string _RODb_UserID = string.Empty; - public string RODb_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODb_UserID", true); - return _RODb_UserID; - } - } - // TODO: Check ContentRoUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentRoUsage - protected override object GetIdValue() - { - return _ROUsageID; - } - // TODO: Replace base ContentRoUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentRoUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyRODb == null ? false : _MyRODb.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - // TODO: Add other validation rules - } - private static bool MyRODbRequired(ContentRoUsage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROUsageID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ContentRoUsage New(string roid, RODb myRODb) - { - return new ContentRoUsage(roid, myRODb); - } - internal static ContentRoUsage Get(SafeDataReader dr) - { - return new ContentRoUsage(dr); - } - public ContentRoUsage() - { - MarkAsChild(); - _ROUsageID = RoUsage.NextROUsageID; - _DTS = _ContentRoUsageExtension.DefaultDTS; - _UserID = _ContentRoUsageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentRoUsage(string roid, RODb myRODb) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ContentRoUsageExtension.DefaultDTS; - _UserID = _ContentRoUsageExtension.DefaultUserID; - _ROID = roid; - _MyRODb = myRODb; - ValidationRules.CheckRules(); - } - internal ContentRoUsage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentRoUsage.FetchDR", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbID = dr.GetInt32("RODbID"); - _RODb_ROName = dr.GetString("RODb_ROName"); - _RODb_FolderPath = dr.GetString("RODb_FolderPath"); - _RODb_DBConnectionString = dr.GetString("RODb_DBConnectionString"); - _RODb_DTS = dr.GetDateTime("RODb_DTS"); - _RODb_UserID = dr.GetString("RODb_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentRoUsage.FetchDR", ex); - throw new DbCslaException("ContentRoUsage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Add(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, _MyRODb); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Update(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _MyRODb); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - RoUsage.Remove(cn, _ROUsageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentRoUsageExtension _ContentRoUsageExtension = new ContentRoUsageExtension(); - [Serializable()] - partial class ContentRoUsageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultContentID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentRoUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentRoUsage) - { - // Return the ToString value - return ((ContentRoUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentRoUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentRoUsageConverter))] + public partial class ContentRoUsage : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; + return _ROUsageID; + } + } + private RoUsage _MyRoUsage; + [System.ComponentModel.DataObjectField(true, true)] + public RoUsage MyRoUsage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); + return _MyRoUsage; + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + PropertyHasChanged(); + } + } + } + private string _RODb_ROName = string.Empty; + /// + /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion + /// + public string RODb_ROName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_ROName; + } + } + private string _RODb_FolderPath = string.Empty; + /// + /// Path to the RO database + /// + public string RODb_FolderPath + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_FolderPath; + } + } + private string _RODb_DBConnectionString = string.Empty; + /// + /// Connection String - Default could just be the full path and name of the database + /// + public string RODb_DBConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_DBConnectionString; + } + } + private DateTime _RODb_DTS = new DateTime(); + public DateTime RODb_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_DTS; + } + } + private string _RODb_UserID = string.Empty; + public string RODb_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODb_UserID; + } + } + // TODO: Check ContentRoUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentRoUsage + protected override object GetIdValue() + { + return _ROUsageID; + } + // TODO: Replace base ContentRoUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentRoUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyRODb == null ? false : _MyRODb.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + // TODO: Add other validation rules + } + private static bool MyRODbRequired(ContentRoUsage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROUsageID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ContentRoUsage New(string roid, RODb myRODb) + { + return new ContentRoUsage(roid, myRODb); + } + internal static ContentRoUsage Get(SafeDataReader dr) + { + return new ContentRoUsage(dr); + } + public ContentRoUsage() + { + MarkAsChild(); + _ROUsageID = RoUsage.NextROUsageID; + _DTS = _ContentRoUsageExtension.DefaultDTS; + _UserID = _ContentRoUsageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentRoUsage(string roid, RODb myRODb) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ContentRoUsageExtension.DefaultDTS; + _UserID = _ContentRoUsageExtension.DefaultUserID; + _ROID = roid; + _MyRODb = myRODb; + ValidationRules.CheckRules(); + } + internal ContentRoUsage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentRoUsage.FetchDR", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbID = dr.GetInt32("RODbID"); + _RODb_ROName = dr.GetString("RODb_ROName"); + _RODb_FolderPath = dr.GetString("RODb_FolderPath"); + _RODb_DBConnectionString = dr.GetString("RODb_DBConnectionString"); + _RODb_DTS = dr.GetDateTime("RODb_DTS"); + _RODb_UserID = dr.GetString("RODb_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentRoUsage.FetchDR", ex); + throw new DbCslaException("ContentRoUsage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Add(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, _MyRODb); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, myContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _MyRODb); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + RoUsage.Remove(cn, _ROUsageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentRoUsageExtension _ContentRoUsageExtension = new ContentRoUsageExtension(); + [Serializable()] + partial class ContentRoUsageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultContentID + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentRoUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentRoUsage) + { + // Return the ToString value + return ((ContentRoUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentTransition.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentTransition.cs index 88fcfde7..68616915 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentTransition.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ContentTransition.cs @@ -19,578 +19,554 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ContentTransition Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ContentTransitionConverter))] - public partial class ContentTransition : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private Item _MyItemToID; - public Item MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); - return _MyItemToID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemToID", true); - if (_MyItemToID != value) - { - _MyItemToID = value; - PropertyHasChanged(); - } - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private Item _MyItemRangeID; - public Item MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); - return _MyItemRangeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemRangeID", true); - if (_MyItemRangeID != value) - { - _MyItemRangeID = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int? _Item_RangeID_PreviousID; - public int? Item_RangeID_PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_PreviousID", true); - return _Item_RangeID_PreviousID; - } - } - private int _Item_RangeID_ContentID; - public int Item_RangeID_ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_ContentID", true); - return _Item_RangeID_ContentID; - } - } - private DateTime _Item_RangeID_DTS = new DateTime(); - public DateTime Item_RangeID_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_DTS", true); - return _Item_RangeID_DTS; - } - } - private string _Item_RangeID_UserID = string.Empty; - public string Item_RangeID_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_RangeID_UserID", true); - return _Item_RangeID_UserID; - } - } - private int? _Item_ToID_PreviousID; - public int? Item_ToID_PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_PreviousID", true); - return _Item_ToID_PreviousID; - } - } - private int _Item_ToID_ContentID; - public int Item_ToID_ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_ContentID", true); - return _Item_ToID_ContentID; - } - } - private DateTime _Item_ToID_DTS = new DateTime(); - public DateTime Item_ToID_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_DTS", true); - return _Item_ToID_DTS; - } - } - private string _Item_ToID_UserID = string.Empty; - public string Item_ToID_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Item_ToID_UserID", true); - return _Item_ToID_UserID; - } - } - // TODO: Check ContentTransition.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ContentTransition - protected override object GetIdValue() - { - return _TransitionID; - } - // TODO: Replace base ContentTransition.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ContentTransition - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyItemToID == null ? false : _MyItemToID.IsDirty) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyItemToID == null ? true : _MyItemToID.IsValid) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); - ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyItemToIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) - { - if (target._ToID == 0 && target._MyItemToID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyItemRangeIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) - { - if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(TransitionID, ""); - //AuthorizationRules.AllowRead(ToID, ""); - //AuthorizationRules.AllowWrite(ToID, ""); - //AuthorizationRules.AllowRead(RangeID, ""); - //AuthorizationRules.AllowWrite(RangeID, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ContentTransition New(Item myItemToID, Item myItemRangeID) - { - return new ContentTransition(myItemToID, myItemRangeID); - } - internal static ContentTransition Get(SafeDataReader dr) - { - return new ContentTransition(dr); - } - public ContentTransition() - { - MarkAsChild(); - _TransitionID = Transition.NextTransitionID; - _TranType = _ContentTransitionExtension.DefaultTranType; - _DTS = _ContentTransitionExtension.DefaultDTS; - _UserID = _ContentTransitionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ContentTransition(Item myItemToID, Item myItemRangeID) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _TranType = _ContentTransitionExtension.DefaultTranType; - _DTS = _ContentTransitionExtension.DefaultDTS; - _UserID = _ContentTransitionExtension.DefaultUserID; - _MyItemToID = myItemToID; - _MyItemRangeID = myItemRangeID; - ValidationRules.CheckRules(); - } - internal ContentTransition(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentTransition.FetchDR", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _ToID = dr.GetInt32("ToID"); - _RangeID = dr.GetInt32("RangeID"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Item_RangeID_PreviousID = (int?)dr.GetValue("Item_RangeID_PreviousID"); - _Item_RangeID_ContentID = dr.GetInt32("Item_RangeID_ContentID"); - _Item_RangeID_DTS = dr.GetDateTime("Item_RangeID_DTS"); - _Item_RangeID_UserID = dr.GetString("Item_RangeID_UserID"); - _Item_ToID_PreviousID = (int?)dr.GetValue("Item_ToID_PreviousID"); - _Item_ToID_ContentID = dr.GetInt32("Item_ToID_ContentID"); - _Item_ToID_DTS = dr.GetDateTime("Item_ToID_DTS"); - _Item_ToID_UserID = dr.GetString("Item_ToID_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentTransition.FetchDR", ex); - throw new DbCslaException("ContentTransition.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Add(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Content myContent) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Update(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Content myContent) - { - // 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"]; - Transition.Remove(cn, _TransitionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ContentTransitionExtension _ContentTransitionExtension = new ContentTransitionExtension(); - [Serializable()] - partial class ContentTransitionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ContentTransitionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ContentTransition) - { - // Return the ToString value - return ((ContentTransition)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ContentTransition Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ContentTransitionConverter))] + public partial class ContentTransition : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private Item _MyItemToID; + public Item MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); + return _MyItemToID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemToID != value) + { + _MyItemToID = value; + PropertyHasChanged(); + } + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private Item _MyItemRangeID; + public Item MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); + return _MyItemRangeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemRangeID != value) + { + _MyItemRangeID = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int? _Item_RangeID_PreviousID; + public int? Item_RangeID_PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_PreviousID; + } + } + private int _Item_RangeID_ContentID; + public int Item_RangeID_ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_ContentID; + } + } + private DateTime _Item_RangeID_DTS = new DateTime(); + public DateTime Item_RangeID_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_DTS; + } + } + private string _Item_RangeID_UserID = string.Empty; + public string Item_RangeID_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_RangeID_UserID; + } + } + private int? _Item_ToID_PreviousID; + public int? Item_ToID_PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_PreviousID; + } + } + private int _Item_ToID_ContentID; + public int Item_ToID_ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_ContentID; + } + } + private DateTime _Item_ToID_DTS = new DateTime(); + public DateTime Item_ToID_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_DTS; + } + } + private string _Item_ToID_UserID = string.Empty; + public string Item_ToID_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Item_ToID_UserID; + } + } + // TODO: Check ContentTransition.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ContentTransition + protected override object GetIdValue() + { + return _TransitionID; + } + // TODO: Replace base ContentTransition.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ContentTransition + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyItemToID == null ? false : _MyItemToID.IsDirty) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyItemToID == null ? true : _MyItemToID.IsValid) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); + ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyItemToIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) + { + if (target._ToID == 0 && target._MyItemToID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyItemRangeIDRequired(ContentTransition target, Csla.Validation.RuleArgs e) + { + if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(TransitionID, ""); + //AuthorizationRules.AllowRead(ToID, ""); + //AuthorizationRules.AllowWrite(ToID, ""); + //AuthorizationRules.AllowRead(RangeID, ""); + //AuthorizationRules.AllowWrite(RangeID, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ContentTransition New(Item myItemToID, Item myItemRangeID) + { + return new ContentTransition(myItemToID, myItemRangeID); + } + internal static ContentTransition Get(SafeDataReader dr) + { + return new ContentTransition(dr); + } + public ContentTransition() + { + MarkAsChild(); + _TransitionID = Transition.NextTransitionID; + _TranType = _ContentTransitionExtension.DefaultTranType; + _DTS = _ContentTransitionExtension.DefaultDTS; + _UserID = _ContentTransitionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ContentTransition(Item myItemToID, Item myItemRangeID) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _TranType = _ContentTransitionExtension.DefaultTranType; + _DTS = _ContentTransitionExtension.DefaultDTS; + _UserID = _ContentTransitionExtension.DefaultUserID; + _MyItemToID = myItemToID; + _MyItemRangeID = myItemRangeID; + ValidationRules.CheckRules(); + } + internal ContentTransition(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ContentTransition.FetchDR", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _ToID = dr.GetInt32("ToID"); + _RangeID = dr.GetInt32("RangeID"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Item_RangeID_PreviousID = (int?)dr.GetValue("Item_RangeID_PreviousID"); + _Item_RangeID_ContentID = dr.GetInt32("Item_RangeID_ContentID"); + _Item_RangeID_DTS = dr.GetDateTime("Item_RangeID_DTS"); + _Item_RangeID_UserID = dr.GetString("Item_RangeID_UserID"); + _Item_ToID_PreviousID = (int?)dr.GetValue("Item_ToID_PreviousID"); + _Item_ToID_ContentID = dr.GetInt32("Item_ToID_ContentID"); + _Item_ToID_DTS = dr.GetDateTime("Item_ToID_DTS"); + _Item_ToID_UserID = dr.GetString("Item_ToID_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ContentTransition.FetchDR", ex); + throw new DbCslaException("ContentTransition.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Add(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Content myContent) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Update(cn, ref _TransitionID, myContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Content myContent) + { + // 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"]; + Transition.Remove(cn, _TransitionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ContentTransitionExtension _ContentTransitionExtension = new ContentTransitionExtension(); + [Serializable()] + partial class ContentTransitionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ContentTransitionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ContentTransition) + { + // Return the ToString value + return ((ContentTransition)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Detail.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Detail.cs index d8330b0c..ddffe616 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Detail.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Detail.cs @@ -20,1023 +20,1009 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Detail Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DetailConverter))] - public partial class Detail : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDetails = new List(); - private void AddToRefreshList(List refreshDetails) - { - if (IsDirty) - refreshDetails.Add(this); - } - private void BuildRefreshList() - { - _RefreshDetails = new List(); - AddToRefreshList(_RefreshDetails); - } - private void ProcessRefreshList() - { - foreach (Detail tmp in _RefreshDetails) - { - DetailInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Detail detail) - { - if (!_CacheList.Contains(detail)) _CacheList.Add(detail); // In AddToCache - } - protected static void RemoveFromCache(Detail detail) - { - while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Detail tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString())) - { - _CacheByPrimaryKey[tmp.DetailID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Detail tmp in remove) - RemoveFromCache(tmp); - } - protected static Detail GetCachedByPrimaryKey(int detailID) - { - ConvertListToDictionary(); - string key = detailID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextDetailID = -1; - public static int NextDetailID - { - get { return _nextDetailID--; } - } - private int _DetailID; - [System.ComponentModel.DataObjectField(true, true)] - public int DetailID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DetailID", true); - return _DetailID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - PropertyHasChanged(); - } - } - } - private int _ItemType; - public int ItemType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemType", true); - return _ItemType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ItemType", true); - if (_ItemType != value) - { - _ItemType = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } - } - // TODO: Replace base Detail.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Detail - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Detail.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Detail - protected override object GetIdValue() - { - return _DetailID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Text"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _DetailExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _DetailExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyContentRequired(Detail target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DetailID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(ItemType, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(ItemType, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _DetailExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _DetailExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _DetailUnique = 0; - protected static int DetailUnique - { get { return ++_DetailUnique; } } - private int _MyDetailUnique = DetailUnique; - public int MyDetailUnique - { get { return _MyDetailUnique; } } - protected Detail() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) - { - List listDetail = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items - while (listDetail.Contains(this)) listDetail.Remove(this); // Remove the item from the list - if (listDetail.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list - } - } - public static Detail New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Detail"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.New", ex); - } - } - public static Detail New(Content myContent, int itemType, string text) - { - Detail tmp = Detail.New(); - tmp.MyContent = myContent; - tmp.ItemType = itemType; - tmp.Text = text; - return tmp; - } - public static Detail New(Content myContent, int itemType, string text, string config, DateTime dts, string userID) - { - Detail tmp = Detail.New(); - tmp.MyContent = myContent; - tmp.ItemType = itemType; - tmp.Text = text; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Detail MakeDetail(Content myContent, int itemType, string text, string config, DateTime dts, string userID) - { - Detail tmp = Detail.New(myContent, itemType, text, config, dts, userID); - if (tmp.IsSavable) - { - Detail tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Detail New(Content myContent, int itemType, string text, string config) - { - Detail tmp = Detail.New(); - tmp.MyContent = myContent; - tmp.ItemType = itemType; - tmp.Text = text; - tmp.Config = config; - return tmp; - } - public static Detail MakeDetail(Content myContent, int itemType, string text, string config) - { - Detail tmp = Detail.New(myContent, itemType, text, config); - if (tmp.IsSavable) - { - Detail tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(detailID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Detail - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.Get", ex); - } - } - public static Detail Get(SafeDataReader dr) - { - if (dr.Read()) return new Detail(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.Delete", ex); - } - } - 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(); - Detail detail = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(detail);//Refresh the item in AllList - ProcessRefreshList(); - return detail; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DetailID; - public int DetailID - { get { return _DetailID; } } - public PKCriteria(int detailID) - { - _DetailID = detailID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _DetailID = NextDetailID; - // Database Defaults - _DTS = _DetailExtension.DefaultDTS; - _UserID = _DetailExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.ReadData", GetHashCode()); - try - { - _DetailID = dr.GetInt32("DetailID"); - _ContentID = dr.GetInt32("ContentID"); - _ItemType = dr.GetInt32("ItemType"); - _Text = dr.GetString("Text"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Detail.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDetail"; - cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Detail.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Detail.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addDetail"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - detailID = (int)cm.Parameters["@newDetailID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Add", ex); - throw new DbCslaException("Detail.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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, _MyContent, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int detailID, Content myContent, int itemType, string text, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateDetail"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@DetailID", detailID); - cm.Parameters.AddWithValue("@ContentID", myContent.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDetail"; - cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDetail"; - // Input PK Fields - cm.Parameters.AddWithValue("@DetailID", detailID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Remove", ex); - throw new DbCslaException("Detail.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int detailID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(detailID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Detail.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DetailID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int detailID) - { - _DetailID = detailID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsDetail"; - cm.Parameters.AddWithValue("@DetailID", _DetailID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Execute", ex); - throw new DbCslaException("Detail.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DetailExtension _DetailExtension = new DetailExtension(); - [Serializable()] - partial class DetailExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DetailConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Detail) - { - // Return the ToString value - return ((Detail)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Detail Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DetailConverter))] + public partial class Detail : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDetails = new List(); + private void AddToRefreshList(List refreshDetails) + { + if (IsDirty) + refreshDetails.Add(this); + } + private void BuildRefreshList() + { + _RefreshDetails = new List(); + AddToRefreshList(_RefreshDetails); + } + private void ProcessRefreshList() + { + foreach (Detail tmp in _RefreshDetails) + { + DetailInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Detail detail) + { + if (!_CacheList.Contains(detail)) _CacheList.Add(detail); // In AddToCache + } + protected static void RemoveFromCache(Detail detail) + { + while (_CacheList.Contains(detail)) _CacheList.Remove(detail); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Detail tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString())) + { + _CacheByPrimaryKey[tmp.DetailID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Detail tmp in remove) + RemoveFromCache(tmp); + } + protected static Detail GetCachedByPrimaryKey(int detailID) + { + ConvertListToDictionary(); + string key = detailID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextDetailID = -1; + public static int NextDetailID + { + get { return _nextDetailID--; } + } + private int _DetailID; + [System.ComponentModel.DataObjectField(true, true)] + public int DetailID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DetailID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + PropertyHasChanged(); + } + } + } + private int _ItemType; + public int ItemType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ItemType != value) + { + _ItemType = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } + } + // TODO: Replace base Detail.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Detail + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Detail.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Detail + protected override object GetIdValue() + { + return _DetailID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Text"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _DetailExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DetailExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyContentRequired(Detail target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(DetailID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(ItemType, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(ItemType, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _DetailExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _DetailExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _DetailUnique = 0; + protected static int DetailUnique + { get { return ++_DetailUnique; } } + private int _MyDetailUnique = DetailUnique; + public int MyDetailUnique + { get { return _MyDetailUnique; } } + protected Detail() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) + { + List listDetail = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items + while (listDetail.Contains(this)) listDetail.Remove(this); // Remove the item from the list + if (listDetail.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DetailID.ToString()); // remove the list + } + } + public static Detail New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Detail"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.New", ex); + } + } + public static Detail New(Content myContent, int itemType, string text) + { + Detail tmp = Detail.New(); + tmp.MyContent = myContent; + tmp.ItemType = itemType; + tmp.Text = text; + return tmp; + } + public static Detail New(Content myContent, int itemType, string text, string config, DateTime dts, string userID) + { + Detail tmp = Detail.New(); + tmp.MyContent = myContent; + tmp.ItemType = itemType; + tmp.Text = text; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Detail MakeDetail(Content myContent, int itemType, string text, string config, DateTime dts, string userID) + { + Detail tmp = Detail.New(myContent, itemType, text, config, dts, userID); + if (tmp.IsSavable) + { + Detail tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Detail New(Content myContent, int itemType, string text, string config) + { + Detail tmp = Detail.New(); + tmp.MyContent = myContent; + tmp.ItemType = itemType; + tmp.Text = text; + tmp.Config = config; + return tmp; + } + public static Detail MakeDetail(Content myContent, int itemType, string text, string config) + { + Detail tmp = Detail.New(myContent, itemType, text, config); + if (tmp.IsSavable) + { + Detail tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(detailID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Detail + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.Get", ex); + } + } + public static Detail Get(SafeDataReader dr) + { + if (dr.Read()) return new Detail(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.Delete", ex); + } + } + 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(); + Detail detail = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(detail);//Refresh the item in AllList + ProcessRefreshList(); + return detail; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DetailID; + public int DetailID + { get { return _DetailID; } } + public PKCriteria(int detailID) + { + _DetailID = detailID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _DetailID = NextDetailID; + // Database Defaults + _DTS = _DetailExtension.DefaultDTS; + _UserID = _DetailExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.ReadData", GetHashCode()); + try + { + _DetailID = dr.GetInt32("DetailID"); + _ContentID = dr.GetInt32("ContentID"); + _ItemType = dr.GetInt32("ItemType"); + _Text = dr.GetString("Text"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Detail.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDetail"; + cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Detail.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Detail.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addDetail"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + detailID = (int)cm.Parameters["@newDetailID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Add", ex); + throw new DbCslaException("Detail.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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, _MyContent, _ItemType, _Text, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int detailID, Content myContent, int itemType, string text, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDetail"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@DetailID", detailID); + cm.Parameters.AddWithValue("@ContentID", myContent.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDetail"; + cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDetail"; + // Input PK Fields + cm.Parameters.AddWithValue("@DetailID", detailID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.Remove", ex); + throw new DbCslaException("Detail.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int detailID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(detailID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Detail.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DetailID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int detailID) + { + _DetailID = detailID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Detail.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsDetail"; + cm.Parameters.AddWithValue("@DetailID", _DetailID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Detail.DataPortal_Execute", ex); + throw new DbCslaException("Detail.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DetailExtension _DetailExtension = new DetailExtension(); + [Serializable()] + partial class DetailExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DetailConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Detail) + { + // Return the ToString value + return ((Detail)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DetailInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DetailInfo.cs index 3780ac9e..ef781538 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DetailInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DetailInfo.cs @@ -19,387 +19,379 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DetailInfoEvent(object sender); - /// - /// DetailInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DetailInfoConverter))] - public partial class DetailInfo : ReadOnlyBase, IDisposable - { - public event DetailInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DetailInfo detailInfo) - { - if (!_CacheList.Contains(detailInfo)) _CacheList.Add(detailInfo); // In AddToCache - } - protected static void RemoveFromCache(DetailInfo detailInfo) - { - while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (DetailInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString())) - { - _CacheByPrimaryKey[tmp.DetailID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (DetailInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(DetailInfoList lst) - { - foreach (DetailInfo item in lst) AddToCache(item); - } - protected static DetailInfo GetCachedByPrimaryKey(int detailID) - { - ConvertListToDictionary(); - string key = detailID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DetailID", true); - return _DetailID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private int _ItemType; - public int ItemType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemType", true); - return _ItemType; - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // TODO: Replace base DetailInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DetailInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check DetailInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DetailInfo - protected override object GetIdValue() - { - return _DetailID; - } - #endregion - #region Factory Methods - private static int _DetailInfoUnique = 0; - private static int DetailInfoUnique - { get { return ++_DetailInfoUnique; } } - private int _MyDetailInfoUnique = DetailInfoUnique; - public int MyDetailInfoUnique - { get { return _MyDetailInfoUnique; } } - protected DetailInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) return; - List listDetailInfo = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items - while (listDetailInfo.Contains(this)) listDetailInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Detail tmp) - { - string key = tmp.DetailID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Detail tmp) - { - if (_ContentID != tmp.ContentID) - { - if (MyContent != null) 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 - _ItemType = tmp.ItemType; - _Text = tmp.Text; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DetailInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ContentDetail tmp) - { - string key = tmp.DetailID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentDetail tmp) - { - _ItemType = tmp.ItemType; - _Text = tmp.Text; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DetailInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(detailID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DetailInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DetailInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DetailInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.Constructor", ex); - throw new DbCslaException("DetailInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DetailID; - public int DetailID - { get { return _DetailID; } } - public PKCriteria(int detailID) - { - _DetailID = detailID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.ReadData", GetHashCode()); - try - { - _DetailID = dr.GetInt32("DetailID"); - _ContentID = dr.GetInt32("ContentID"); - _ItemType = dr.GetInt32("ItemType"); - _Text = dr.GetString("Text"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DetailInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDetail"; - cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DetailInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension(); - [Serializable()] - partial class DetailInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DetailInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DetailInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DetailInfo) - { - // Return the ToString value - return ((DetailInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DetailInfoEvent(object sender); + /// + /// DetailInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DetailInfoConverter))] + public partial class DetailInfo : ReadOnlyBase, IDisposable + { + public event DetailInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DetailInfo detailInfo) + { + if (!_CacheList.Contains(detailInfo)) _CacheList.Add(detailInfo); // In AddToCache + } + protected static void RemoveFromCache(DetailInfo detailInfo) + { + while (_CacheList.Contains(detailInfo)) _CacheList.Remove(detailInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DetailInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.DetailID.ToString())) + { + _CacheByPrimaryKey[tmp.DetailID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.DetailID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (DetailInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(DetailInfoList lst) + { + foreach (DetailInfo item in lst) AddToCache(item); + } + protected static DetailInfo GetCachedByPrimaryKey(int detailID) + { + ConvertListToDictionary(); + string key = detailID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DetailID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private int _ItemType; + public int ItemType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemType; + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // TODO: Replace base DetailInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DetailInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check DetailInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DetailInfo + protected override object GetIdValue() + { + return _DetailID; + } + #endregion + #region Factory Methods + private static int _DetailInfoUnique = 0; + private static int DetailInfoUnique + { get { return ++_DetailInfoUnique; } } + private int _MyDetailInfoUnique = DetailInfoUnique; + public int MyDetailInfoUnique + { get { return _MyDetailInfoUnique; } } + protected DetailInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DetailID.ToString())) return; + List listDetailInfo = _CacheByPrimaryKey[DetailID.ToString()]; // Get the list of items + while (listDetailInfo.Contains(this)) listDetailInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Detail tmp) + { + string key = tmp.DetailID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Detail tmp) + { + if (_ContentID != tmp.ContentID) + { + if (MyContent != null) 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 + _ItemType = tmp.ItemType; + _Text = tmp.Text; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DetailInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ContentDetail tmp) + { + string key = tmp.DetailID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DetailInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentDetail tmp) + { + _ItemType = tmp.ItemType; + _Text = tmp.Text; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DetailInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(detailID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DetailInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DetailInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DetailInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.Constructor", ex); + throw new DbCslaException("DetailInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DetailID; + public int DetailID + { get { return _DetailID; } } + public PKCriteria(int detailID) + { + _DetailID = detailID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.ReadData", GetHashCode()); + try + { + _DetailID = dr.GetInt32("DetailID"); + _ContentID = dr.GetInt32("ContentID"); + _ItemType = dr.GetInt32("ItemType"); + _Text = dr.GetString("Text"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DetailInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DetailInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDetail"; + cm.Parameters.AddWithValue("@DetailID", criteria.DetailID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DetailInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DetailInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DetailInfoExtension _DetailInfoExtension = new DetailInfoExtension(); + [Serializable()] + partial class DetailInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DetailInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DetailInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DetailInfo) + { + // Return the ToString value + return ((DetailInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersion.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersion.cs index c7e5b795..dc19b6ee 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersion.cs @@ -20,1219 +20,1195 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionConverter))] - public partial class DocVersion : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDocVersions = new List(); - private List _RefreshDocVersionDocVersionROFsts = new List(); - private void AddToRefreshList(List refreshDocVersions, List refreshDocVersionDocVersionROFsts) - { - if (IsDirty) - refreshDocVersions.Add(this); - if (_DocVersionDocVersionROFsts != null && _DocVersionDocVersionROFsts.IsDirty) - { - foreach (DocVersionDocVersionROFst tmp in _DocVersionDocVersionROFsts) - { - if (tmp.IsDirty) refreshDocVersionDocVersionROFsts.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshDocVersions = new List(); - _RefreshDocVersionDocVersionROFsts = new List(); - AddToRefreshList(_RefreshDocVersions, _RefreshDocVersionDocVersionROFsts); - } - private void ProcessRefreshList() - { - foreach (DocVersion tmp in _RefreshDocVersions) - { - DocVersionInfo.Refresh(tmp); - if (tmp._MyFolder != null) FolderInfo.Refresh(tmp._MyFolder); - if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); - if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); - } - foreach (DocVersionDocVersionROFst tmp in _RefreshDocVersionDocVersionROFsts) - { - DocVersionROFstInfo.Refresh(this, tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocVersion docVersion) - { - if (!_CacheList.Contains(docVersion)) _CacheList.Add(docVersion); // In AddToCache - } - protected static void RemoveFromCache(DocVersion docVersion) - { - while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (DocVersion tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) - { - _CacheByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (DocVersion tmp in remove) - RemoveFromCache(tmp); - } - protected static DocVersion GetCachedByPrimaryKey(int versionID) - { - ConvertListToDictionary(); - string key = versionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextVersionID = -1; - public static int NextVersionID - { - get { return _nextVersionID--; } - } - private int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - return _VersionID; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyItem = value; - _ItemID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _DocVersionDocVersionROFstCount = 0; - /// - /// Count of DocVersionDocVersionROFsts for this DocVersion - /// - public int DocVersionDocVersionROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionDocVersionROFstCount", true); - return _DocVersionDocVersionROFstCount; - } - } - private DocVersionDocVersionROFsts _DocVersionDocVersionROFsts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(DocVersionDocVersionROFstsConverter))] - public DocVersionDocVersionROFsts DocVersionDocVersionROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionDocVersionROFsts", true); - if (_DocVersionDocVersionROFstCount > 0 && _DocVersionDocVersionROFsts == null) - _DocVersionDocVersionROFsts = DocVersionDocVersionROFsts.GetByVersionID(VersionID); - else if (_DocVersionDocVersionROFsts == null) - _DocVersionDocVersionROFsts = DocVersionDocVersionROFsts.New(); - return _DocVersionDocVersionROFsts; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_DocVersionDocVersionROFsts == null ? false : _DocVersionDocVersionROFsts.IsDirty) || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_DocVersionDocVersionROFsts == null ? true : _DocVersionDocVersionROFsts.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } - } - // TODO: Replace base DocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check DocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersion - protected override object GetIdValue() - { - return _VersionID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_DocVersionDocVersionROFsts != null && (hasBrokenRules = _DocVersionDocVersionROFsts.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _DocVersionExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _DocVersionExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyFolderRequired(DocVersion target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _DocVersionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _DocVersionExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _DocVersionDocVersionROFstCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _DocVersionUnique = 0; - protected static int DocVersionUnique - { get { return ++_DocVersionUnique; } } - private int _MyDocVersionUnique = DocVersionUnique; - public int MyDocVersionUnique - { get { return _MyDocVersionUnique; } } - protected DocVersion() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) - { - List listDocVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items - while (listDocVersion.Contains(this)) listDocVersion.Remove(this); // Remove the item from the list - if (listDocVersion.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list - } - } - public static DocVersion New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocVersion"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.New", ex); - } - } - public static DocVersion New(Folder myFolder, string name) - { - DocVersion tmp = DocVersion.New(); - tmp.MyFolder = myFolder; - tmp.Name = name; - return tmp; - } - public static DocVersion New(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) - { - DocVersion tmp = DocVersion.New(); - tmp.MyFolder = myFolder; - tmp.VersionType = versionType; - tmp.Name = name; - tmp.Title = title; - tmp.MyItem = myItem; - tmp.MyFormat = myFormat; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static DocVersion MakeDocVersion(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) - { - DocVersion tmp = DocVersion.New(myFolder, versionType, name, title, myItem, myFormat, config, dts, userID); - if (tmp.IsSavable) - { - DocVersion tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static DocVersion New(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) - { - DocVersion tmp = DocVersion.New(); - tmp.MyFolder = myFolder; - tmp.Name = name; - tmp.Title = title; - tmp.MyItem = myItem; - tmp.MyFormat = myFormat; - tmp.Config = config; - return tmp; - } - public static DocVersion MakeDocVersion(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) - { - DocVersion tmp = DocVersion.New(myFolder, name, title, myItem, myFormat, config); - if (tmp.IsSavable) - { - DocVersion tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocVersion - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.Get", ex); - } - } - public static DocVersion Get(SafeDataReader dr) - { - if (dr.Read()) return new DocVersion(dr); - return null; - } - internal DocVersion(SafeDataReader dr) - { - ReadData(dr); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.Delete", ex); - } - } - 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(); - DocVersion docVersion = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(docVersion);//Refresh the item in AllList - ProcessRefreshList(); - return docVersion; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _VersionID = NextVersionID; - // Database Defaults - _VersionType = _DocVersionExtension.DefaultVersionType; - _DTS = _DocVersionExtension.DefaultDTS; - _UserID = _DocVersionExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _DocVersionDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersion.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _DocVersionDocVersionROFsts = DocVersionDocVersionROFsts.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersion.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersion.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.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()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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 (_DocVersionDocVersionROFsts != null) _DocVersionDocVersionROFsts.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addDocVersion"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); - cm.Parameters.AddWithValue("@VersionType", versionType); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - if (myItem != null) cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - versionID = (int)cm.Parameters["@newVersionID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Add", ex); - throw new DbCslaException("DocVersion.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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 (_DocVersionDocVersionROFsts != null) _DocVersionDocVersionROFsts.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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, _MyFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_DocVersionDocVersionROFsts != null) _DocVersionDocVersionROFsts.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int versionID, Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateDocVersion"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@VersionID", versionID); - cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); - cm.Parameters.AddWithValue("@VersionType", versionType); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - if (myItem != null) cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocVersion"; - // Input PK Fields - cm.Parameters.AddWithValue("@VersionID", versionID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Remove", ex); - throw new DbCslaException("DocVersion.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int versionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(versionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersion.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _VersionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int versionID) - { - _VersionID = versionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsDocVersion"; - cm.Parameters.AddWithValue("@VersionID", _VersionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Execute", ex); - throw new DbCslaException("DocVersion.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DocVersionExtension _DocVersionExtension = new DocVersionExtension(); - [Serializable()] - partial class DocVersionExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersion) - { - // Return the ToString value - return ((DocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// DocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionConverter))] + public partial class DocVersion : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocVersions = new List(); + private List _RefreshDocVersionDocVersionROFsts = new List(); + private void AddToRefreshList(List refreshDocVersions, List refreshDocVersionDocVersionROFsts) + { + if (IsDirty) + refreshDocVersions.Add(this); + if (_DocVersionDocVersionROFsts != null && _DocVersionDocVersionROFsts.IsDirty) + { + foreach (DocVersionDocVersionROFst tmp in _DocVersionDocVersionROFsts) + { + if (tmp.IsDirty) refreshDocVersionDocVersionROFsts.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshDocVersions = new List(); + _RefreshDocVersionDocVersionROFsts = new List(); + AddToRefreshList(_RefreshDocVersions, _RefreshDocVersionDocVersionROFsts); + } + private void ProcessRefreshList() + { + foreach (DocVersion tmp in _RefreshDocVersions) + { + DocVersionInfo.Refresh(tmp); + if (tmp._MyFolder != null) FolderInfo.Refresh(tmp._MyFolder); + if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); + if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); + } + foreach (DocVersionDocVersionROFst tmp in _RefreshDocVersionDocVersionROFsts) + { + DocVersionROFstInfo.Refresh(this, tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocVersion docVersion) + { + if (!_CacheList.Contains(docVersion)) _CacheList.Add(docVersion); // In AddToCache + } + protected static void RemoveFromCache(DocVersion docVersion) + { + while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocVersion tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) + { + _CacheByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (DocVersion tmp in remove) + RemoveFromCache(tmp); + } + protected static DocVersion GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextVersionID = -1; + public static int NextVersionID + { + get { return _nextVersionID--; } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionID; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyItem = value; + _ItemID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _DocVersionDocVersionROFstCount = 0; + /// + /// Count of DocVersionDocVersionROFsts for this DocVersion + /// + public int DocVersionDocVersionROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersionDocVersionROFstCount; + } + } + private DocVersionDocVersionROFsts _DocVersionDocVersionROFsts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(DocVersionDocVersionROFstsConverter))] + public DocVersionDocVersionROFsts DocVersionDocVersionROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocVersionDocVersionROFstCount > 0 && _DocVersionDocVersionROFsts == null) + _DocVersionDocVersionROFsts = DocVersionDocVersionROFsts.GetByVersionID(VersionID); + else if (_DocVersionDocVersionROFsts == null) + _DocVersionDocVersionROFsts = DocVersionDocVersionROFsts.New(); + return _DocVersionDocVersionROFsts; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_DocVersionDocVersionROFsts == null ? false : _DocVersionDocVersionROFsts.IsDirty) || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_DocVersionDocVersionROFsts == null ? true : _DocVersionDocVersionROFsts.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } + } + // TODO: Replace base DocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check DocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersion + protected override object GetIdValue() + { + return _VersionID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_DocVersionDocVersionROFsts != null && (hasBrokenRules = _DocVersionDocVersionROFsts.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocVersionExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DocVersionExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyFolderRequired(DocVersion target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _DocVersionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _DocVersionExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _DocVersionDocVersionROFstCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _DocVersionUnique = 0; + protected static int DocVersionUnique + { get { return ++_DocVersionUnique; } } + private int _MyDocVersionUnique = DocVersionUnique; + public int MyDocVersionUnique + { get { return _MyDocVersionUnique; } } + protected DocVersion() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) + { + List listDocVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listDocVersion.Contains(this)) listDocVersion.Remove(this); // Remove the item from the list + if (listDocVersion.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list + } + } + public static DocVersion New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocVersion"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.New", ex); + } + } + public static DocVersion New(Folder myFolder, string name) + { + DocVersion tmp = DocVersion.New(); + tmp.MyFolder = myFolder; + tmp.Name = name; + return tmp; + } + public static DocVersion New(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) + { + DocVersion tmp = DocVersion.New(); + tmp.MyFolder = myFolder; + tmp.VersionType = versionType; + tmp.Name = name; + tmp.Title = title; + tmp.MyItem = myItem; + tmp.MyFormat = myFormat; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static DocVersion MakeDocVersion(Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID) + { + DocVersion tmp = DocVersion.New(myFolder, versionType, name, title, myItem, myFormat, config, dts, userID); + if (tmp.IsSavable) + { + DocVersion tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static DocVersion New(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) + { + DocVersion tmp = DocVersion.New(); + tmp.MyFolder = myFolder; + tmp.Name = name; + tmp.Title = title; + tmp.MyItem = myItem; + tmp.MyFormat = myFormat; + tmp.Config = config; + return tmp; + } + public static DocVersion MakeDocVersion(Folder myFolder, string name, string title, Item myItem, Format myFormat, string config) + { + DocVersion tmp = DocVersion.New(myFolder, name, title, myItem, myFormat, config); + if (tmp.IsSavable) + { + DocVersion tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersion + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.Get", ex); + } + } + public static DocVersion Get(SafeDataReader dr) + { + if (dr.Read()) return new DocVersion(dr); + return null; + } + internal DocVersion(SafeDataReader dr) + { + ReadData(dr); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.Delete", ex); + } + } + 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(); + DocVersion docVersion = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(docVersion);//Refresh the item in AllList + ProcessRefreshList(); + return docVersion; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _VersionID = NextVersionID; + // Database Defaults + _VersionType = _DocVersionExtension.DefaultVersionType; + _DTS = _DocVersionExtension.DefaultDTS; + _UserID = _DocVersionExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _DocVersionDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersion.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _DocVersionDocVersionROFsts = DocVersionDocVersionROFsts.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersion.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersion.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.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()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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 (_DocVersionDocVersionROFsts != null) _DocVersionDocVersionROFsts.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addDocVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); + cm.Parameters.AddWithValue("@VersionType", versionType); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + if (myItem != null) cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + versionID = (int)cm.Parameters["@newVersionID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Add", ex); + throw new DbCslaException("DocVersion.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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 (_DocVersionDocVersionROFsts != null) _DocVersionDocVersionROFsts.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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, _MyFolder, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_DocVersionDocVersionROFsts != null) _DocVersionDocVersionROFsts.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int versionID, Folder myFolder, int versionType, string name, string title, Item myItem, Format myFormat, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDocVersion"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", versionID); + cm.Parameters.AddWithValue("@FolderID", myFolder.FolderID); + cm.Parameters.AddWithValue("@VersionType", versionType); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + if (myItem != null) cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocVersion"; + // Input PK Fields + cm.Parameters.AddWithValue("@VersionID", versionID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.Remove", ex); + throw new DbCslaException("DocVersion.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int versionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(versionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersion.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _VersionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int versionID) + { + _VersionID = versionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersion.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsDocVersion"; + cm.Parameters.AddWithValue("@VersionID", _VersionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersion.DataPortal_Execute", ex); + throw new DbCslaException("DocVersion.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DocVersionExtension _DocVersionExtension = new DocVersionExtension(); + [Serializable()] + partial class DocVersionExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersion) + { + // Return the ToString value + return ((DocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionDocVersionROFst.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionDocVersionROFst.cs index ea4809fe..69b87e07 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionDocVersionROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionDocVersionROFst.cs @@ -19,374 +19,363 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocVersionDocVersionROFst Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionDocVersionROFstConverter))] - public partial class DocVersionDocVersionROFst : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - 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 - { - CanReadProperty("ROFst_RODbID", true); - return _ROFst_RODbID; - } - } - private byte[] _ROFst_ROFST; - public byte[] ROFst_ROFST - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_ROFST", true); - return _ROFst_ROFST; - } - } - private DateTime _ROFst_DTS = new DateTime(); - public DateTime ROFst_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_DTS", true); - return _ROFst_DTS; - } - } - private string _ROFst_UserID = string.Empty; - public string ROFst_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_UserID", true); - return _ROFst_UserID; - } - } - // TODO: Check DocVersionDocVersionROFst.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersionDocVersionROFst - protected override object GetIdValue() - { - return _ROFstID; - } - // TODO: Replace base DocVersionDocVersionROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersionDocVersionROFst - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static DocVersionDocVersionROFst New(ROFst myROFst) - { - return new DocVersionDocVersionROFst(myROFst); - } - internal static DocVersionDocVersionROFst Get(SafeDataReader dr) - { - return new DocVersionDocVersionROFst(dr); - } - public DocVersionDocVersionROFst() - { - MarkAsChild(); + /// + /// DocVersionDocVersionROFst Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionDocVersionROFstConverter))] + public partial class DocVersionDocVersionROFst : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + } + } + private ROFst _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + 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_ROFST; + public byte[] ROFst_ROFST + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_ROFST; + } + } + private DateTime _ROFst_DTS = new DateTime(); + public DateTime ROFst_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_DTS; + } + } + private string _ROFst_UserID = string.Empty; + public string ROFst_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_UserID; + } + } + // TODO: Check DocVersionDocVersionROFst.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersionDocVersionROFst + protected override object GetIdValue() + { + return _ROFstID; + } + // TODO: Replace base DocVersionDocVersionROFst.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersionDocVersionROFst + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static DocVersionDocVersionROFst New(ROFst myROFst) + { + return new DocVersionDocVersionROFst(myROFst); + } + internal static DocVersionDocVersionROFst Get(SafeDataReader dr) + { + return new DocVersionDocVersionROFst(dr); + } + public DocVersionDocVersionROFst() + { + MarkAsChild(); - _DTS = _DocVersionDocVersionROFstExtension.DefaultDTS; - _UserID = _DocVersionDocVersionROFstExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private DocVersionDocVersionROFst(ROFst myROFst) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _DocVersionDocVersionROFstExtension.DefaultDTS; - _UserID = _DocVersionDocVersionROFstExtension.DefaultUserID; - _MyROFst = myROFst; - ValidationRules.CheckRules(); - } - internal DocVersionDocVersionROFst(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionDocVersionROFst.FetchDR", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROFst_RODbID = dr.GetInt32("ROFst_RODbID"); - _ROFst_ROFST = (byte[])dr.GetValue("ROFst_ROFST"); - _ROFst_DTS = dr.GetDateTime("ROFst_DTS"); - _ROFst_UserID = dr.GetString("ROFst_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionDocVersionROFst.FetchDR", ex); - throw new DbCslaException("DocVersionDocVersionROFst.Fetch", ex); - } - MarkOld(); - } - internal void Insert(DocVersion myDocVersion) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = DocVersionROFst.Add(cn, myDocVersion, _MyROFst, _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 = DocVersionROFst.Update(cn, myDocVersion, _MyROFst, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - 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"]; - DocVersionROFst.Remove(cn, myDocVersion.VersionID, _ROFstID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - DocVersionDocVersionROFstExtension _DocVersionDocVersionROFstExtension = new DocVersionDocVersionROFstExtension(); - [Serializable()] - partial class DocVersionDocVersionROFstExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocVersionDocVersionROFstConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersionDocVersionROFst) - { - // Return the ToString value - return ((DocVersionDocVersionROFst)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _DocVersionDocVersionROFstExtension.DefaultDTS; + _UserID = _DocVersionDocVersionROFstExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private DocVersionDocVersionROFst(ROFst myROFst) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _DocVersionDocVersionROFstExtension.DefaultDTS; + _UserID = _DocVersionDocVersionROFstExtension.DefaultUserID; + _MyROFst = myROFst; + ValidationRules.CheckRules(); + } + internal DocVersionDocVersionROFst(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionDocVersionROFst.FetchDR", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROFst_RODbID = dr.GetInt32("ROFst_RODbID"); + _ROFst_ROFST = (byte[])dr.GetValue("ROFst_ROFST"); + _ROFst_DTS = dr.GetDateTime("ROFst_DTS"); + _ROFst_UserID = dr.GetString("ROFst_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionDocVersionROFst.FetchDR", ex); + throw new DbCslaException("DocVersionDocVersionROFst.Fetch", ex); + } + MarkOld(); + } + internal void Insert(DocVersion myDocVersion) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = DocVersionROFst.Add(cn, myDocVersion, _MyROFst, _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 = DocVersionROFst.Update(cn, myDocVersion, _MyROFst, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + 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"]; + DocVersionROFst.Remove(cn, myDocVersion.VersionID, _ROFstID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + DocVersionDocVersionROFstExtension _DocVersionDocVersionROFstExtension = new DocVersionDocVersionROFstExtension(); + [Serializable()] + partial class DocVersionDocVersionROFstExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocVersionDocVersionROFstConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersionDocVersionROFst) + { + // Return the ToString value + return ((DocVersionDocVersionROFst)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionInfo.cs index c587a857..47aae191 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionInfo.cs @@ -19,629 +19,614 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DocVersionInfoEvent(object sender); - /// - /// DocVersionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionInfoConverter))] - public partial class DocVersionInfo : ReadOnlyBase, IDisposable - { - public event DocVersionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocVersionInfo docVersionInfo) - { - if (!_CacheList.Contains(docVersionInfo)) _CacheList.Add(docVersionInfo); // In AddToCache - } - protected static void RemoveFromCache(DocVersionInfo docVersionInfo) - { - while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (DocVersionInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) - { - _CacheByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (DocVersionInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(DocVersionInfoList lst) - { - foreach (DocVersionInfo item in lst) AddToCache(item); - } - protected static DocVersionInfo GetCachedByPrimaryKey(int versionID) - { - ConvertListToDictionary(); - string key = versionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - return _VersionID; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private FolderInfo _MyFolder; - public FolderInfo MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); - return _MyFolder; - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private ItemInfo _MyItem; - public ItemInfo MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = ItemInfo.Get((int)_ItemID); - return _MyItem; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private FormatInfo _MyFormat; - public FormatInfo MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); - return _MyFormat; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DocVersionDocVersionROFstCount = 0; - /// - /// Count of DocVersionDocVersionROFsts for this DocVersion - /// - public int DocVersionDocVersionROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionDocVersionROFstCount", true); - return _DocVersionDocVersionROFstCount; - } - } - private DocVersionROFstInfoList _DocVersionDocVersionROFsts = null; - [TypeConverter(typeof(DocVersionROFstInfoListConverter))] - public DocVersionROFstInfoList DocVersionDocVersionROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersionDocVersionROFsts", true); - if (_DocVersionDocVersionROFstCount < 0 || (_DocVersionDocVersionROFstCount > 0 && _DocVersionDocVersionROFsts == null)) - _DocVersionDocVersionROFsts = DocVersionROFstInfoList.GetByVersionID(_VersionID); - if (_DocVersionDocVersionROFstCount < 0) - _DocVersionDocVersionROFstCount = _DocVersionDocVersionROFsts.Count; - return _DocVersionDocVersionROFsts; - } - } - public void RefreshDocVersionDocVersionROFsts() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_VersionID.ToString())) - foreach (DocVersionInfo tmp in _CacheByPrimaryKey[_VersionID.ToString()]) - tmp._DocVersionDocVersionROFstCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base DocVersionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check DocVersionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersionInfo - protected override object GetIdValue() - { - return _VersionID; - } - #endregion - #region Factory Methods - private static int _DocVersionInfoUnique = 0; - private static int DocVersionInfoUnique - { get { return ++_DocVersionInfoUnique; } } - private int _MyDocVersionInfoUnique = DocVersionInfoUnique; - public int MyDocVersionInfoUnique - { get { return _MyDocVersionInfoUnique; } } - protected DocVersionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; - List listDocVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items - while (listDocVersionInfo.Contains(this)) listDocVersionInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(DocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocVersion tmp) - { - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) 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 - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) 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 - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(FolderDocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FolderDocVersion tmp) - { - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) 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 - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(FormatDocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FormatDocVersion tmp) - { - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) 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 - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ItemDocVersion tmp) - { - string key = tmp.VersionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemDocVersion tmp) - { - if (_FolderID != tmp.FolderID) - { - if (MyFolder != null) 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 - _VersionType = tmp.VersionType; - _Name = tmp.Name; - _Title = tmp.Title; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionInfoExtension.Refresh(this); - if(_MyFolder != null) - { - _MyFolder.Dispose();// Dispose related value - _MyFolder = null;// Reset related value - } - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocVersionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DocVersionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.Constructor", ex); - throw new DbCslaException("DocVersionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - public PKCriteria(int versionID) - { - _VersionID = versionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DocVersionDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocVersion"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension(); - [Serializable()] - partial class DocVersionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DocVersionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DocVersionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersionInfo) - { - // Return the ToString value - return ((DocVersionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DocVersionInfoEvent(object sender); + /// + /// DocVersionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionInfoConverter))] + public partial class DocVersionInfo : ReadOnlyBase, IDisposable + { + public event DocVersionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocVersionInfo docVersionInfo) + { + if (!_CacheList.Contains(docVersionInfo)) _CacheList.Add(docVersionInfo); // In AddToCache + } + protected static void RemoveFromCache(DocVersionInfo docVersionInfo) + { + while (_CacheList.Contains(docVersionInfo)) _CacheList.Remove(docVersionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocVersionInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString())) + { + _CacheByPrimaryKey[tmp.VersionID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (DocVersionInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(DocVersionInfoList lst) + { + foreach (DocVersionInfo item in lst) AddToCache(item); + } + protected static DocVersionInfo GetCachedByPrimaryKey(int versionID) + { + ConvertListToDictionary(); + string key = versionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionID; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private FolderInfo _MyFolder; + public FolderInfo MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = FolderInfo.Get(_FolderID); + return _MyFolder; + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private ItemInfo _MyItem; + public ItemInfo MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = ItemInfo.Get((int)_ItemID); + return _MyItem; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private FormatInfo _MyFormat; + public FormatInfo MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); + return _MyFormat; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DocVersionDocVersionROFstCount = 0; + /// + /// Count of DocVersionDocVersionROFsts for this DocVersion + /// + public int DocVersionDocVersionROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersionDocVersionROFstCount; + } + } + private DocVersionROFstInfoList _DocVersionDocVersionROFsts = null; + [TypeConverter(typeof(DocVersionROFstInfoListConverter))] + public DocVersionROFstInfoList DocVersionDocVersionROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocVersionDocVersionROFstCount < 0 || (_DocVersionDocVersionROFstCount > 0 && _DocVersionDocVersionROFsts == null)) + _DocVersionDocVersionROFsts = DocVersionROFstInfoList.GetByVersionID(_VersionID); + if (_DocVersionDocVersionROFstCount < 0) + _DocVersionDocVersionROFstCount = _DocVersionDocVersionROFsts.Count; + return _DocVersionDocVersionROFsts; + } + } + public void RefreshDocVersionDocVersionROFsts() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_VersionID.ToString())) + foreach (DocVersionInfo tmp in _CacheByPrimaryKey[_VersionID.ToString()]) + tmp._DocVersionDocVersionROFstCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base DocVersionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check DocVersionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersionInfo + protected override object GetIdValue() + { + return _VersionID; + } + #endregion + #region Factory Methods + private static int _DocVersionInfoUnique = 0; + private static int DocVersionInfoUnique + { get { return ++_DocVersionInfoUnique; } } + private int _MyDocVersionInfoUnique = DocVersionInfoUnique; + public int MyDocVersionInfoUnique + { get { return _MyDocVersionInfoUnique; } } + protected DocVersionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString())) return; + List listDocVersionInfo = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items + while (listDocVersionInfo.Contains(this)) listDocVersionInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(DocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocVersion tmp) + { + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) 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 + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) 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 + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(FolderDocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FolderDocVersion tmp) + { + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) 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 + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(FormatDocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FormatDocVersion tmp) + { + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) 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 + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ItemDocVersion tmp) + { + string key = tmp.VersionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemDocVersion tmp) + { + if (_FolderID != tmp.FolderID) + { + if (MyFolder != null) 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 + _VersionType = tmp.VersionType; + _Name = tmp.Name; + _Title = tmp.Title; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionInfoExtension.Refresh(this); + if (_MyFolder != null) + { + _MyFolder.Dispose();// Dispose related value + _MyFolder = null;// Reset related value + } + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocVersionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.Constructor", ex); + throw new DbCslaException("DocVersionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + public PKCriteria(int versionID) + { + _VersionID = versionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DocVersionDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersion"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocVersionInfoExtension _DocVersionInfoExtension = new DocVersionInfoExtension(); + [Serializable()] + partial class DocVersionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocVersionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocVersionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersionInfo) + { + // Return the ToString value + return ((DocVersionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFst.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFst.cs index d0f759e9..76fe5a16 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFst.cs @@ -20,915 +20,907 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocVersionROFst Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionROFstConverter))] - public partial class DocVersionROFst : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDocVersionROFsts = new List(); - private void AddToRefreshList(List refreshDocVersionROFsts) - { - if (IsDirty) - refreshDocVersionROFsts.Add(this); - } - private void BuildRefreshList() - { - _RefreshDocVersionROFsts = new List(); - AddToRefreshList(_RefreshDocVersionROFsts); - } - private void ProcessRefreshList() - { - foreach (DocVersionROFst tmp in _RefreshDocVersionROFsts) - { - DocVersionROFstInfo.Refresh(tmp); - if (tmp._MyDocVersion != null) DocVersionInfo.Refresh(tmp._MyDocVersion); - if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocVersionROFst docVersionROFst) - { - if (!_CacheList.Contains(docVersionROFst)) _CacheList.Add(docVersionROFst); // In AddToCache - } - protected static void RemoveFromCache(DocVersionROFst docVersionROFst) - { - while (_CacheList.Contains(docVersionROFst)) _CacheList.Remove(docVersionROFst); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (DocVersionROFst tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString())) - { - _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (DocVersionROFst tmp in remove) - RemoveFromCache(tmp); - } - protected static DocVersionROFst GetCachedByPrimaryKey(int versionID, int rOFstID) - { - ConvertListToDictionary(); - string key = versionID.ToString() + "_" + rOFstID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirty) || (_MyROFst == null ? false : _MyROFst.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyDocVersion == null ? true : _MyDocVersion.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValid); } - } - // TODO: Replace base DocVersionROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersionROFst - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check DocVersionROFst.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersionROFst - protected override object GetIdValue() - { - return (_VersionID.ToString() + "." + _ROFstID.ToString()).GetHashCode(); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _DocVersionROFstExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _DocVersionROFstExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _DocVersionROFstExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _DocVersionROFstExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _DocVersionROFstUnique = 0; - protected static int DocVersionROFstUnique - { get { return ++_DocVersionROFstUnique; } } - private int _MyDocVersionROFstUnique = DocVersionROFstUnique; - public int MyDocVersionROFstUnique - { get { return _MyDocVersionROFstUnique; } } - protected DocVersionROFst() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString() + "_" + ROFstID.ToString())) - { - List listDocVersionROFst = _CacheByPrimaryKey[VersionID.ToString() + "_" + ROFstID.ToString()]; // Get the list of items - while (listDocVersionROFst.Contains(this)) listDocVersionROFst.Remove(this); // Remove the item from the list - if (listDocVersionROFst.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(VersionID.ToString() + "_" + ROFstID.ToString()); // remove the list - } - } - public static DocVersionROFst New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocVersionROFst"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersionROFst.New", ex); - } - } - public static DocVersionROFst New(DocVersion myDocVersion, ROFst myROFst) - { - DocVersionROFst tmp = DocVersionROFst.New(); - tmp._MyDocVersion = myDocVersion; - tmp._MyROFst = myROFst; - return tmp; - } - public static DocVersionROFst MakeDocVersionROFst(DocVersion myDocVersion, ROFst myROFst) - { - DocVersionROFst tmp = DocVersionROFst.New(myDocVersion, myROFst); - if (tmp.IsSavable) - { - DocVersionROFst tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static DocVersionROFst New(DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID) - { - DocVersionROFst tmp = DocVersionROFst.New(); - tmp._MyDocVersion = myDocVersion; - tmp._MyROFst = myROFst; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static DocVersionROFst MakeDocVersionROFst(DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID) - { - DocVersionROFst tmp = DocVersionROFst.New(myDocVersion, myROFst, dts, userID); - if (tmp.IsSavable) - { - DocVersionROFst tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static DocVersionROFst Get(int versionID, int rOFstID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a DocVersionROFst"); - try - { - DocVersionROFst tmp = GetCachedByPrimaryKey(versionID, rOFstID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID, rOFstID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocVersionROFst - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersionROFst.Get", ex); - } - } - public static DocVersionROFst Get(SafeDataReader dr) - { - if (dr.Read()) return new DocVersionROFst(dr); - return null; - } - internal DocVersionROFst(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int versionID, int rOFstID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DocVersionROFst"); - try - { - DataPortal.Delete(new PKCriteria(versionID, rOFstID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersionROFst.Delete", ex); - } - } - public override DocVersionROFst Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a DocVersionROFst"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a DocVersionROFst"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a DocVersionROFst"); - try - { - BuildRefreshList(); - DocVersionROFst docVersionROFst = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(docVersionROFst);//Refresh the item in AllList - ProcessRefreshList(); - return docVersionROFst; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int versionID, int rOFstID) - { - _VersionID = versionID; - _ROFstID = rOFstID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// DocVersionROFst Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionROFstConverter))] + public partial class DocVersionROFst : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocVersionROFsts = new List(); + private void AddToRefreshList(List refreshDocVersionROFsts) + { + if (IsDirty) + refreshDocVersionROFsts.Add(this); + } + private void BuildRefreshList() + { + _RefreshDocVersionROFsts = new List(); + AddToRefreshList(_RefreshDocVersionROFsts); + } + private void ProcessRefreshList() + { + foreach (DocVersionROFst tmp in _RefreshDocVersionROFsts) + { + DocVersionROFstInfo.Refresh(tmp); + if (tmp._MyDocVersion != null) DocVersionInfo.Refresh(tmp._MyDocVersion); + if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocVersionROFst docVersionROFst) + { + if (!_CacheList.Contains(docVersionROFst)) _CacheList.Add(docVersionROFst); // In AddToCache + } + protected static void RemoveFromCache(DocVersionROFst docVersionROFst) + { + while (_CacheList.Contains(docVersionROFst)) _CacheList.Remove(docVersionROFst); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocVersionROFst tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString())) + { + _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (DocVersionROFst tmp in remove) + RemoveFromCache(tmp); + } + protected static DocVersionROFst GetCachedByPrimaryKey(int versionID, int rOFstID) + { + ConvertListToDictionary(); + string key = versionID.ToString() + "_" + rOFstID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyDocVersion == null ? false : _MyDocVersion.IsDirty) || (_MyROFst == null ? false : _MyROFst.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyDocVersion == null ? true : _MyDocVersion.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValid); } + } + // TODO: Replace base DocVersionROFst.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersionROFst + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check DocVersionROFst.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersionROFst + protected override object GetIdValue() + { + return (_VersionID.ToString() + "." + _ROFstID.ToString()).GetHashCode(); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocVersionROFstExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DocVersionROFstExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _DocVersionROFstExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _DocVersionROFstExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _DocVersionROFstUnique = 0; + protected static int DocVersionROFstUnique + { get { return ++_DocVersionROFstUnique; } } + private int _MyDocVersionROFstUnique = DocVersionROFstUnique; + public int MyDocVersionROFstUnique + { get { return _MyDocVersionROFstUnique; } } + protected DocVersionROFst() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString() + "_" + ROFstID.ToString())) + { + List listDocVersionROFst = _CacheByPrimaryKey[VersionID.ToString() + "_" + ROFstID.ToString()]; // Get the list of items + while (listDocVersionROFst.Contains(this)) listDocVersionROFst.Remove(this); // Remove the item from the list + if (listDocVersionROFst.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString() + "_" + ROFstID.ToString()); // remove the list + } + } + public static DocVersionROFst New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocVersionROFst"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionROFst.New", ex); + } + } + public static DocVersionROFst New(DocVersion myDocVersion, ROFst myROFst) + { + DocVersionROFst tmp = DocVersionROFst.New(); + tmp._MyDocVersion = myDocVersion; + tmp._MyROFst = myROFst; + return tmp; + } + public static DocVersionROFst MakeDocVersionROFst(DocVersion myDocVersion, ROFst myROFst) + { + DocVersionROFst tmp = DocVersionROFst.New(myDocVersion, myROFst); + if (tmp.IsSavable) + { + DocVersionROFst tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static DocVersionROFst New(DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID) + { + DocVersionROFst tmp = DocVersionROFst.New(); + tmp._MyDocVersion = myDocVersion; + tmp._MyROFst = myROFst; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static DocVersionROFst MakeDocVersionROFst(DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID) + { + DocVersionROFst tmp = DocVersionROFst.New(myDocVersion, myROFst, dts, userID); + if (tmp.IsSavable) + { + DocVersionROFst tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static DocVersionROFst Get(int versionID, int rOFstID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a DocVersionROFst"); + try + { + DocVersionROFst tmp = GetCachedByPrimaryKey(versionID, rOFstID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID, rOFstID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersionROFst + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionROFst.Get", ex); + } + } + public static DocVersionROFst Get(SafeDataReader dr) + { + if (dr.Read()) return new DocVersionROFst(dr); + return null; + } + internal DocVersionROFst(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int versionID, int rOFstID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a DocVersionROFst"); + try + { + DataPortal.Delete(new PKCriteria(versionID, rOFstID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionROFst.Delete", ex); + } + } + public override DocVersionROFst Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a DocVersionROFst"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a DocVersionROFst"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a DocVersionROFst"); + try + { + BuildRefreshList(); + DocVersionROFst docVersionROFst = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(docVersionROFst);//Refresh the item in AllList + ProcessRefreshList(); + return docVersionROFst; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + public PKCriteria(int versionID, int rOFstID) + { + _VersionID = versionID; + _ROFstID = rOFstID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _DocVersionROFstExtension.DefaultDTS; - _UserID = _DocVersionROFstExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _ROFstID = dr.GetInt32("ROFstID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionROFst.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocVersionROFst"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionROFst.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionROFst.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyDocVersion != null) _MyDocVersion.Update(); - if (_MyROFst != null) _MyROFst.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addDocVersionROFst"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@VersionID", VersionID); - cm.Parameters.AddWithValue("@ROFstID", ROFstID); - 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); - // TODO: 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}] DocVersionROFst.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionROFst.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addDocVersionROFst"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@VersionID", myDocVersion.VersionID); - cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.Add", ex); - throw new DbCslaException("DocVersionROFst.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] DocVersionROFst.SQLUpdate", GetHashCode()); - try - { - if (_MyDocVersion != null) _MyDocVersion.Update(); - if (_MyROFst != null) _MyROFst.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateDocVersionROFst"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@VersionID", VersionID); - cm.Parameters.AddWithValue("@ROFstID", ROFstID); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = DocVersionROFst.Add(cn, _MyDocVersion, _MyROFst, _DTS, _UserID); - else - _LastChanged = DocVersionROFst.Update(cn, _MyDocVersion, _MyROFst, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateDocVersionROFst"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@VersionID", myDocVersion.VersionID); - cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.Update", ex); - throw new DbCslaException("DocVersionROFst.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_VersionID, _ROFstID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocVersionROFst"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionROFst.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int versionID, int rOFstID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocVersionROFst"; - // Input PK Fields - cm.Parameters.AddWithValue("@VersionID", versionID); - cm.Parameters.AddWithValue("@ROFstID", rOFstID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.Remove", ex); - throw new DbCslaException("DocVersionROFst.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int versionID, int rOFstID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(versionID, rOFstID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersionROFst.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _VersionID; - private int _ROFstID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int versionID, int rOFstID) - { - _VersionID = versionID; - _ROFstID = rOFstID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsDocVersionROFst"; - cm.Parameters.AddWithValue("@VersionID", _VersionID); - cm.Parameters.AddWithValue("@ROFstID", _ROFstID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Execute", ex); - throw new DbCslaException("DocVersionROFst.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DocVersionROFstExtension _DocVersionROFstExtension = new DocVersionROFstExtension(); - [Serializable()] - partial class DocVersionROFstExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocVersionROFstConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersionROFst) - { - // Return the ToString value - return ((DocVersionROFst)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _DocVersionROFstExtension.DefaultDTS; + _UserID = _DocVersionROFstExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _ROFstID = dr.GetInt32("ROFstID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionROFst.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionROFst"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionROFst.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionROFst.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyDocVersion != null) _MyDocVersion.Update(); + if (_MyROFst != null) _MyROFst.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addDocVersionROFst"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", VersionID); + cm.Parameters.AddWithValue("@ROFstID", ROFstID); + 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); + // TODO: 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}] DocVersionROFst.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionROFst.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addDocVersionROFst"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", myDocVersion.VersionID); + cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.Add", ex); + throw new DbCslaException("DocVersionROFst.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] DocVersionROFst.SQLUpdate", GetHashCode()); + try + { + if (_MyDocVersion != null) _MyDocVersion.Update(); + if (_MyROFst != null) _MyROFst.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDocVersionROFst"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@VersionID", VersionID); + cm.Parameters.AddWithValue("@ROFstID", ROFstID); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = DocVersionROFst.Add(cn, _MyDocVersion, _MyROFst, _DTS, _UserID); + else + _LastChanged = DocVersionROFst.Update(cn, _MyDocVersion, _MyROFst, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, DocVersion myDocVersion, ROFst myROFst, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDocVersionROFst"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@VersionID", myDocVersion.VersionID); + cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.Update", ex); + throw new DbCslaException("DocVersionROFst.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_VersionID, _ROFstID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocVersionROFst"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionROFst.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int versionID, int rOFstID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocVersionROFst"; + // Input PK Fields + cm.Parameters.AddWithValue("@VersionID", versionID); + cm.Parameters.AddWithValue("@ROFstID", rOFstID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.Remove", ex); + throw new DbCslaException("DocVersionROFst.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int versionID, int rOFstID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(versionID, rOFstID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionROFst.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _VersionID; + private int _ROFstID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int versionID, int rOFstID) + { + _VersionID = versionID; + _ROFstID = rOFstID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFst.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsDocVersionROFst"; + cm.Parameters.AddWithValue("@VersionID", _VersionID); + cm.Parameters.AddWithValue("@ROFstID", _ROFstID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFst.DataPortal_Execute", ex); + throw new DbCslaException("DocVersionROFst.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DocVersionROFstExtension _DocVersionROFstExtension = new DocVersionROFstExtension(); + [Serializable()] + partial class DocVersionROFstExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocVersionROFstConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersionROFst) + { + // Return the ToString value + return ((DocVersionROFst)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFstInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFstInfo.cs index 5febec5b..272e22de 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFstInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocVersionROFstInfo.cs @@ -19,396 +19,390 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DocVersionROFstInfoEvent(object sender); - /// - /// DocVersionROFstInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocVersionROFstInfoConverter))] - public partial class DocVersionROFstInfo : ReadOnlyBase, IDisposable - { - public event DocVersionROFstInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocVersionROFstInfo docVersionROFstInfo) - { - if (!_CacheList.Contains(docVersionROFstInfo)) _CacheList.Add(docVersionROFstInfo); // In AddToCache - } - protected static void RemoveFromCache(DocVersionROFstInfo docVersionROFstInfo) - { - while (_CacheList.Contains(docVersionROFstInfo)) _CacheList.Remove(docVersionROFstInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (DocVersionROFstInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString())) - { - _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (DocVersionROFstInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(DocVersionROFstInfoList lst) - { - foreach (DocVersionROFstInfo item in lst) AddToCache(item); - } - protected static DocVersionROFstInfo GetCachedByPrimaryKey(int versionID, int rOFstID) - { - ConvertListToDictionary(); - string key = versionID.ToString() + "_" + rOFstID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected DocVersionROFst _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersionInfo _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersionInfo MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersionInfo.Get(_VersionID); - return _MyDocVersion; - } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFstInfo _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFstInfo MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); - return _MyROFst; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // TODO: Replace base DocVersionROFstInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocVersionROFstInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check DocVersionROFstInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocVersionROFstInfo - protected override object GetIdValue() - { - return (_VersionID.ToString() + "." + _ROFstID.ToString()).GetHashCode(); - } - #endregion - #region Factory Methods - private static int _DocVersionROFstInfoUnique = 0; - private static int DocVersionROFstInfoUnique - { get { return ++_DocVersionROFstInfoUnique; } } - private int _MyDocVersionROFstInfoUnique = DocVersionROFstInfoUnique; - public int MyDocVersionROFstInfoUnique - { get { return _MyDocVersionROFstInfoUnique; } } - protected DocVersionROFstInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString() + "_" + ROFstID.ToString())) return; - List listDocVersionROFstInfo = _CacheByPrimaryKey[VersionID.ToString() + "_" + ROFstID.ToString()]; // Get the list of items - while (listDocVersionROFstInfo.Contains(this)) listDocVersionROFstInfo.Remove(this); // Remove the item from the list - if (listDocVersionROFstInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(VersionID.ToString() + "_" + ROFstID.ToString()); // remove the list - } - public virtual DocVersionROFst Get() - { - return _Editable = DocVersionROFst.Get(_VersionID, _ROFstID); - } - public static void Refresh(DocVersionROFst tmp) - { - string key = tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionROFstInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocVersionROFst tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionROFstInfoExtension.Refresh(this); - if(_MyDocVersion != null) - { - _MyDocVersion.Dispose();// Dispose related value - _MyDocVersion = null;// Reset related value - } - if(_MyROFst != null) - { - _MyROFst.Dispose();// Dispose related value - _MyROFst = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(DocVersion myDocVersion, DocVersionDocVersionROFst tmp) - { - string key = myDocVersion.VersionID.ToString() + "_" + tmp.ROFstID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionROFstInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocVersionDocVersionROFst tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionROFstInfoExtension.Refresh(this); - if(_MyDocVersion != null) - { - _MyDocVersion.Dispose();// Dispose related value - _MyDocVersion = null;// Reset related value - } - if(_MyROFst != null) - { - _MyROFst.Dispose();// Dispose related value - _MyROFst = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ROFst myROFst, ROFstDocVersionROFst tmp) - { - string key = tmp.VersionID.ToString() + "_" + myROFst.ROFstID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocVersionROFstInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROFstDocVersionROFst tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocVersionROFstInfoExtension.Refresh(this); - if(_MyDocVersion != null) - { - _MyDocVersion.Dispose();// Dispose related value - _MyDocVersion = null;// Reset related value - } - if(_MyROFst != null) - { - _MyROFst.Dispose();// Dispose related value - _MyROFst = null;// Reset related value - } - OnChange();// raise an event - } - public static DocVersionROFstInfo Get(int versionID, int rOFstID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a DocVersionROFst"); - try - { - DocVersionROFstInfo tmp = GetCachedByPrimaryKey(versionID, rOFstID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(versionID, rOFstID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocVersionROFstInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocVersionROFstInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DocVersionROFstInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFstInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFstInfo.Constructor", ex); - throw new DbCslaException("DocVersionROFstInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _VersionID; - public int VersionID - { get { return _VersionID; } } - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int versionID, int rOFstID) - { - _VersionID = versionID; - _ROFstID = rOFstID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFstInfo.ReadData", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _ROFstID = dr.GetInt32("ROFstID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFstInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionROFstInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFstInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocVersionROFst"; - cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFstInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocVersionROFstInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DocVersionROFstInfoExtension _DocVersionROFstInfoExtension = new DocVersionROFstInfoExtension(); - [Serializable()] - partial class DocVersionROFstInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DocVersionROFstInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DocVersionROFstInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocVersionROFstInfo) - { - // Return the ToString value - return ((DocVersionROFstInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DocVersionROFstInfoEvent(object sender); + /// + /// DocVersionROFstInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocVersionROFstInfoConverter))] + public partial class DocVersionROFstInfo : ReadOnlyBase, IDisposable + { + public event DocVersionROFstInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocVersionROFstInfo docVersionROFstInfo) + { + if (!_CacheList.Contains(docVersionROFstInfo)) _CacheList.Add(docVersionROFstInfo); // In AddToCache + } + protected static void RemoveFromCache(DocVersionROFstInfo docVersionROFstInfo) + { + while (_CacheList.Contains(docVersionROFstInfo)) _CacheList.Remove(docVersionROFstInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocVersionROFstInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString())) + { + _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (DocVersionROFstInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(DocVersionROFstInfoList lst) + { + foreach (DocVersionROFstInfo item in lst) AddToCache(item); + } + protected static DocVersionROFstInfo GetCachedByPrimaryKey(int versionID, int rOFstID) + { + ConvertListToDictionary(); + string key = versionID.ToString() + "_" + rOFstID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected DocVersionROFst _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersionInfo _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersionInfo MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersionInfo.Get(_VersionID); + return _MyDocVersion; + } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFstInfo _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFstInfo MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); + return _MyROFst; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // TODO: Replace base DocVersionROFstInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocVersionROFstInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check DocVersionROFstInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocVersionROFstInfo + protected override object GetIdValue() + { + return (_VersionID.ToString() + "." + _ROFstID.ToString()).GetHashCode(); + } + #endregion + #region Factory Methods + private static int _DocVersionROFstInfoUnique = 0; + private static int DocVersionROFstInfoUnique + { get { return ++_DocVersionROFstInfoUnique; } } + private int _MyDocVersionROFstInfoUnique = DocVersionROFstInfoUnique; + public int MyDocVersionROFstInfoUnique + { get { return _MyDocVersionROFstInfoUnique; } } + protected DocVersionROFstInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(VersionID.ToString() + "_" + ROFstID.ToString())) return; + List listDocVersionROFstInfo = _CacheByPrimaryKey[VersionID.ToString() + "_" + ROFstID.ToString()]; // Get the list of items + while (listDocVersionROFstInfo.Contains(this)) listDocVersionROFstInfo.Remove(this); // Remove the item from the list + if (listDocVersionROFstInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(VersionID.ToString() + "_" + ROFstID.ToString()); // remove the list + } + public virtual DocVersionROFst Get() + { + return _Editable = DocVersionROFst.Get(_VersionID, _ROFstID); + } + public static void Refresh(DocVersionROFst tmp) + { + string key = tmp.VersionID.ToString() + "_" + tmp.ROFstID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionROFstInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocVersionROFst tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionROFstInfoExtension.Refresh(this); + if (_MyDocVersion != null) + { + _MyDocVersion.Dispose();// Dispose related value + _MyDocVersion = null;// Reset related value + } + if (_MyROFst != null) + { + _MyROFst.Dispose();// Dispose related value + _MyROFst = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(DocVersion myDocVersion, DocVersionDocVersionROFst tmp) + { + string key = myDocVersion.VersionID.ToString() + "_" + tmp.ROFstID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionROFstInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocVersionDocVersionROFst tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionROFstInfoExtension.Refresh(this); + if (_MyDocVersion != null) + { + _MyDocVersion.Dispose();// Dispose related value + _MyDocVersion = null;// Reset related value + } + if (_MyROFst != null) + { + _MyROFst.Dispose();// Dispose related value + _MyROFst = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ROFst myROFst, ROFstDocVersionROFst tmp) + { + string key = tmp.VersionID.ToString() + "_" + myROFst.ROFstID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocVersionROFstInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROFstDocVersionROFst tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocVersionROFstInfoExtension.Refresh(this); + if (_MyDocVersion != null) + { + _MyDocVersion.Dispose();// Dispose related value + _MyDocVersion = null;// Reset related value + } + if (_MyROFst != null) + { + _MyROFst.Dispose();// Dispose related value + _MyROFst = null;// Reset related value + } + OnChange();// raise an event + } + public static DocVersionROFstInfo Get(int versionID, int rOFstID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a DocVersionROFst"); + try + { + DocVersionROFstInfo tmp = GetCachedByPrimaryKey(versionID, rOFstID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(versionID, rOFstID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocVersionROFstInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocVersionROFstInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocVersionROFstInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFstInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFstInfo.Constructor", ex); + throw new DbCslaException("DocVersionROFstInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _VersionID; + public int VersionID + { get { return _VersionID; } } + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + public PKCriteria(int versionID, int rOFstID) + { + _VersionID = versionID; + _ROFstID = rOFstID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFstInfo.ReadData", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _ROFstID = dr.GetInt32("ROFstID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFstInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionROFstInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocVersionROFstInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocVersionROFst"; + cm.Parameters.AddWithValue("@VersionID", criteria.VersionID); + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocVersionROFstInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocVersionROFstInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocVersionROFstInfoExtension _DocVersionROFstInfoExtension = new DocVersionROFstInfoExtension(); + [Serializable()] + partial class DocVersionROFstInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocVersionROFstInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocVersionROFstInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocVersionROFstInfo) + { + // Return the ToString value + return ((DocVersionROFstInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Document.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Document.cs index c5654037..cb398069 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Document.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Document.cs @@ -20,1062 +20,1047 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Document Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentConverter))] - public partial class Document : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshDocuments = new List(); - private List _RefreshDocumentEntries = new List(); - private void AddToRefreshList(List refreshDocuments, List refreshDocumentEntries) - { - if (IsDirty) - refreshDocuments.Add(this); - if (_DocumentEntries != null && _DocumentEntries.IsDirty) - { - foreach (DocumentEntry tmp in _DocumentEntries) - { - if (tmp.IsDirty) refreshDocumentEntries.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshDocuments = new List(); - _RefreshDocumentEntries = new List(); - AddToRefreshList(_RefreshDocuments, _RefreshDocumentEntries); - } - private void ProcessRefreshList() - { - foreach (Document tmp in _RefreshDocuments) - { - DocumentInfo.Refresh(tmp); - } - foreach (DocumentEntry tmp in _RefreshDocumentEntries) - { - EntryInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Document document) - { - if (!_CacheList.Contains(document)) _CacheList.Add(document); // In AddToCache - } - protected static void RemoveFromCache(Document document) - { - while (_CacheList.Contains(document)) _CacheList.Remove(document); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Document tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.DocID.ToString())) - { - _CacheByPrimaryKey[tmp.DocID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Document tmp in remove) - RemoveFromCache(tmp); - } - protected static Document GetCachedByPrimaryKey(int docID) - { - ConvertListToDictionary(); - string key = docID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextDocID = -1; - public static int NextDocID - { - get { return _nextDocID--; } - } - private int _DocID; - [System.ComponentModel.DataObjectField(true, true)] - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("LibTitle", true); - if (value == null) value = string.Empty; - if (_LibTitle != value) - { - _LibTitle = value; - PropertyHasChanged(); - } - } - } - private byte[] _DocContent; - /// - /// Actual content of a Word Document (RTF, DOC or XML Format) - /// - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocContent", true); - if (_DocContent != value) - { - _DocContent = value; - PropertyHasChanged(); - } - } - } - private string _DocAscii = string.Empty; - /// - /// Used for searching - /// - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DocAscii", true); - if (value == null) value = string.Empty; - if (_DocAscii != value) - { - _DocAscii = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _DocumentEntryCount = 0; - /// - /// Count of DocumentEntries for this Document - /// - public int DocumentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntryCount", true); - return _DocumentEntryCount; - } - } - private DocumentEntries _DocumentEntries = null; - /// - /// Related Field - /// - [TypeConverter(typeof(DocumentEntriesConverter))] - public DocumentEntries DocumentEntries - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntries", true); - if (_DocumentEntryCount > 0 && _DocumentEntries == null) - _DocumentEntries = DocumentEntries.GetByDocID(DocID); - else if (_DocumentEntries == null) - _DocumentEntries = DocumentEntries.New(); - return _DocumentEntries; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_DocumentEntries == null ? false : _DocumentEntries.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_DocumentEntries == null ? true : _DocumentEntries.IsValid); } - } - // TODO: Replace base Document.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Document - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Document.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Document - protected override object GetIdValue() - { - return _DocID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_DocumentEntries != null && (hasBrokenRules = _DocumentEntries.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 1024)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _DocumentExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _DocumentExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(LibTitle, ""); - //AuthorizationRules.AllowRead(DocContent, ""); - //AuthorizationRules.AllowRead(DocAscii, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(LibTitle, ""); - //AuthorizationRules.AllowWrite(DocContent, ""); - //AuthorizationRules.AllowWrite(DocAscii, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _DocumentExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _DocumentExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _DocumentEntryCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _DocumentUnique = 0; - protected static int DocumentUnique - { get { return ++_DocumentUnique; } } - private int _MyDocumentUnique = DocumentUnique; - public int MyDocumentUnique - { get { return _MyDocumentUnique; } } - protected Document() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(DocID.ToString())) - { - List listDocument = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items - while (listDocument.Contains(this)) listDocument.Remove(this); // Remove the item from the list - if (listDocument.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list - } - } - public static Document New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Document"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.New", ex); - } - } - public static Document New(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID) - { - Document tmp = Document.New(); - tmp.LibTitle = libTitle; - tmp.DocContent = docContent; - tmp.DocAscii = docAscii; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID) - { - Document tmp = Document.New(libTitle, docContent, docAscii, config, dts, userID); - if (tmp.IsSavable) - { - Document tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Document New(string libTitle, byte[] docContent, string docAscii, string config) - { - Document tmp = Document.New(); - tmp.LibTitle = libTitle; - tmp.DocContent = docContent; - tmp.DocAscii = docAscii; - tmp.Config = config; - return tmp; - } - public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config) - { - Document tmp = Document.New(libTitle, docContent, docAscii, config); - if (tmp.IsSavable) - { - Document tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(docID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Document - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.Get", ex); - } - } - public static Document Get(SafeDataReader dr) - { - if (dr.Read()) return new Document(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.Delete", ex); - } - } - 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(); - Document document = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(document);//Refresh the item in AllList - ProcessRefreshList(); - return document; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _DocID; - public int DocID - { get { return _DocID; } } - public PKCriteria(int docID) - { - _DocID = docID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _DocID = NextDocID; - // Database Defaults - _DTS = _DocumentExtension.DefaultDTS; - _UserID = _DocumentExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.ReadData", GetHashCode()); - try - { - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _DocumentEntryCount = dr.GetInt32("EntryCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Document.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocument"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _DocumentEntries = DocumentEntries.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Document.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Document.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // 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); - // TODO: 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 (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - docID = (int)cm.Parameters["@newDocID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Add", ex); - throw new DbCslaException("Document.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - else - _LastChanged = Document.Update(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_DocumentEntries != null) _DocumentEntries.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) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateDocument"; - // 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("@LastChanged", lastChanged); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Update", ex); - throw new DbCslaException("Document.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_DocID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocument"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteDocument"; - // Input PK Fields - cm.Parameters.AddWithValue("@DocID", docID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Remove", ex); - throw new DbCslaException("Document.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int docID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(docID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Document.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _DocID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int docID) - { - _DocID = docID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsDocument"; - cm.Parameters.AddWithValue("@DocID", _DocID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Execute", ex); - throw new DbCslaException("Document.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - DocumentExtension _DocumentExtension = new DocumentExtension(); - [Serializable()] - partial class DocumentExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Document) - { - // Return the ToString value - return ((Document)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Document Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentConverter))] + public partial class Document : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshDocuments = new List(); + private List _RefreshDocumentEntries = new List(); + private void AddToRefreshList(List refreshDocuments, List refreshDocumentEntries) + { + if (IsDirty) + refreshDocuments.Add(this); + if (_DocumentEntries != null && _DocumentEntries.IsDirty) + { + foreach (DocumentEntry tmp in _DocumentEntries) + { + if (tmp.IsDirty) refreshDocumentEntries.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshDocuments = new List(); + _RefreshDocumentEntries = new List(); + AddToRefreshList(_RefreshDocuments, _RefreshDocumentEntries); + } + private void ProcessRefreshList() + { + foreach (Document tmp in _RefreshDocuments) + { + DocumentInfo.Refresh(tmp); + } + foreach (DocumentEntry tmp in _RefreshDocumentEntries) + { + EntryInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Document document) + { + if (!_CacheList.Contains(document)) _CacheList.Add(document); // In AddToCache + } + protected static void RemoveFromCache(Document document) + { + while (_CacheList.Contains(document)) _CacheList.Remove(document); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Document tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.DocID.ToString())) + { + _CacheByPrimaryKey[tmp.DocID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Document tmp in remove) + RemoveFromCache(tmp); + } + protected static Document GetCachedByPrimaryKey(int docID) + { + ConvertListToDictionary(); + string key = docID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextDocID = -1; + public static int NextDocID + { + get { return _nextDocID--; } + } + private int _DocID; + [System.ComponentModel.DataObjectField(true, true)] + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_LibTitle != value) + { + _LibTitle = value; + PropertyHasChanged(); + } + } + } + private byte[] _DocContent; + /// + /// Actual content of a Word Document (RTF, DOC or XML Format) + /// + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DocContent != value) + { + _DocContent = value; + PropertyHasChanged(); + } + } + } + private string _DocAscii = string.Empty; + /// + /// Used for searching + /// + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_DocAscii != value) + { + _DocAscii = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _DocumentEntryCount = 0; + /// + /// Count of DocumentEntries for this Document + /// + public int DocumentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocumentEntryCount; + } + } + private DocumentEntries _DocumentEntries = null; + /// + /// Related Field + /// + [TypeConverter(typeof(DocumentEntriesConverter))] + public DocumentEntries DocumentEntries + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentEntryCount > 0 && _DocumentEntries == null) + _DocumentEntries = DocumentEntries.GetByDocID(DocID); + else if (_DocumentEntries == null) + _DocumentEntries = DocumentEntries.New(); + return _DocumentEntries; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_DocumentEntries == null ? false : _DocumentEntries.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_DocumentEntries == null ? true : _DocumentEntries.IsValid); } + } + // TODO: Replace base Document.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Document + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Document.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Document + protected override object GetIdValue() + { + return _DocID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_DocumentEntries != null && (hasBrokenRules = _DocumentEntries.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("LibTitle", 1024)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("DocAscii", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _DocumentExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _DocumentExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(LibTitle, ""); + //AuthorizationRules.AllowRead(DocContent, ""); + //AuthorizationRules.AllowRead(DocAscii, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(LibTitle, ""); + //AuthorizationRules.AllowWrite(DocContent, ""); + //AuthorizationRules.AllowWrite(DocAscii, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _DocumentExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _DocumentExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _DocumentEntryCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _DocumentUnique = 0; + protected static int DocumentUnique + { get { return ++_DocumentUnique; } } + private int _MyDocumentUnique = DocumentUnique; + public int MyDocumentUnique + { get { return _MyDocumentUnique; } } + protected Document() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(DocID.ToString())) + { + List listDocument = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items + while (listDocument.Contains(this)) listDocument.Remove(this); // Remove the item from the list + if (listDocument.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(DocID.ToString()); // remove the list + } + } + public static Document New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Document"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.New", ex); + } + } + public static Document New(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID) + { + Document tmp = Document.New(); + tmp.LibTitle = libTitle; + tmp.DocContent = docContent; + tmp.DocAscii = docAscii; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config, DateTime dts, string userID) + { + Document tmp = Document.New(libTitle, docContent, docAscii, config, dts, userID); + if (tmp.IsSavable) + { + Document tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Document New(string libTitle, byte[] docContent, string docAscii, string config) + { + Document tmp = Document.New(); + tmp.LibTitle = libTitle; + tmp.DocContent = docContent; + tmp.DocAscii = docAscii; + tmp.Config = config; + return tmp; + } + public static Document MakeDocument(string libTitle, byte[] docContent, string docAscii, string config) + { + Document tmp = Document.New(libTitle, docContent, docAscii, config); + if (tmp.IsSavable) + { + Document tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Document + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.Get", ex); + } + } + public static Document Get(SafeDataReader dr) + { + if (dr.Read()) return new Document(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.Delete", ex); + } + } + 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(); + Document document = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(document);//Refresh the item in AllList + ProcessRefreshList(); + return document; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _DocID; + public int DocID + { get { return _DocID; } } + public PKCriteria(int docID) + { + _DocID = docID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _DocID = NextDocID; + // Database Defaults + _DTS = _DocumentExtension.DefaultDTS; + _UserID = _DocumentExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.ReadData", GetHashCode()); + try + { + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _DocumentEntryCount = dr.GetInt32("EntryCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Document.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocument"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _DocumentEntries = DocumentEntries.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Document.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Document.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // 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); + // TODO: 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 (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + docID = (int)cm.Parameters["@newDocID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Add", ex); + throw new DbCslaException("Document.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + else + _LastChanged = Document.Update(cn, ref _DocID, _LibTitle, _DocContent, _DocAscii, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_DocumentEntries != null) _DocumentEntries.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) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateDocument"; + // 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("@LastChanged", lastChanged); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Update", ex); + throw new DbCslaException("Document.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_DocID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocument"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteDocument"; + // Input PK Fields + cm.Parameters.AddWithValue("@DocID", docID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.Remove", ex); + throw new DbCslaException("Document.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int docID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(docID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Document.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _DocID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int docID) + { + _DocID = docID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Document.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsDocument"; + cm.Parameters.AddWithValue("@DocID", _DocID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Document.DataPortal_Execute", ex); + throw new DbCslaException("Document.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + DocumentExtension _DocumentExtension = new DocumentExtension(); + [Serializable()] + partial class DocumentExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Document) + { + // Return the ToString value + return ((Document)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentEntry.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentEntry.cs index 8b50b21b..bc29e416 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentEntry.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentEntry.cs @@ -19,410 +19,397 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// DocumentEntry Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentEntryConverter))] - public partial class DocumentEntry : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyEntry != null) _ContentID = _MyEntry.ContentID; - return _ContentID; - } - } - private Entry _MyEntry; - [System.ComponentModel.DataObjectField(true, true)] - public Entry MyEntry - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyEntry", true); - if (_MyEntry == null && _ContentID != 0) _MyEntry = Entry.Get(_ContentID); - return _MyEntry; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // TODO: Check DocumentEntry.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentEntry - protected override object GetIdValue() - { - return _ContentID; - } - // TODO: Replace base DocumentEntry.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentEntry - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static DocumentEntry New(Entry myEntry) - { - return new DocumentEntry(myEntry); - } - internal static DocumentEntry Get(SafeDataReader dr) - { - return new DocumentEntry(dr); - } - public DocumentEntry() - { - MarkAsChild(); + /// + /// DocumentEntry Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentEntryConverter))] + public partial class DocumentEntry : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyEntry != null) _ContentID = _MyEntry.ContentID; + return _ContentID; + } + } + private Entry _MyEntry; + [System.ComponentModel.DataObjectField(true, true)] + public Entry MyEntry + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyEntry == null && _ContentID != 0) _MyEntry = Entry.Get(_ContentID); + return _MyEntry; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // TODO: Check DocumentEntry.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentEntry + protected override object GetIdValue() + { + return _ContentID; + } + // TODO: Replace base DocumentEntry.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentEntry + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static DocumentEntry New(Entry myEntry) + { + return new DocumentEntry(myEntry); + } + internal static DocumentEntry Get(SafeDataReader dr) + { + return new DocumentEntry(dr); + } + public DocumentEntry() + { + MarkAsChild(); - _DTS = _DocumentEntryExtension.DefaultDTS; - _UserID = _DocumentEntryExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private DocumentEntry(Entry myEntry) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _DocumentEntryExtension.DefaultDTS; - _UserID = _DocumentEntryExtension.DefaultUserID; - _MyEntry = myEntry; - ValidationRules.CheckRules(); - } - internal DocumentEntry(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentEntry.FetchDR", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentEntry.FetchDR", ex); - throw new DbCslaException("DocumentEntry.Fetch", ex); - } - MarkOld(); - } - 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); - 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, _MyEntry.MyContent, myDocument, _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 we're new then don't update the database - if (this.IsNew) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - Entry.Remove(cn, _ContentID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension(); - [Serializable()] - partial class DocumentEntryExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class DocumentEntryConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentEntry) - { - // Return the ToString value - return ((DocumentEntry)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _DocumentEntryExtension.DefaultDTS; + _UserID = _DocumentEntryExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private DocumentEntry(Entry myEntry) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _DocumentEntryExtension.DefaultDTS; + _UserID = _DocumentEntryExtension.DefaultUserID; + _MyEntry = myEntry; + ValidationRules.CheckRules(); + } + internal DocumentEntry(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentEntry.FetchDR", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentEntry.FetchDR", ex); + throw new DbCslaException("DocumentEntry.Fetch", ex); + } + MarkOld(); + } + 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); + 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, _MyEntry.MyContent, myDocument, _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 we're new then don't update the database + if (this.IsNew) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + Entry.Remove(cn, _ContentID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + DocumentEntryExtension _DocumentEntryExtension = new DocumentEntryExtension(); + [Serializable()] + partial class DocumentEntryExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class DocumentEntryConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentEntry) + { + // Return the ToString value + return ((DocumentEntry)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentInfo.cs index 8b027dba..df013431 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/DocumentInfo.cs @@ -19,383 +19,374 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void DocumentInfoEvent(object sender); - /// - /// DocumentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(DocumentInfoConverter))] - public partial class DocumentInfo : ReadOnlyBase, IDisposable - { - public event DocumentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(DocumentInfo documentInfo) - { - if (!_CacheList.Contains(documentInfo)) _CacheList.Add(documentInfo); // In AddToCache - } - protected static void RemoveFromCache(DocumentInfo documentInfo) - { - while (_CacheList.Contains(documentInfo)) _CacheList.Remove(documentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (DocumentInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.DocID.ToString())) - { - _CacheByPrimaryKey[tmp.DocID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (DocumentInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(DocumentInfoList lst) - { - foreach (DocumentInfo item in lst) AddToCache(item); - } - protected static DocumentInfo GetCachedByPrimaryKey(int docID) - { - ConvertListToDictionary(); - string key = docID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - return _DocID; - } - } - private string _LibTitle = string.Empty; - public string LibTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LibTitle", true); - return _LibTitle; - } - } - private byte[] _DocContent; - /// - /// Actual content of a Word Document (RTF, DOC or XML Format) - /// - public byte[] DocContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocContent", true); - return _DocContent; - } - } - private string _DocAscii = string.Empty; - /// - /// Used for searching - /// - public string DocAscii - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocAscii", true); - return _DocAscii; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _DocumentEntryCount = 0; - /// - /// Count of DocumentEntries for this Document - /// - public int DocumentEntryCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntryCount", true); - return _DocumentEntryCount; - } - } - private EntryInfoList _DocumentEntries = null; - [TypeConverter(typeof(EntryInfoListConverter))] - public EntryInfoList DocumentEntries - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocumentEntries", true); - if (_DocumentEntryCount < 0 || (_DocumentEntryCount > 0 && _DocumentEntries == null)) - _DocumentEntries = EntryInfoList.GetByDocID(_DocID); - if (_DocumentEntryCount < 0) - _DocumentEntryCount = _DocumentEntries.Count; - return _DocumentEntries; - } - } - public void RefreshDocumentEntries() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) - foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) - tmp._DocumentEntryCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base DocumentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current DocumentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check DocumentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current DocumentInfo - protected override object GetIdValue() - { - return _DocID; - } - #endregion - #region Factory Methods - private static int _DocumentInfoUnique = 0; - private static int DocumentInfoUnique - { get { return ++_DocumentInfoUnique; } } - private int _MyDocumentInfoUnique = DocumentInfoUnique; - public int MyDocumentInfoUnique - { get { return _MyDocumentInfoUnique; } } - protected DocumentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString())) return; - List listDocumentInfo = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items - while (listDocumentInfo.Contains(this)) listDocumentInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Document tmp) - { - string key = tmp.DocID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (DocumentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Document tmp) - { - _LibTitle = tmp.LibTitle; - _DocContent = tmp.DocContent; - _DocAscii = tmp.DocAscii; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _DocumentInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(docID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up DocumentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on DocumentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal DocumentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.Constructor", ex); - throw new DbCslaException("DocumentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _DocID; - public int DocID - { get { return _DocID; } } - public PKCriteria(int docID) - { - _DocID = docID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.ReadData", GetHashCode()); - try - { - _DocID = dr.GetInt32("DocID"); - _LibTitle = dr.GetString("LibTitle"); - _DocContent = (byte[])dr.GetValue("DocContent"); - _DocAscii = dr.GetString("DocAscii"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _DocumentEntryCount = dr.GetInt32("EntryCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getDocument"; - cm.Parameters.AddWithValue("@DocID", criteria.DocID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("DocumentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension(); - [Serializable()] - partial class DocumentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(DocumentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class DocumentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is DocumentInfo) - { - // Return the ToString value - return ((DocumentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void DocumentInfoEvent(object sender); + /// + /// DocumentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(DocumentInfoConverter))] + public partial class DocumentInfo : ReadOnlyBase, IDisposable + { + public event DocumentInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(DocumentInfo documentInfo) + { + if (!_CacheList.Contains(documentInfo)) _CacheList.Add(documentInfo); // In AddToCache + } + protected static void RemoveFromCache(DocumentInfo documentInfo) + { + while (_CacheList.Contains(documentInfo)) _CacheList.Remove(documentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (DocumentInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.DocID.ToString())) + { + _CacheByPrimaryKey[tmp.DocID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.DocID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (DocumentInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(DocumentInfoList lst) + { + foreach (DocumentInfo item in lst) AddToCache(item); + } + protected static DocumentInfo GetCachedByPrimaryKey(int docID) + { + ConvertListToDictionary(); + string key = docID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocID; + } + } + private string _LibTitle = string.Empty; + public string LibTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LibTitle; + } + } + private byte[] _DocContent; + /// + /// Actual content of a Word Document (RTF, DOC or XML Format) + /// + public byte[] DocContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocContent; + } + } + private string _DocAscii = string.Empty; + /// + /// Used for searching + /// + public string DocAscii + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocAscii; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _DocumentEntryCount = 0; + /// + /// Count of DocumentEntries for this Document + /// + public int DocumentEntryCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocumentEntryCount; + } + } + private EntryInfoList _DocumentEntries = null; + [TypeConverter(typeof(EntryInfoListConverter))] + public EntryInfoList DocumentEntries + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_DocumentEntryCount < 0 || (_DocumentEntryCount > 0 && _DocumentEntries == null)) + _DocumentEntries = EntryInfoList.GetByDocID(_DocID); + if (_DocumentEntryCount < 0) + _DocumentEntryCount = _DocumentEntries.Count; + return _DocumentEntries; + } + } + public void RefreshDocumentEntries() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_DocID.ToString())) + foreach (DocumentInfo tmp in _CacheByPrimaryKey[_DocID.ToString()]) + tmp._DocumentEntryCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base DocumentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current DocumentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check DocumentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current DocumentInfo + protected override object GetIdValue() + { + return _DocID; + } + #endregion + #region Factory Methods + private static int _DocumentInfoUnique = 0; + private static int DocumentInfoUnique + { get { return ++_DocumentInfoUnique; } } + private int _MyDocumentInfoUnique = DocumentInfoUnique; + public int MyDocumentInfoUnique + { get { return _MyDocumentInfoUnique; } } + protected DocumentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(DocID.ToString())) return; + List listDocumentInfo = _CacheByPrimaryKey[DocID.ToString()]; // Get the list of items + while (listDocumentInfo.Contains(this)) listDocumentInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Document tmp) + { + string key = tmp.DocID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (DocumentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Document tmp) + { + _LibTitle = tmp.LibTitle; + _DocContent = tmp.DocContent; + _DocAscii = tmp.DocAscii; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _DocumentInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(docID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up DocumentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on DocumentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal DocumentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.Constructor", ex); + throw new DbCslaException("DocumentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _DocID; + public int DocID + { get { return _DocID; } } + public PKCriteria(int docID) + { + _DocID = docID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.ReadData", GetHashCode()); + try + { + _DocID = dr.GetInt32("DocID"); + _LibTitle = dr.GetString("LibTitle"); + _DocContent = (byte[])dr.GetValue("DocContent"); + _DocAscii = dr.GetString("DocAscii"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _DocumentEntryCount = dr.GetInt32("EntryCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] DocumentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getDocument"; + cm.Parameters.AddWithValue("@DocID", criteria.DocID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("DocumentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("DocumentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + DocumentInfoExtension _DocumentInfoExtension = new DocumentInfoExtension(); + [Serializable()] + partial class DocumentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(DocumentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class DocumentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is DocumentInfo) + { + // Return the ToString value + return ((DocumentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Entry.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Entry.cs index 11d99026..38d96df3 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Entry.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Entry.cs @@ -20,930 +20,921 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Entry Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(EntryConverter))] - public partial class Entry : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshEntries = new List(); - private void AddToRefreshList(List refreshEntries) - { - if (IsDirty) - refreshEntries.Add(this); - } - private void BuildRefreshList() - { - _RefreshEntries = new List(); - AddToRefreshList(_RefreshEntries); - } - private void ProcessRefreshList() - { - foreach (Entry tmp in _RefreshEntries) - { - EntryInfo.Refresh(tmp); - if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Entry entry) - { - if (!_CacheList.Contains(entry)) _CacheList.Add(entry); // In AddToCache - } - protected static void RemoveFromCache(Entry entry) - { - while (_CacheList.Contains(entry)) _CacheList.Remove(entry); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Entry tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Entry tmp in remove) - RemoveFromCache(tmp); - } - protected static Entry GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private Document _MyDocument; - public Document MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); - return _MyDocument; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyDocument", true); - if (_MyDocument != value) - { - _MyDocument = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValid); } - } - // TODO: Replace base Entry.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Entry - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Entry.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Entry - protected override object GetIdValue() - { - return _ContentID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _EntryExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _EntryExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyDocumentRequired(Entry target, Csla.Validation.RuleArgs e) - { - if (target._DocID == 0 && target._MyDocument == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DocID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(DocID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _EntryExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _EntryExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _EntryUnique = 0; - protected static int EntryUnique - { get { return ++_EntryUnique; } } - private int _MyEntryUnique = EntryUnique; - public int MyEntryUnique - { get { return _MyEntryUnique; } } - protected Entry() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listEntry = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listEntry.Contains(this)) listEntry.Remove(this); // Remove the item from the list - if (listEntry.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static Entry New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Entry"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.New", ex); - } - } - public static Entry New(Content myContent, Document myDocument) - { - Entry tmp = Entry.New(); - tmp._MyContent = myContent; - tmp.MyDocument = myDocument; - return tmp; - } - public static Entry MakeEntry(Content myContent, Document myDocument) - { - Entry tmp = Entry.New(myContent, myDocument); - if (tmp.IsSavable) - { - Entry tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Entry New(Content myContent, Document myDocument, DateTime dts, string userID) - { - Entry tmp = Entry.New(); - tmp._MyContent = myContent; - tmp.MyDocument = myDocument; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Entry MakeEntry(Content myContent, Document myDocument, DateTime dts, string userID) - { - Entry tmp = Entry.New(myContent, myDocument, dts, userID); - if (tmp.IsSavable) - { - Entry tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Entry New(Content myContent) - { - Entry tmp = Entry.New(); - tmp._MyContent = myContent; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Entry - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.Get", ex); - } - } - public static Entry Get(SafeDataReader dr) - { - if (dr.Read()) return new Entry(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.Delete", ex); - } - } - 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(); - Entry entry = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(entry);//Refresh the item in AllList - ProcessRefreshList(); - return entry; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// Entry Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryConverter))] + public partial class Entry : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshEntries = new List(); + private void AddToRefreshList(List refreshEntries) + { + if (IsDirty) + refreshEntries.Add(this); + } + private void BuildRefreshList() + { + _RefreshEntries = new List(); + AddToRefreshList(_RefreshEntries); + } + private void ProcessRefreshList() + { + foreach (Entry tmp in _RefreshEntries) + { + EntryInfo.Refresh(tmp); + if (tmp._MyDocument != null) DocumentInfo.Refresh(tmp._MyDocument); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Entry entry) + { + if (!_CacheList.Contains(entry)) _CacheList.Add(entry); // In AddToCache + } + protected static void RemoveFromCache(Entry entry) + { + while (_CacheList.Contains(entry)) _CacheList.Remove(entry); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Entry tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Entry tmp in remove) + RemoveFromCache(tmp); + } + protected static Entry GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private Document _MyDocument; + public Document MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = Document.Get(_DocID); + return _MyDocument; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyDocument != value) + { + _MyDocument = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyDocument == null ? false : _MyDocument.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyDocument == null ? true : _MyDocument.IsValid); } + } + // TODO: Replace base Entry.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Entry + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Entry.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Entry + protected override object GetIdValue() + { + return _ContentID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyDocument != null && (hasBrokenRules = _MyDocument.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyDocumentRequired, "MyDocument"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _EntryExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _EntryExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyDocumentRequired(Entry target, Csla.Validation.RuleArgs e) + { + if (target._DocID == 0 && target._MyDocument == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DocID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(DocID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _EntryExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _EntryExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _EntryUnique = 0; + protected static int EntryUnique + { get { return ++_EntryUnique; } } + private int _MyEntryUnique = EntryUnique; + public int MyEntryUnique + { get { return _MyEntryUnique; } } + protected Entry() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listEntry = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listEntry.Contains(this)) listEntry.Remove(this); // Remove the item from the list + if (listEntry.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static Entry New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Entry"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.New", ex); + } + } + public static Entry New(Content myContent, Document myDocument) + { + Entry tmp = Entry.New(); + tmp._MyContent = myContent; + tmp.MyDocument = myDocument; + return tmp; + } + public static Entry MakeEntry(Content myContent, Document myDocument) + { + Entry tmp = Entry.New(myContent, myDocument); + if (tmp.IsSavable) + { + Entry tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Entry New(Content myContent, Document myDocument, DateTime dts, string userID) + { + Entry tmp = Entry.New(); + tmp._MyContent = myContent; + tmp.MyDocument = myDocument; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Entry MakeEntry(Content myContent, Document myDocument, DateTime dts, string userID) + { + Entry tmp = Entry.New(myContent, myDocument, dts, userID); + if (tmp.IsSavable) + { + Entry tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Entry New(Content myContent) + { + Entry tmp = Entry.New(); + tmp._MyContent = myContent; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Entry + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.Get", ex); + } + } + public static Entry Get(SafeDataReader dr) + { + if (dr.Read()) return new Entry(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.Delete", ex); + } + } + 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(); + Entry entry = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(entry);//Refresh the item in AllList + ProcessRefreshList(); + return entry; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _EntryExtension.DefaultDTS; - _UserID = _EntryExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _DocID = dr.GetInt32("DocID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Entry.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getEntry"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Entry.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Entry.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyDocument != null) _MyDocument.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addEntry"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@DocID", myDocument.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Add", ex); - throw new DbCslaException("Entry.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Content content) - { - if (!this.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, MyDocument, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, Content myContent, Document myDocument, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateEntry"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@DocID", myDocument.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Update", ex); - throw new DbCslaException("Entry.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}] Entry.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteEntry"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteEntry"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Remove", ex); - throw new DbCslaException("Entry.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Entry.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsEntry"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Execute", ex); - throw new DbCslaException("Entry.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - EntryExtension _EntryExtension = new EntryExtension(); - [Serializable()] - partial class EntryExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class EntryConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Entry) - { - // Return the ToString value - return ((Entry)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _EntryExtension.DefaultDTS; + _UserID = _EntryExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Entry.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntry"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Entry.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Entry.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyDocument != null) _MyDocument.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addEntry"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@DocID", myDocument.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Add", ex); + throw new DbCslaException("Entry.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Content content) + { + if (!this.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, MyDocument, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, Content myContent, Document myDocument, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateEntry"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@DocID", myDocument.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Update", ex); + throw new DbCslaException("Entry.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}] Entry.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteEntry"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteEntry"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.Remove", ex); + throw new DbCslaException("Entry.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Entry.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Entry.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsEntry"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Entry.DataPortal_Execute", ex); + throw new DbCslaException("Entry.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + EntryExtension _EntryExtension = new EntryExtension(); + [Serializable()] + partial class EntryExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class EntryConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Entry) + { + // Return the ToString value + return ((Entry)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/EntryInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/EntryInfo.cs index e25e95fe..f8886485 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/EntryInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/EntryInfo.cs @@ -19,371 +19,365 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void EntryInfoEvent(object sender); - /// - /// EntryInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(EntryInfoConverter))] - public partial class EntryInfo : ReadOnlyBase, IDisposable - { - public event EntryInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(EntryInfo entryInfo) - { - if (!_CacheList.Contains(entryInfo)) _CacheList.Add(entryInfo); // In AddToCache - } - protected static void RemoveFromCache(EntryInfo entryInfo) - { - while (_CacheList.Contains(entryInfo)) _CacheList.Remove(entryInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (EntryInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (EntryInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(EntryInfoList lst) - { - foreach (EntryInfo item in lst) AddToCache(item); - } - protected static EntryInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private int _DocID; - public int DocID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocID", true); - if (_MyDocument != null) _DocID = _MyDocument.DocID; - return _DocID; - } - } - private DocumentInfo _MyDocument; - public DocumentInfo MyDocument - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocument", true); - if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); - return _MyDocument; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // TODO: Replace base EntryInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current EntryInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check EntryInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current EntryInfo - protected override object GetIdValue() - { - return _ContentID; - } - #endregion - #region Factory Methods - private static int _EntryInfoUnique = 0; - private static int EntryInfoUnique - { get { return ++_EntryInfoUnique; } } - private int _MyEntryInfoUnique = EntryInfoUnique; - public int MyEntryInfoUnique - { get { return _MyEntryInfoUnique; } } - protected EntryInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listEntryInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listEntryInfo.Contains(this)) listEntryInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Entry tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Entry tmp) - { - if (_DocID != tmp.DocID) - { - if (MyDocument != null) 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 - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _EntryInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyDocument != null) - { - _MyDocument.Dispose();// Dispose related value - _MyDocument = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(DocumentEntry tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(DocumentEntry tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _EntryInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyDocument != null) - { - _MyDocument.Dispose();// Dispose related value - _MyDocument = null;// Reset related value - } - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up EntryInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on EntryInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal EntryInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.Constructor", ex); - throw new DbCslaException("EntryInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _DocID = dr.GetInt32("DocID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getEntry"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("EntryInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension(); - [Serializable()] - partial class EntryInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(EntryInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class EntryInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is EntryInfo) - { - // Return the ToString value - return ((EntryInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void EntryInfoEvent(object sender); + /// + /// EntryInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(EntryInfoConverter))] + public partial class EntryInfo : ReadOnlyBase, IDisposable + { + public event EntryInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(EntryInfo entryInfo) + { + if (!_CacheList.Contains(entryInfo)) _CacheList.Add(entryInfo); // In AddToCache + } + protected static void RemoveFromCache(EntryInfo entryInfo) + { + while (_CacheList.Contains(entryInfo)) _CacheList.Remove(entryInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (EntryInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (EntryInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(EntryInfoList lst) + { + foreach (EntryInfo item in lst) AddToCache(item); + } + protected static EntryInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private int _DocID; + public int DocID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument != null) _DocID = _MyDocument.DocID; + return _DocID; + } + } + private DocumentInfo _MyDocument; + public DocumentInfo MyDocument + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocument == null && _DocID != 0) _MyDocument = DocumentInfo.Get(_DocID); + return _MyDocument; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // TODO: Replace base EntryInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current EntryInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check EntryInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current EntryInfo + protected override object GetIdValue() + { + return _ContentID; + } + #endregion + #region Factory Methods + private static int _EntryInfoUnique = 0; + private static int EntryInfoUnique + { get { return ++_EntryInfoUnique; } } + private int _MyEntryInfoUnique = EntryInfoUnique; + public int MyEntryInfoUnique + { get { return _MyEntryInfoUnique; } } + protected EntryInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listEntryInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listEntryInfo.Contains(this)) listEntryInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Entry tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Entry tmp) + { + if (_DocID != tmp.DocID) + { + if (MyDocument != null) 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 + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _EntryInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyDocument != null) + { + _MyDocument.Dispose();// Dispose related value + _MyDocument = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(DocumentEntry tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (EntryInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(DocumentEntry tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _EntryInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyDocument != null) + { + _MyDocument.Dispose();// Dispose related value + _MyDocument = null;// Reset related value + } + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up EntryInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on EntryInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal EntryInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.Constructor", ex); + throw new DbCslaException("EntryInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _DocID = dr.GetInt32("DocID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] EntryInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getEntry"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("EntryInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("EntryInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + EntryInfoExtension _EntryInfoExtension = new EntryInfoExtension(); + [Serializable()] + partial class EntryInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(EntryInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class EntryInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is EntryInfo) + { + // Return the ToString value + return ((EntryInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Folder.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Folder.cs index db5a4c6e..fbf54664 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Folder.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Folder.cs @@ -20,1467 +20,1437 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Folder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderConverter))] - public partial class Folder : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshFolders = new List(); - private List _RefreshFolderAssignments = new List(); - private List _RefreshFolderDocVersions = new List(); - private void AddToRefreshList(List refreshFolders, List refreshFolderAssignments, List refreshFolderDocVersions) - { - if (IsDirty) - refreshFolders.Add(this); - if (_FolderAssignments != null && _FolderAssignments.IsDirty) - { - foreach (FolderAssignment tmp in _FolderAssignments) - { - if (tmp.IsDirty) refreshFolderAssignments.Add(tmp); - } - } - if (_FolderDocVersions != null && _FolderDocVersions.IsDirty) - { - foreach (FolderDocVersion tmp in _FolderDocVersions) - { - if (tmp.IsDirty) refreshFolderDocVersions.Add(tmp); - } - } - if (_ChildFolders != null && _ChildFolders.IsDirty) - { - foreach (Folder tmp in _ChildFolders) - { - tmp.AddToRefreshList(refreshFolders, refreshFolderAssignments, refreshFolderDocVersions); - } - } - } - private void BuildRefreshList() - { - _RefreshFolders = new List(); - _RefreshFolderAssignments = new List(); - _RefreshFolderDocVersions = new List(); - AddToRefreshList(_RefreshFolders, _RefreshFolderAssignments, _RefreshFolderDocVersions); - } - private void ProcessRefreshList() - { - foreach (Folder tmp in _RefreshFolders) - { - FolderInfo.Refresh(tmp); - if (tmp._MyConnection != null) ConnectionInfo.Refresh(tmp._MyConnection); - if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); - } - foreach (FolderAssignment tmp in _RefreshFolderAssignments) - { - AssignmentInfo.Refresh(tmp); - } - foreach (FolderDocVersion tmp in _RefreshFolderDocVersions) - { - DocVersionInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Folder folder) - { - if (!_CacheList.Contains(folder)) _CacheList.Add(folder); // In AddToCache - } - protected static void RemoveFromCache(Folder folder) - { - while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByParentID_Name = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Folder tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) - { - _CacheByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name - } - _CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index - remove.Add(tmp); - } - foreach (Folder tmp in remove) - RemoveFromCache(tmp); - } - protected static Folder GetCachedByPrimaryKey(int folderID) - { - ConvertListToDictionary(); - string key = folderID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Folder GetCachedByParentID_Name(int parentID, string name) - { - ConvertListToDictionary(); - string key = parentID.ToString() + "_" + name.ToString(); - if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextFolderID = -1; - public static int NextFolderID - { - get { return _nextFolderID--; } - } - private int _FolderID; - [System.ComponentModel.DataObjectField(true, true)] - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - return _FolderID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private Folder _MyParent; - public Folder MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - PropertyHasChanged(); - } - } - } - private int _DBID; - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - if (_MyConnection != null) _DBID = _MyConnection.DBID; - return _DBID; - } - } - private Connection _MyConnection; - public Connection MyConnection - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyConnection", true); - if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); - return _MyConnection; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyConnection", true); - if (_MyConnection != value) - { - _MyConnection = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ShortName", true); - if (value == null) value = string.Empty; - if (_ShortName != value) - { - _ShortName = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ManualOrder", true); - if (_ManualOrder != value) - { - _ManualOrder = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _FolderAssignmentCount = 0; - /// - /// Count of FolderAssignments for this Folder - /// - public int FolderAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignmentCount", true); - return _FolderAssignmentCount; - } - } - private FolderAssignments _FolderAssignments = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FolderAssignmentsConverter))] - public FolderAssignments FolderAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignments", true); - if (_FolderAssignmentCount > 0 && _FolderAssignments == null) - _FolderAssignments = FolderAssignments.GetByFolderID(FolderID); - else if (_FolderAssignments == null) - _FolderAssignments = FolderAssignments.New(); - return _FolderAssignments; - } - } - private int _FolderDocVersionCount = 0; - /// - /// Count of FolderDocVersions for this Folder - /// - public int FolderDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersionCount", true); - return _FolderDocVersionCount; - } - } - private FolderDocVersions _FolderDocVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FolderDocVersionsConverter))] - public FolderDocVersions FolderDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersions", true); - if (_FolderDocVersionCount > 0 && _FolderDocVersions == null) - _FolderDocVersions = FolderDocVersions.GetByFolderID(FolderID); - else if (_FolderDocVersions == null) - _FolderDocVersions = FolderDocVersions.New(); - return _FolderDocVersions; - } - } - private int _ChildFolderCount = 0; - /// - /// Count of ChildFolders for this Folder - /// - public int ChildFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolderCount", true); - return _ChildFolderCount; - } - } - private ChildFolders _ChildFolders = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ChildFoldersConverter))] - public ChildFolders ChildFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolders", true); - if (_ChildFolderCount > 0 && _ChildFolders == null) - _ChildFolders = ChildFolders.GetByParentID(FolderID); - else if (_ChildFolders == null) - _ChildFolders = ChildFolders.New(); - return _ChildFolders; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_FolderAssignments == null ? false : _FolderAssignments.IsDirty) || (_FolderDocVersions == null ? false : _FolderDocVersions.IsDirty) || (_ChildFolders == null ? false : _ChildFolders.IsDirty) || (_MyConnection == null ? false : _MyConnection.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_FolderAssignments == null ? true : _FolderAssignments.IsValid) && (_FolderDocVersions == null ? true : _FolderDocVersions.IsValid) && (_ChildFolders == null ? true : _ChildFolders.IsValid) && (_MyConnection == null ? true : _MyConnection.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid); } - } - // TODO: Replace base Folder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Folder - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Folder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Folder - protected override object GetIdValue() - { - return _FolderID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_FolderAssignments != null && (hasBrokenRules = _FolderAssignments.HasBrokenRules) != null) return hasBrokenRules; - if (_FolderDocVersions != null && (hasBrokenRules = _FolderDocVersions.HasBrokenRules) != null) return hasBrokenRules; - if (_ChildFolders != null && (hasBrokenRules = _ChildFolders.HasBrokenRules) != null) return hasBrokenRules; - if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ShortName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _FolderExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _FolderExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyConnectionRequired(Folder target, Csla.Validation.RuleArgs e) - { - if (target._DBID == 0 && target._MyConnection == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowRead(DBID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ShortName, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(ManualOrder, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowWrite(DBID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ShortName, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowWrite(ManualOrder, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _FolderExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _FolderExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _FolderUnique = 0; - protected static int FolderUnique - { get { return ++_FolderUnique; } } - private int _MyFolderUnique = FolderUnique; - public int MyFolderUnique - { get { return _MyFolderUnique; } } - protected Folder() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) - { - List listFolder = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items - while (listFolder.Contains(this)) listFolder.Remove(this); // Remove the item from the list - if (listFolder.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByParentID_Name.Keys) - if (_CacheByParentID_Name[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listFolder = _CacheByParentID_Name[myKey]; // Get the list of items - listFolder.Remove(this); // Remove the item from the list - if (listFolder.Count == 0) //If there are no items left in the list - _CacheByParentID_Name.Remove(myKey); // remove the list - } - } - public static Folder New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Folder"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.New", ex); - } - } - public static Folder New(Folder myParent, string name, string shortName) - { - Folder tmp = Folder.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.ShortName = shortName; - return tmp; - } - public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) - { - Folder tmp = Folder.New(); - tmp.MyParent = myParent; - tmp.MyConnection = myConnection; - tmp.Name = name; - tmp.Title = title; - tmp.ShortName = shortName; - tmp.MyFormat = myFormat; - tmp.ManualOrder = manualOrder; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) - { - Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config, dts, usrID); - if (tmp.IsSavable) - { - Folder tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) - { - Folder tmp = Folder.New(); - tmp.MyParent = myParent; - tmp.MyConnection = myConnection; - tmp.Name = name; - tmp.Title = title; - tmp.ShortName = shortName; - tmp.MyFormat = myFormat; - tmp.ManualOrder = manualOrder; - tmp.Config = config; - return tmp; - } - public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) - { - Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config); - if (tmp.IsSavable) - { - Folder tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(folderID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Folder - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.Get", ex); - } - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Folder - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.GetByParentID_Name", ex); - } - } - public static Folder Get(SafeDataReader dr, Folder parent) - { - if (dr.Read()) return new Folder(dr, parent); - return null; - } - internal Folder(SafeDataReader dr) - { - ReadData(dr); - } - private Folder(SafeDataReader dr, Folder parent) - { - ReadData(dr); - MarkAsChild(); - } - internal Folder(SafeDataReader dr, int parentID) - { - ReadData(dr); - MarkAsChild(); - } - public static void Delete(int folderID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Folder"); - try - { - DataPortal.Delete(new PKCriteria(folderID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.Delete", ex); - } - } - 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(); - Folder folder = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(folder);//Refresh the item in AllList - ProcessRefreshList(); - return folder; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _FolderID; - public int FolderID - { get { return _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; } } - public ParentID_NameCriteria(int parentID, string name) - { - _ParentID = parentID; - _Name = name; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _FolderID = NextFolderID; - // Database Defaults - _ParentID = _FolderExtension.DefaultParentID; - _DBID = _FolderExtension.DefaultDBID; - _DTS = _FolderExtension.DefaultDTS; - _UsrID = _FolderExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.ReadData", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _FormatID = (int?)dr.GetValue("FormatID"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); - _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); - _ChildFolderCount = dr.GetInt32("ChildCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFolder"; - cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _FolderAssignments = FolderAssignments.Get(dr); - // load child objects - dr.NextResult(); - _FolderDocVersions = FolderDocVersions.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(ParentID_NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFolderByParentID_Name"; - cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); - cm.Parameters.AddWithValue("@Name", criteria.Name); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Folder.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyConnection != null) _MyConnection.Update(); - if (_MyFormat != null) _MyFormat.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addFolder"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ParentID", myParent.FolderID); - cm.Parameters.AddWithValue("@DBID", myConnection.DBID); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - cm.Parameters.AddWithValue("@ShortName", shortName); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - folderID = (int)cm.Parameters["@newFolderID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Add", ex); - throw new DbCslaException("Folder.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _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); - } - internal void DeleteSelf(Folder folder) - { - // 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"]; - Folder.Remove(cn, _FolderID); - MarkNew(); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(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, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateFolder"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FolderID", folderID); - cm.Parameters.AddWithValue("@ParentID", myParent.FolderID); - cm.Parameters.AddWithValue("@DBID", myConnection.DBID); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - cm.Parameters.AddWithValue("@ShortName", shortName); - if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Update", ex); - throw new DbCslaException("Folder.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_FolderID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteFolder"; - cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteFolder"; - // Input PK Fields - cm.Parameters.AddWithValue("@FolderID", folderID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Remove", ex); - throw new DbCslaException("Folder.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int folderID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(folderID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Folder.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _FolderID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int folderID) - { - _FolderID = folderID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsFolder"; - cm.Parameters.AddWithValue("@FolderID", _FolderID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Execute", ex); - throw new DbCslaException("Folder.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - FolderExtension _FolderExtension = new FolderExtension(); - [Serializable()] - partial class FolderExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FolderConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Folder) - { - // Return the ToString value - return ((Folder)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Folder Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderConverter))] + public partial class Folder : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshFolders = new List(); + private List _RefreshFolderAssignments = new List(); + private List _RefreshFolderDocVersions = new List(); + private void AddToRefreshList(List refreshFolders, List refreshFolderAssignments, List refreshFolderDocVersions) + { + if (IsDirty) + refreshFolders.Add(this); + if (_FolderAssignments != null && _FolderAssignments.IsDirty) + { + foreach (FolderAssignment tmp in _FolderAssignments) + { + if (tmp.IsDirty) refreshFolderAssignments.Add(tmp); + } + } + if (_FolderDocVersions != null && _FolderDocVersions.IsDirty) + { + foreach (FolderDocVersion tmp in _FolderDocVersions) + { + if (tmp.IsDirty) refreshFolderDocVersions.Add(tmp); + } + } + if (_ChildFolders != null && _ChildFolders.IsDirty) + { + foreach (Folder tmp in _ChildFolders) + { + tmp.AddToRefreshList(refreshFolders, refreshFolderAssignments, refreshFolderDocVersions); + } + } + } + private void BuildRefreshList() + { + _RefreshFolders = new List(); + _RefreshFolderAssignments = new List(); + _RefreshFolderDocVersions = new List(); + AddToRefreshList(_RefreshFolders, _RefreshFolderAssignments, _RefreshFolderDocVersions); + } + private void ProcessRefreshList() + { + foreach (Folder tmp in _RefreshFolders) + { + FolderInfo.Refresh(tmp); + if (tmp._MyConnection != null) ConnectionInfo.Refresh(tmp._MyConnection); + if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat); + } + foreach (FolderAssignment tmp in _RefreshFolderAssignments) + { + AssignmentInfo.Refresh(tmp); + } + foreach (FolderDocVersion tmp in _RefreshFolderDocVersions) + { + DocVersionInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Folder folder) + { + if (!_CacheList.Contains(folder)) _CacheList.Add(folder); // In AddToCache + } + protected static void RemoveFromCache(Folder folder) + { + while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByParentID_Name = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Folder tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) + { + _CacheByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name + } + _CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index + remove.Add(tmp); + } + foreach (Folder tmp in remove) + RemoveFromCache(tmp); + } + protected static Folder GetCachedByPrimaryKey(int folderID) + { + ConvertListToDictionary(); + string key = folderID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Folder GetCachedByParentID_Name(int parentID, string name) + { + ConvertListToDictionary(); + string key = parentID.ToString() + "_" + name.ToString(); + if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextFolderID = -1; + public static int NextFolderID + { + get { return _nextFolderID--; } + } + private int _FolderID; + [System.ComponentModel.DataObjectField(true, true)] + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private Folder _MyParent; + public Folder MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + PropertyHasChanged(); + } + } + } + private int _DBID; + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection != null) _DBID = _MyConnection.DBID; + return _DBID; + } + } + private Connection _MyConnection; + public Connection MyConnection + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); + return _MyConnection; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyConnection != value) + { + _MyConnection = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ShortName != value) + { + _ShortName = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ManualOrder != value) + { + _ManualOrder = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _FolderAssignmentCount = 0; + /// + /// Count of FolderAssignments for this Folder + /// + public int FolderAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderAssignmentCount; + } + } + private FolderAssignments _FolderAssignments = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FolderAssignmentsConverter))] + public FolderAssignments FolderAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderAssignmentCount > 0 && _FolderAssignments == null) + _FolderAssignments = FolderAssignments.GetByFolderID(FolderID); + else if (_FolderAssignments == null) + _FolderAssignments = FolderAssignments.New(); + return _FolderAssignments; + } + } + private int _FolderDocVersionCount = 0; + /// + /// Count of FolderDocVersions for this Folder + /// + public int FolderDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderDocVersionCount; + } + } + private FolderDocVersions _FolderDocVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FolderDocVersionsConverter))] + public FolderDocVersions FolderDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderDocVersionCount > 0 && _FolderDocVersions == null) + _FolderDocVersions = FolderDocVersions.GetByFolderID(FolderID); + else if (_FolderDocVersions == null) + _FolderDocVersions = FolderDocVersions.New(); + return _FolderDocVersions; + } + } + private int _ChildFolderCount = 0; + /// + /// Count of ChildFolders for this Folder + /// + public int ChildFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ChildFolderCount; + } + } + private ChildFolders _ChildFolders = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ChildFoldersConverter))] + public ChildFolders ChildFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFolderCount > 0 && _ChildFolders == null) + _ChildFolders = ChildFolders.GetByParentID(FolderID); + else if (_ChildFolders == null) + _ChildFolders = ChildFolders.New(); + return _ChildFolders; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_FolderAssignments == null ? false : _FolderAssignments.IsDirty) || (_FolderDocVersions == null ? false : _FolderDocVersions.IsDirty) || (_ChildFolders == null ? false : _ChildFolders.IsDirty) || (_MyConnection == null ? false : _MyConnection.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_FolderAssignments == null ? true : _FolderAssignments.IsValid) && (_FolderDocVersions == null ? true : _FolderDocVersions.IsValid) && (_ChildFolders == null ? true : _ChildFolders.IsValid) && (_MyConnection == null ? true : _MyConnection.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid); } + } + // TODO: Replace base Folder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Folder + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Folder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Folder + protected override object GetIdValue() + { + return _FolderID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_FolderAssignments != null && (hasBrokenRules = _FolderAssignments.HasBrokenRules) != null) return hasBrokenRules; + if (_FolderDocVersions != null && (hasBrokenRules = _FolderDocVersions.HasBrokenRules) != null) return hasBrokenRules; + if (_ChildFolders != null && (hasBrokenRules = _ChildFolders.HasBrokenRules) != null) return hasBrokenRules; + if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ShortName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _FolderExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _FolderExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyConnectionRequired(Folder target, Csla.Validation.RuleArgs e) + { + if (target._DBID == 0 && target._MyConnection == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowRead(DBID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(ShortName, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowWrite(DBID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(ShortName, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _FolderExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _FolderExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _FolderUnique = 0; + protected static int FolderUnique + { get { return ++_FolderUnique; } } + private int _MyFolderUnique = FolderUnique; + public int MyFolderUnique + { get { return _MyFolderUnique; } } + protected Folder() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) + { + List listFolder = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items + while (listFolder.Contains(this)) listFolder.Remove(this); // Remove the item from the list + if (listFolder.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByParentID_Name.Keys) + if (_CacheByParentID_Name[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listFolder = _CacheByParentID_Name[myKey]; // Get the list of items + listFolder.Remove(this); // Remove the item from the list + if (listFolder.Count == 0) //If there are no items left in the list + _CacheByParentID_Name.Remove(myKey); // remove the list + } + } + public static Folder New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Folder"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.New", ex); + } + } + public static Folder New(Folder myParent, string name, string shortName) + { + Folder tmp = Folder.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.ShortName = shortName; + return tmp; + } + public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) + { + Folder tmp = Folder.New(); + tmp.MyParent = myParent; + tmp.MyConnection = myConnection; + tmp.Name = name; + tmp.Title = title; + tmp.ShortName = shortName; + tmp.MyFormat = myFormat; + tmp.ManualOrder = manualOrder; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID) + { + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config, dts, usrID); + if (tmp.IsSavable) + { + Folder tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) + { + Folder tmp = Folder.New(); + tmp.MyParent = myParent; + tmp.MyConnection = myConnection; + tmp.Name = name; + tmp.Title = title; + tmp.ShortName = shortName; + tmp.MyFormat = myFormat; + tmp.ManualOrder = manualOrder; + tmp.Config = config; + return tmp; + } + public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config) + { + Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config); + if (tmp.IsSavable) + { + Folder tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(folderID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Folder + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.Get", ex); + } + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Folder + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.GetByParentID_Name", ex); + } + } + public static Folder Get(SafeDataReader dr, Folder parent) + { + if (dr.Read()) return new Folder(dr, parent); + return null; + } + internal Folder(SafeDataReader dr) + { + ReadData(dr); + } + private Folder(SafeDataReader dr, Folder parent) + { + ReadData(dr); + MarkAsChild(); + } + internal Folder(SafeDataReader dr, int parentID) + { + ReadData(dr); + MarkAsChild(); + } + public static void Delete(int folderID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Folder"); + try + { + DataPortal.Delete(new PKCriteria(folderID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.Delete", ex); + } + } + 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(); + Folder folder = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(folder);//Refresh the item in AllList + ProcessRefreshList(); + return folder; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _FolderID; + public int FolderID + { get { return _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; } } + public ParentID_NameCriteria(int parentID, string name) + { + _ParentID = parentID; + _Name = name; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _FolderID = NextFolderID; + // Database Defaults + _ParentID = _FolderExtension.DefaultParentID; + _DBID = _FolderExtension.DefaultDBID; + _DTS = _FolderExtension.DefaultDTS; + _UsrID = _FolderExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.ReadData", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); + _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); + _ChildFolderCount = dr.GetInt32("ChildCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolder"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _FolderAssignments = FolderAssignments.Get(dr); + // load child objects + dr.NextResult(); + _FolderDocVersions = FolderDocVersions.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(ParentID_NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolderByParentID_Name"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + cm.Parameters.AddWithValue("@Name", criteria.Name); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Folder.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyConnection != null) _MyConnection.Update(); + if (_MyFormat != null) _MyFormat.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addFolder"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ParentID", myParent.FolderID); + cm.Parameters.AddWithValue("@DBID", myConnection.DBID); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + cm.Parameters.AddWithValue("@ShortName", shortName); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + folderID = (int)cm.Parameters["@newFolderID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Add", ex); + throw new DbCslaException("Folder.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _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); + } + internal void DeleteSelf(Folder folder) + { + // 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"]; + Folder.Remove(cn, _FolderID); + MarkNew(); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(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, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateFolder"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FolderID", folderID); + cm.Parameters.AddWithValue("@ParentID", myParent.FolderID); + cm.Parameters.AddWithValue("@DBID", myConnection.DBID); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + cm.Parameters.AddWithValue("@ShortName", shortName); + if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Update", ex); + throw new DbCslaException("Folder.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_FolderID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteFolder"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteFolder"; + // Input PK Fields + cm.Parameters.AddWithValue("@FolderID", folderID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.Remove", ex); + throw new DbCslaException("Folder.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int folderID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(folderID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Folder.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _FolderID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int folderID) + { + _FolderID = folderID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsFolder"; + cm.Parameters.AddWithValue("@FolderID", _FolderID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Folder.DataPortal_Execute", ex); + throw new DbCslaException("Folder.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + FolderExtension _FolderExtension = new FolderExtension(); + [Serializable()] + partial class FolderExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FolderConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Folder) + { + // Return the ToString value + return ((Folder)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderAssignment.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderAssignment.cs index 1f75dc61..bed984bb 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderAssignment.cs @@ -19,632 +19,607 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FolderAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderAssignmentConverter))] - public partial class FolderAssignment : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - if (_MyAssignment != null) _AID = _MyAssignment.AID; - return _AID; - } - } - private Assignment _MyAssignment; - [System.ComponentModel.DataObjectField(true, true)] - public Assignment MyAssignment - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssignment", true); - if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); - return _MyAssignment; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - PropertyHasChanged(); - } - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private Role _MyRole; - public Role MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); - return _MyRole; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRole", true); - if (_MyRole != value) - { - _MyRole = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Group_GroupName = string.Empty; - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupName", true); - return _Group_GroupName; - } - } - private int? _Group_GroupType; - public int? Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupType", true); - return _Group_GroupType; - } - } - private string _Group_Config = string.Empty; - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_Config", true); - return _Group_Config; - } - } - private DateTime _Group_DTS = new DateTime(); - public DateTime Group_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_DTS", true); - return _Group_DTS; - } - } - private string _Group_UsrID = string.Empty; - public string Group_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_UsrID", true); - return _Group_UsrID; - } - } - private string _Role_Name = string.Empty; - public string Role_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Name", true); - return _Role_Name; - } - } - private string _Role_Title = string.Empty; - public string Role_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Title", true); - return _Role_Title; - } - } - private DateTime _Role_DTS = new DateTime(); - public DateTime Role_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_DTS", true); - return _Role_DTS; - } - } - private string _Role_UsrID = string.Empty; - public string Role_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_UsrID", true); - return _Role_UsrID; - } - } - // TODO: Check FolderAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderAssignment - protected override object GetIdValue() - { - return _AID; - } - // TODO: Replace base FolderAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyRole == null ? false : _MyRole.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyRole == null ? true : _MyRole.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule(MyRoleRequired, "MyRole"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool StartDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyGroupRequired(FolderAssignment target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyRoleRequired(FolderAssignment target, Csla.Validation.RuleArgs e) - { - if (target._RID == 0 && target._MyRole == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AID, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowWrite(RID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static FolderAssignment New(Group myGroup, Role myRole) - { - return new FolderAssignment(myGroup, myRole); - } - internal static FolderAssignment Get(SafeDataReader dr) - { - return new FolderAssignment(dr); - } - public FolderAssignment() - { - MarkAsChild(); - _AID = Assignment.NextAID; - _StartDate = _FolderAssignmentExtension.DefaultStartDate; - _DTS = _FolderAssignmentExtension.DefaultDTS; - _UsrID = _FolderAssignmentExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private FolderAssignment(Group myGroup, Role myRole) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _StartDate = _FolderAssignmentExtension.DefaultStartDate; - _DTS = _FolderAssignmentExtension.DefaultDTS; - _UsrID = _FolderAssignmentExtension.DefaultUsrID; - _MyGroup = myGroup; - _MyRole = myRole; - ValidationRules.CheckRules(); - } - internal FolderAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderAssignment.FetchDR", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _GID = dr.GetInt32("GID"); - _RID = dr.GetInt32("RID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Group_GroupName = dr.GetString("Group_GroupName"); - _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); - _Group_Config = dr.GetString("Group_Config"); - _Group_DTS = dr.GetDateTime("Group_DTS"); - _Group_UsrID = dr.GetString("Group_UsrID"); - _Role_Name = dr.GetString("Role_Name"); - _Role_Title = dr.GetString("Role_Title"); - _Role_DTS = dr.GetDateTime("Role_DTS"); - _Role_UsrID = dr.GetString("Role_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderAssignment.FetchDR", ex); - throw new DbCslaException("FolderAssignment.Fetch", ex); - } - MarkOld(); - } - 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); - 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, _MyGroup, _MyRole, myFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Folder myFolder) - { - // 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension(); - [Serializable()] - partial class FolderAssignmentExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FolderAssignmentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FolderAssignment) - { - // Return the ToString value - return ((FolderAssignment)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FolderAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderAssignmentConverter))] + public partial class FolderAssignment : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment != null) _AID = _MyAssignment.AID; + return _AID; + } + } + private Assignment _MyAssignment; + [System.ComponentModel.DataObjectField(true, true)] + public Assignment MyAssignment + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); + return _MyAssignment; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + PropertyHasChanged(); + } + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private Role _MyRole; + public Role MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); + return _MyRole; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRole != value) + { + _MyRole = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Group_GroupName = string.Empty; + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupName; + } + } + private int? _Group_GroupType; + public int? Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupType; + } + } + private string _Group_Config = string.Empty; + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_Config; + } + } + private DateTime _Group_DTS = new DateTime(); + public DateTime Group_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_DTS; + } + } + private string _Group_UsrID = string.Empty; + public string Group_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_UsrID; + } + } + private string _Role_Name = string.Empty; + public string Role_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Name; + } + } + private string _Role_Title = string.Empty; + public string Role_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Title; + } + } + private DateTime _Role_DTS = new DateTime(); + public DateTime Role_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_DTS; + } + } + private string _Role_UsrID = string.Empty; + public string Role_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_UsrID; + } + } + // TODO: Check FolderAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderAssignment + protected override object GetIdValue() + { + return _AID; + } + // TODO: Replace base FolderAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyRole == null ? false : _MyRole.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyRole == null ? true : _MyRole.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule(MyRoleRequired, "MyRole"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool StartDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(FolderAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyGroupRequired(FolderAssignment target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyRoleRequired(FolderAssignment target, Csla.Validation.RuleArgs e) + { + if (target._RID == 0 && target._MyRole == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(AID, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowWrite(RID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static FolderAssignment New(Group myGroup, Role myRole) + { + return new FolderAssignment(myGroup, myRole); + } + internal static FolderAssignment Get(SafeDataReader dr) + { + return new FolderAssignment(dr); + } + public FolderAssignment() + { + MarkAsChild(); + _AID = Assignment.NextAID; + _StartDate = _FolderAssignmentExtension.DefaultStartDate; + _DTS = _FolderAssignmentExtension.DefaultDTS; + _UsrID = _FolderAssignmentExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private FolderAssignment(Group myGroup, Role myRole) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _StartDate = _FolderAssignmentExtension.DefaultStartDate; + _DTS = _FolderAssignmentExtension.DefaultDTS; + _UsrID = _FolderAssignmentExtension.DefaultUsrID; + _MyGroup = myGroup; + _MyRole = myRole; + ValidationRules.CheckRules(); + } + internal FolderAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderAssignment.FetchDR", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _GID = dr.GetInt32("GID"); + _RID = dr.GetInt32("RID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Group_GroupName = dr.GetString("Group_GroupName"); + _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); + _Group_Config = dr.GetString("Group_Config"); + _Group_DTS = dr.GetDateTime("Group_DTS"); + _Group_UsrID = dr.GetString("Group_UsrID"); + _Role_Name = dr.GetString("Role_Name"); + _Role_Title = dr.GetString("Role_Title"); + _Role_DTS = dr.GetDateTime("Role_DTS"); + _Role_UsrID = dr.GetString("Role_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderAssignment.FetchDR", ex); + throw new DbCslaException("FolderAssignment.Fetch", ex); + } + MarkOld(); + } + 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); + 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, _MyGroup, _MyRole, myFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Folder myFolder) + { + // 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FolderAssignmentExtension _FolderAssignmentExtension = new FolderAssignmentExtension(); + [Serializable()] + partial class FolderAssignmentExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FolderAssignmentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderAssignment) + { + // Return the ToString value + return ((FolderAssignment)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderDocVersion.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderDocVersion.cs index 733f6aff..03f3908f 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderDocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderDocVersion.cs @@ -19,519 +19,499 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FolderDocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderDocVersionConverter))] - public partial class FolderDocVersion : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyItem = value; - _ItemID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check FolderDocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderDocVersion - protected override object GetIdValue() - { - return _VersionID; - } - // TODO: Replace base FolderDocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderDocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static FolderDocVersion New(string name) - { - return new FolderDocVersion(name); - } - internal static FolderDocVersion Get(SafeDataReader dr) - { - return new FolderDocVersion(dr); - } - public FolderDocVersion() - { - MarkAsChild(); - _VersionID = DocVersion.NextVersionID; - _VersionType = _FolderDocVersionExtension.DefaultVersionType; - _DTS = _FolderDocVersionExtension.DefaultDTS; - _UserID = _FolderDocVersionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private FolderDocVersion(string name) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _VersionType = _FolderDocVersionExtension.DefaultVersionType; - _DTS = _FolderDocVersionExtension.DefaultDTS; - _UserID = _FolderDocVersionExtension.DefaultUserID; - _Name = name; - ValidationRules.CheckRules(); - } - internal FolderDocVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderDocVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderDocVersion.FetchDR", ex); - throw new DbCslaException("FolderDocVersion.Fetch", ex); - } - MarkOld(); - } - 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); - 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, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Folder myFolder) - { - // 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension(); - [Serializable()] - partial class FolderDocVersionExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FolderDocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FolderDocVersion) - { - // Return the ToString value - return ((FolderDocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FolderDocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderDocVersionConverter))] + public partial class FolderDocVersion : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyItem = value; + _ItemID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check FolderDocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderDocVersion + protected override object GetIdValue() + { + return _VersionID; + } + // TODO: Replace base FolderDocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderDocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static FolderDocVersion New(string name) + { + return new FolderDocVersion(name); + } + internal static FolderDocVersion Get(SafeDataReader dr) + { + return new FolderDocVersion(dr); + } + public FolderDocVersion() + { + MarkAsChild(); + _VersionID = DocVersion.NextVersionID; + _VersionType = _FolderDocVersionExtension.DefaultVersionType; + _DTS = _FolderDocVersionExtension.DefaultDTS; + _UserID = _FolderDocVersionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private FolderDocVersion(string name) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _VersionType = _FolderDocVersionExtension.DefaultVersionType; + _DTS = _FolderDocVersionExtension.DefaultDTS; + _UserID = _FolderDocVersionExtension.DefaultUserID; + _Name = name; + ValidationRules.CheckRules(); + } + internal FolderDocVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderDocVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderDocVersion.FetchDR", ex); + throw new DbCslaException("FolderDocVersion.Fetch", ex); + } + MarkOld(); + } + 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); + 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, _VersionType, _Name, _Title, _MyItem, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Folder myFolder) + { + // 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FolderDocVersionExtension _FolderDocVersionExtension = new FolderDocVersionExtension(); + [Serializable()] + partial class FolderDocVersionExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FolderDocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderDocVersion) + { + // Return the ToString value + return ((FolderDocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderInfo.cs index 0a4b88f4..a8e7fd3e 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FolderInfo.cs @@ -19,664 +19,644 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void FolderInfoEvent(object sender); - /// - /// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FolderInfoConverter))] - public partial class FolderInfo : ReadOnlyBase, IDisposable - { - public event FolderInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(FolderInfo folderInfo) - { - if (!_CacheList.Contains(folderInfo)) _CacheList.Add(folderInfo); // In AddToCache - } - protected static void RemoveFromCache(FolderInfo folderInfo) - { - while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (FolderInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) - { - _CacheByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (FolderInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(FolderInfoList lst) - { - foreach (FolderInfo item in lst) AddToCache(item); - } - protected static FolderInfo GetCachedByPrimaryKey(int folderID) - { - ConvertListToDictionary(); - string key = folderID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - return _FolderID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private FolderInfo _MyParent; - public FolderInfo MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = FolderInfo.Get(_ParentID); - return _MyParent; - } - } - private int _DBID; - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - if (_MyConnection != null) _DBID = _MyConnection.DBID; - return _DBID; - } - } - private ConnectionInfo _MyConnection; - public ConnectionInfo MyConnection - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyConnection", true); - if (_MyConnection == null && _DBID != 0) _MyConnection = ConnectionInfo.Get(_DBID); - return _MyConnection; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private FormatInfo _MyFormat; - public FormatInfo MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); - return _MyFormat; - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _FolderAssignmentCount = 0; - /// - /// Count of FolderAssignments for this Folder - /// - public int FolderAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignmentCount", true); - return _FolderAssignmentCount; - } - } - private AssignmentInfoList _FolderAssignments = null; - [TypeConverter(typeof(AssignmentInfoListConverter))] - public AssignmentInfoList FolderAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderAssignments", true); - if (_FolderAssignmentCount < 0 || (_FolderAssignmentCount > 0 && _FolderAssignments == null)) - _FolderAssignments = AssignmentInfoList.GetByFolderID(_FolderID); - if (_FolderAssignmentCount < 0) - _FolderAssignmentCount = _FolderAssignments.Count; - return _FolderAssignments; - } - } - public void RefreshFolderAssignments() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) - tmp._FolderAssignmentCount = -1; // This will cause the data to be requeried - } - private int _FolderDocVersionCount = 0; - /// - /// Count of FolderDocVersions for this Folder - /// - public int FolderDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersionCount", true); - return _FolderDocVersionCount; - } - } - private DocVersionInfoList _FolderDocVersions = null; - [TypeConverter(typeof(DocVersionInfoListConverter))] - public DocVersionInfoList FolderDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderDocVersions", true); - if (_FolderDocVersionCount < 0 || (_FolderDocVersionCount > 0 && _FolderDocVersions == null)) - _FolderDocVersions = DocVersionInfoList.GetByFolderID(_FolderID); - if (_FolderDocVersionCount < 0) - _FolderDocVersionCount = _FolderDocVersions.Count; - return _FolderDocVersions; - } - } - public void RefreshFolderDocVersions() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) - tmp._FolderDocVersionCount = -1; // This will cause the data to be requeried - } - private int _ChildFolderCount = 0; - /// - /// Count of ChildFolders for this Folder - /// - public int ChildFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolderCount", true); - return _ChildFolderCount; - } - } - private FolderInfoList _ChildFolders = null; - [TypeConverter(typeof(FolderInfoListConverter))] - public FolderInfoList ChildFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFolders", true); - if (_ChildFolderCount < 0 || (_ChildFolderCount > 0 && _ChildFolders == null)) - _ChildFolders = FolderInfoList.GetChildren(_FolderID); - if (_ChildFolderCount < 0) - _ChildFolderCount = _ChildFolders.Count; - return _ChildFolders; - } - } - public void RefreshChildFolders() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) - foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) - tmp._ChildFolderCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base FolderInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderInfo - protected override object GetIdValue() - { - return _FolderID; - } - #endregion - #region Factory Methods - private static int _FolderInfoUnique = 0; - private static int FolderInfoUnique - { get { return ++_FolderInfoUnique; } } - private int _MyFolderInfoUnique = FolderInfoUnique; - public int MyFolderInfoUnique - { get { return _MyFolderInfoUnique; } } - protected FolderInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) return; - List listFolderInfo = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items - while (listFolderInfo.Contains(this)) listFolderInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Folder tmp) - { - string key = tmp.FolderID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Folder tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - if (_DBID != tmp.DBID) - { - if (MyConnection != null) 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 - _Name = tmp.Name; - _Title = tmp.Title; - _ShortName = tmp.ShortName; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _ManualOrder = tmp.ManualOrder; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _FolderInfoExtension.Refresh(this); - if(_MyParent != null) - { - _MyParent.Dispose();// Dispose related value - _MyParent = null;// Reset related value - } - if(_MyConnection != null) - { - _MyConnection.Dispose();// Dispose related value - _MyConnection = null;// Reset related value - } - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ConnectionFolder tmp) - { - string key = tmp.FolderID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ConnectionFolder tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - _Name = tmp.Name; - _Title = tmp.Title; - _ShortName = tmp.ShortName; - if (_FormatID != tmp.FormatID) - { - if (MyFormat != null) 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 - _ManualOrder = tmp.ManualOrder; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _FolderInfoExtension.Refresh(this); - if(_MyParent != null) - { - _MyParent.Dispose();// Dispose related value - _MyParent = null;// Reset related value - } - if(_MyConnection != null) - { - _MyConnection.Dispose();// Dispose related value - _MyConnection = null;// Reset related value - } - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(FormatFolder tmp) - { - string key = tmp.FolderID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(FormatFolder tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - if (_DBID != tmp.DBID) - { - if (MyConnection != null) 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 - _Name = tmp.Name; - _Title = tmp.Title; - _ShortName = tmp.ShortName; - _ManualOrder = tmp.ManualOrder; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _FolderInfoExtension.Refresh(this); - if(_MyParent != null) - { - _MyParent.Dispose();// Dispose related value - _MyParent = null;// Reset related value - } - if(_MyConnection != null) - { - _MyConnection.Dispose();// Dispose related value - _MyConnection = null;// Reset related value - } - if(_MyFormat != null) - { - _MyFormat.Dispose();// Dispose related value - _MyFormat = null;// Reset related value - } - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(folderID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up FolderInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on FolderInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal FolderInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.Constructor", ex); - throw new DbCslaException("FolderInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _FolderID; - public int FolderID - { get { return _FolderID; } } - public PKCriteria(int folderID) - { - _FolderID = folderID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.ReadData", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _FormatID = (int?)dr.GetValue("FormatID"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); - _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); - _ChildFolderCount = dr.GetInt32("ChildCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FolderInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFolder"; - cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FolderInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension(); - [Serializable()] - partial class FolderInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(FolderInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class FolderInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FolderInfo) - { - // Return the ToString value - return ((FolderInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void FolderInfoEvent(object sender); + /// + /// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FolderInfoConverter))] + public partial class FolderInfo : ReadOnlyBase, IDisposable + { + public event FolderInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(FolderInfo folderInfo) + { + if (!_CacheList.Contains(folderInfo)) _CacheList.Add(folderInfo); // In AddToCache + } + protected static void RemoveFromCache(FolderInfo folderInfo) + { + while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (FolderInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString())) + { + _CacheByPrimaryKey[tmp.FolderID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (FolderInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(FolderInfoList lst) + { + foreach (FolderInfo item in lst) AddToCache(item); + } + protected static FolderInfo GetCachedByPrimaryKey(int folderID) + { + ConvertListToDictionary(); + string key = folderID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private FolderInfo _MyParent; + public FolderInfo MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = FolderInfo.Get(_ParentID); + return _MyParent; + } + } + private int _DBID; + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection != null) _DBID = _MyConnection.DBID; + return _DBID; + } + } + private ConnectionInfo _MyConnection; + public ConnectionInfo MyConnection + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection == null && _DBID != 0) _MyConnection = ConnectionInfo.Get(_DBID); + return _MyConnection; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private FormatInfo _MyFormat; + public FormatInfo MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID); + return _MyFormat; + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _FolderAssignmentCount = 0; + /// + /// Count of FolderAssignments for this Folder + /// + public int FolderAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderAssignmentCount; + } + } + private AssignmentInfoList _FolderAssignments = null; + [TypeConverter(typeof(AssignmentInfoListConverter))] + public AssignmentInfoList FolderAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderAssignmentCount < 0 || (_FolderAssignmentCount > 0 && _FolderAssignments == null)) + _FolderAssignments = AssignmentInfoList.GetByFolderID(_FolderID); + if (_FolderAssignmentCount < 0) + _FolderAssignmentCount = _FolderAssignments.Count; + return _FolderAssignments; + } + } + public void RefreshFolderAssignments() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) + tmp._FolderAssignmentCount = -1; // This will cause the data to be requeried + } + private int _FolderDocVersionCount = 0; + /// + /// Count of FolderDocVersions for this Folder + /// + public int FolderDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderDocVersionCount; + } + } + private DocVersionInfoList _FolderDocVersions = null; + [TypeConverter(typeof(DocVersionInfoListConverter))] + public DocVersionInfoList FolderDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FolderDocVersionCount < 0 || (_FolderDocVersionCount > 0 && _FolderDocVersions == null)) + _FolderDocVersions = DocVersionInfoList.GetByFolderID(_FolderID); + if (_FolderDocVersionCount < 0) + _FolderDocVersionCount = _FolderDocVersions.Count; + return _FolderDocVersions; + } + } + public void RefreshFolderDocVersions() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) + tmp._FolderDocVersionCount = -1; // This will cause the data to be requeried + } + private int _ChildFolderCount = 0; + /// + /// Count of ChildFolders for this Folder + /// + public int ChildFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ChildFolderCount; + } + } + private FolderInfoList _ChildFolders = null; + [TypeConverter(typeof(FolderInfoListConverter))] + public FolderInfoList ChildFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFolderCount < 0 || (_ChildFolderCount > 0 && _ChildFolders == null)) + _ChildFolders = FolderInfoList.GetChildren(_FolderID); + if (_ChildFolderCount < 0) + _ChildFolderCount = _ChildFolders.Count; + return _ChildFolders; + } + } + public void RefreshChildFolders() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString())) + foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()]) + tmp._ChildFolderCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base FolderInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderInfo + protected override object GetIdValue() + { + return _FolderID; + } + #endregion + #region Factory Methods + private static int _FolderInfoUnique = 0; + private static int FolderInfoUnique + { get { return ++_FolderInfoUnique; } } + private int _MyFolderInfoUnique = FolderInfoUnique; + public int MyFolderInfoUnique + { get { return _MyFolderInfoUnique; } } + protected FolderInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) return; + List listFolderInfo = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items + while (listFolderInfo.Contains(this)) listFolderInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Folder tmp) + { + string key = tmp.FolderID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Folder tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + if (_DBID != tmp.DBID) + { + if (MyConnection != null) 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 + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _ManualOrder = tmp.ManualOrder; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + if (_MyParent != null) + { + _MyParent.Dispose();// Dispose related value + _MyParent = null;// Reset related value + } + if (_MyConnection != null) + { + _MyConnection.Dispose();// Dispose related value + _MyConnection = null;// Reset related value + } + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ConnectionFolder tmp) + { + string key = tmp.FolderID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ConnectionFolder tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + if (_FormatID != tmp.FormatID) + { + if (MyFormat != null) 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 + _ManualOrder = tmp.ManualOrder; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + if (_MyParent != null) + { + _MyParent.Dispose();// Dispose related value + _MyParent = null;// Reset related value + } + if (_MyConnection != null) + { + _MyConnection.Dispose();// Dispose related value + _MyConnection = null;// Reset related value + } + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(FormatFolder tmp) + { + string key = tmp.FolderID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(FormatFolder tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + if (_DBID != tmp.DBID) + { + if (MyConnection != null) 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 + _Name = tmp.Name; + _Title = tmp.Title; + _ShortName = tmp.ShortName; + _ManualOrder = tmp.ManualOrder; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _FolderInfoExtension.Refresh(this); + if (_MyParent != null) + { + _MyParent.Dispose();// Dispose related value + _MyParent = null;// Reset related value + } + if (_MyConnection != null) + { + _MyConnection.Dispose();// Dispose related value + _MyConnection = null;// Reset related value + } + if (_MyFormat != null) + { + _MyFormat.Dispose();// Dispose related value + _MyFormat = null;// Reset related value + } + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(folderID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FolderInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FolderInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal FolderInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.Constructor", ex); + throw new DbCslaException("FolderInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _FolderID; + public int FolderID + { get { return _FolderID; } } + public PKCriteria(int folderID) + { + _FolderID = folderID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.ReadData", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _FormatID = (int?)dr.GetValue("FormatID"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _FolderAssignmentCount = dr.GetInt32("AssignmentCount"); + _FolderDocVersionCount = dr.GetInt32("DocVersionCount"); + _ChildFolderCount = dr.GetInt32("ChildCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FolderInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolder"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FolderInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension(); + [Serializable()] + partial class FolderInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(FolderInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class FolderInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FolderInfo) + { + // Return the ToString value + return ((FolderInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Format.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Format.cs index c57d1137..5cde382a 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Format.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Format.cs @@ -20,1385 +20,1361 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Format Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatConverter))] - public partial class Format : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshFormats = new List(); - private List _RefreshFormatContents = new List(); - private List _RefreshFormatDocVersions = new List(); - private List _RefreshFormatFolders = new List(); - private void AddToRefreshList(List refreshFormats, List refreshFormatContents, List refreshFormatDocVersions, List refreshFormatFolders) - { - if (IsDirty) - refreshFormats.Add(this); - if (_FormatContents != null && _FormatContents.IsDirty) - { - foreach (FormatContent tmp in _FormatContents) - { - if (tmp.IsDirty) refreshFormatContents.Add(tmp); - } - } - if (_FormatDocVersions != null && _FormatDocVersions.IsDirty) - { - foreach (FormatDocVersion tmp in _FormatDocVersions) - { - if (tmp.IsDirty) refreshFormatDocVersions.Add(tmp); - } - } - if (_FormatFolders != null && _FormatFolders.IsDirty) - { - foreach (FormatFolder tmp in _FormatFolders) - { - if (tmp.IsDirty) refreshFormatFolders.Add(tmp); - } - } - if (_ChildFormats != null && _ChildFormats.IsDirty) - { - foreach (Format tmp in _ChildFormats) - { - tmp.AddToRefreshList(refreshFormats, refreshFormatContents, refreshFormatDocVersions, refreshFormatFolders); - } - } - } - private void BuildRefreshList() - { - _RefreshFormats = new List(); - _RefreshFormatContents = new List(); - _RefreshFormatDocVersions = new List(); - _RefreshFormatFolders = new List(); - AddToRefreshList(_RefreshFormats, _RefreshFormatContents, _RefreshFormatDocVersions, _RefreshFormatFolders); - } - private void ProcessRefreshList() - { - foreach (Format tmp in _RefreshFormats) - { - FormatInfo.Refresh(tmp); - } - foreach (FormatContent tmp in _RefreshFormatContents) - { - ContentInfo.Refresh(tmp); - } - foreach (FormatDocVersion tmp in _RefreshFormatDocVersions) - { - DocVersionInfo.Refresh(tmp); - } - foreach (FormatFolder tmp in _RefreshFormatFolders) - { - FolderInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Format format) - { - if (!_CacheList.Contains(format)) _CacheList.Add(format); // In AddToCache - } - protected static void RemoveFromCache(Format format) - { - while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByParentID_Name = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Format tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.FormatID.ToString())) - { - _CacheByPrimaryKey[tmp.FormatID.ToString()] = new List(); // Add new list for PrimaryKey - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name - } - _CacheByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list - _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index - remove.Add(tmp); - } - foreach (Format tmp in remove) - RemoveFromCache(tmp); - } - protected static Format GetCachedByPrimaryKey(int formatID) - { - ConvertListToDictionary(); - string key = formatID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Format GetCachedByParentID_Name(int parentID, string name) - { - ConvertListToDictionary(); - string key = parentID.ToString() + "_" + name.ToString(); - if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextFormatID = -1; - public static int NextFormatID - { - get { return _nextFormatID--; } - } - private int _FormatID; - [System.ComponentModel.DataObjectField(true, true)] - public int FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FormatID; - return _ParentID; - } - } - private Format _MyParent; - public Format MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FormatID) _MyParent = Format.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Description = string.Empty; - public string Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Description", true); - return _Description; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Description", true); - if (value == null) value = string.Empty; - if (_Description != value) - { - _Description = value; - PropertyHasChanged(); - } - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Data", true); - if (value == null) value = string.Empty; - if (_Data != value) - { - _Data = value; - PropertyHasChanged(); - } - } - } - private string _GenMac = string.Empty; - public string GenMac - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GenMac", true); - return _GenMac; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("GenMac", true); - if (value == null) value = string.Empty; - if (_GenMac != value) - { - _GenMac = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _FormatContentCount = 0; - /// - /// Count of FormatContents for this Format - /// - public int FormatContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContentCount", true); - return _FormatContentCount; - } - } - private FormatContents _FormatContents = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FormatContentsConverter))] - public FormatContents FormatContents - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContents", true); - if (_FormatContentCount > 0 && _FormatContents == null) - _FormatContents = FormatContents.GetByFormatID(FormatID); - else if (_FormatContents == null) - _FormatContents = FormatContents.New(); - return _FormatContents; - } - } - private int _FormatDocVersionCount = 0; - /// - /// Count of FormatDocVersions for this Format - /// - public int FormatDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersionCount", true); - return _FormatDocVersionCount; - } - } - private FormatDocVersions _FormatDocVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FormatDocVersionsConverter))] - public FormatDocVersions FormatDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersions", true); - if (_FormatDocVersionCount > 0 && _FormatDocVersions == null) - _FormatDocVersions = FormatDocVersions.GetByFormatID(FormatID); - else if (_FormatDocVersions == null) - _FormatDocVersions = FormatDocVersions.New(); - return _FormatDocVersions; - } - } - private int _FormatFolderCount = 0; - /// - /// Count of FormatFolders for this Format - /// - public int FormatFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolderCount", true); - return _FormatFolderCount; - } - } - private FormatFolders _FormatFolders = null; - /// - /// Related Field - /// - [TypeConverter(typeof(FormatFoldersConverter))] - public FormatFolders FormatFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolders", true); - if (_FormatFolderCount > 0 && _FormatFolders == null) - _FormatFolders = FormatFolders.GetByFormatID(FormatID); - else if (_FormatFolders == null) - _FormatFolders = FormatFolders.New(); - return _FormatFolders; - } - } - private int _ChildFormatCount = 0; - /// - /// Count of ChildFormats for this Format - /// - public int ChildFormatCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormatCount", true); - return _ChildFormatCount; - } - } - private ChildFormats _ChildFormats = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ChildFormatsConverter))] - public ChildFormats ChildFormats - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormats", true); - if (_ChildFormatCount > 0 && _ChildFormats == null) - _ChildFormats = ChildFormats.GetByParentID(FormatID); - else if (_ChildFormats == null) - _ChildFormats = ChildFormats.New(); - return _ChildFormats; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_FormatContents == null ? false : _FormatContents.IsDirty) || (_FormatDocVersions == null ? false : _FormatDocVersions.IsDirty) || (_FormatFolders == null ? false : _FormatFolders.IsDirty) || (_ChildFormats == null ? false : _ChildFormats.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_FormatContents == null ? true : _FormatContents.IsValid) && (_FormatDocVersions == null ? true : _FormatDocVersions.IsValid) && (_FormatFolders == null ? true : _FormatFolders.IsValid) && (_ChildFormats == null ? true : _ChildFormats.IsValid); } - } - // TODO: Replace base Format.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Format - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Format.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Format - protected override object GetIdValue() - { - return _FormatID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_FormatFolders != null && (hasBrokenRules = _FormatFolders.HasBrokenRules) != null) return hasBrokenRules; - if (_FormatContents != null && (hasBrokenRules = _FormatContents.HasBrokenRules) != null) return hasBrokenRules; - if (_FormatDocVersions != null && (hasBrokenRules = _FormatDocVersions.HasBrokenRules) != null) return hasBrokenRules; - if (_ChildFormats != null && (hasBrokenRules = _ChildFormats.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 20)); - 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)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("GenMac", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _FormatExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _FormatExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Description, ""); - //AuthorizationRules.AllowRead(Data, ""); - //AuthorizationRules.AllowRead(GenMac, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Description, ""); - //AuthorizationRules.AllowWrite(Data, ""); - //AuthorizationRules.AllowWrite(GenMac, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _FormatExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _FormatExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _FormatUnique = 0; - protected static int FormatUnique - { get { return ++_FormatUnique; } } - private int _MyFormatUnique = FormatUnique; - public int MyFormatUnique - { get { return _MyFormatUnique; } } - protected Format() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) - { - List listFormat = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items - while (listFormat.Contains(this)) listFormat.Remove(this); // Remove the item from the list - if (listFormat.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByParentID_Name.Keys) - if (_CacheByParentID_Name[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listFormat = _CacheByParentID_Name[myKey]; // Get the list of items - listFormat.Remove(this); // Remove the item from the list - if (listFormat.Count == 0) //If there are no items left in the list - _CacheByParentID_Name.Remove(myKey); // remove the list - } - } - public static Format New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Format"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.New", ex); - } - } - public static Format New(Format myParent, string name, string data) - { - Format tmp = Format.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.Data = data; - return tmp; - } - public static Format New(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) - { - Format tmp = Format.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.Description = description; - tmp.Data = data; - tmp.GenMac = genMac; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) - { - Format tmp = Format.New(myParent, name, description, data, genMac, dts, userID); - if (tmp.IsSavable) - { - Format tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Format New(Format myParent, string name, string description, string data, string genMac) - { - Format tmp = Format.New(); - tmp.MyParent = myParent; - tmp.Name = name; - tmp.Description = description; - tmp.Data = data; - tmp.GenMac = genMac; - return tmp; - } - public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac) - { - Format tmp = Format.New(myParent, name, description, data, genMac); - if (tmp.IsSavable) - { - Format tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(formatID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Format - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.Get", ex); - } - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Format - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.GetByParentID_Name", ex); - } - } - public static Format Get(SafeDataReader dr, Format parent) - { - if (dr.Read()) return new Format(dr, parent); - return null; - } - internal Format(SafeDataReader dr) - { - ReadData(dr); - } - private Format(SafeDataReader dr, Format parent) - { - ReadData(dr); - MarkAsChild(); - } - internal Format(SafeDataReader dr, int parentID) - { - ReadData(dr); - MarkAsChild(); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.Delete", ex); - } - } - 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(); - Format format = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(format);//Refresh the item in AllList - ProcessRefreshList(); - return format; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _FormatID; - public int FormatID - { get { return _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; } } - public ParentID_NameCriteria(int parentID, string name) - { - _ParentID = parentID; - _Name = name; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _FormatID = NextFormatID; - // Database Defaults - _ParentID = _FormatExtension.DefaultParentID; - _DTS = _FormatExtension.DefaultDTS; - _UserID = _FormatExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.ReadData", GetHashCode()); - try - { - _FormatID = dr.GetInt32("FormatID"); - _ParentID = dr.GetInt32("ParentID"); - _Name = dr.GetString("Name"); - _Description = dr.GetString("Description"); - _Data = dr.GetString("Data"); - _GenMac = dr.GetString("GenMac"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _FormatContentCount = dr.GetInt32("ContentCount"); - _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); - _FormatFolderCount = dr.GetInt32("FolderCount"); - _ChildFormatCount = dr.GetInt32("ChildCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFormat"; - cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _FormatContents = FormatContents.Get(dr); - // load child objects - dr.NextResult(); - _FormatDocVersions = FormatDocVersions.Get(dr); - // load child objects - dr.NextResult(); - _FormatFolders = FormatFolders.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(ParentID_NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFormatByParentID_Name"; - cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); - cm.Parameters.AddWithValue("@Name", criteria.Name); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Format.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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("@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); - // TODO: 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); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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 genMac, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addFormat"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ParentID", myParent.FormatID); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Description", description); - cm.Parameters.AddWithValue("@Data", data); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - formatID = (int)cm.Parameters["@newFormatID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Add", ex); - throw new DbCslaException("Format.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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("@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); - // TODO: 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _GenMac, _DTS, _UserID); - else - _LastChanged = Format.Update(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _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); - } - internal void DeleteSelf(Format format) - { - // 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"]; - Format.Remove(cn, _FormatID); - MarkNew(); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int formatID, Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateFormat"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FormatID", formatID); - cm.Parameters.AddWithValue("@ParentID", myParent.FormatID); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Description", description); - cm.Parameters.AddWithValue("@Data", data); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteFormat"; - cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteFormat"; - // Input PK Fields - cm.Parameters.AddWithValue("@FormatID", formatID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Remove", ex); - throw new DbCslaException("Format.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int formatID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(formatID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Format.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _FormatID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int formatID) - { - _FormatID = formatID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsFormat"; - cm.Parameters.AddWithValue("@FormatID", _FormatID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Execute", ex); - throw new DbCslaException("Format.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - FormatExtension _FormatExtension = new FormatExtension(); - [Serializable()] - partial class FormatExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Format) - { - // Return the ToString value - return ((Format)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Format Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatConverter))] + public partial class Format : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshFormats = new List(); + private List _RefreshFormatContents = new List(); + private List _RefreshFormatDocVersions = new List(); + private List _RefreshFormatFolders = new List(); + private void AddToRefreshList(List refreshFormats, List refreshFormatContents, List refreshFormatDocVersions, List refreshFormatFolders) + { + if (IsDirty) + refreshFormats.Add(this); + if (_FormatContents != null && _FormatContents.IsDirty) + { + foreach (FormatContent tmp in _FormatContents) + { + if (tmp.IsDirty) refreshFormatContents.Add(tmp); + } + } + if (_FormatDocVersions != null && _FormatDocVersions.IsDirty) + { + foreach (FormatDocVersion tmp in _FormatDocVersions) + { + if (tmp.IsDirty) refreshFormatDocVersions.Add(tmp); + } + } + if (_FormatFolders != null && _FormatFolders.IsDirty) + { + foreach (FormatFolder tmp in _FormatFolders) + { + if (tmp.IsDirty) refreshFormatFolders.Add(tmp); + } + } + if (_ChildFormats != null && _ChildFormats.IsDirty) + { + foreach (Format tmp in _ChildFormats) + { + tmp.AddToRefreshList(refreshFormats, refreshFormatContents, refreshFormatDocVersions, refreshFormatFolders); + } + } + } + private void BuildRefreshList() + { + _RefreshFormats = new List(); + _RefreshFormatContents = new List(); + _RefreshFormatDocVersions = new List(); + _RefreshFormatFolders = new List(); + AddToRefreshList(_RefreshFormats, _RefreshFormatContents, _RefreshFormatDocVersions, _RefreshFormatFolders); + } + private void ProcessRefreshList() + { + foreach (Format tmp in _RefreshFormats) + { + FormatInfo.Refresh(tmp); + } + foreach (FormatContent tmp in _RefreshFormatContents) + { + ContentInfo.Refresh(tmp); + } + foreach (FormatDocVersion tmp in _RefreshFormatDocVersions) + { + DocVersionInfo.Refresh(tmp); + } + foreach (FormatFolder tmp in _RefreshFormatFolders) + { + FolderInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Format format) + { + if (!_CacheList.Contains(format)) _CacheList.Add(format); // In AddToCache + } + protected static void RemoveFromCache(Format format) + { + while (_CacheList.Contains(format)) _CacheList.Remove(format); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByParentID_Name = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Format tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.FormatID.ToString())) + { + _CacheByPrimaryKey[tmp.FormatID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List(); // Add new list for ParentID_Name + } + _CacheByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index + remove.Add(tmp); + } + foreach (Format tmp in remove) + RemoveFromCache(tmp); + } + protected static Format GetCachedByPrimaryKey(int formatID) + { + ConvertListToDictionary(); + string key = formatID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Format GetCachedByParentID_Name(int parentID, string name) + { + ConvertListToDictionary(); + string key = parentID.ToString() + "_" + name.ToString(); + if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextFormatID = -1; + public static int NextFormatID + { + get { return _nextFormatID--; } + } + private int _FormatID; + [System.ComponentModel.DataObjectField(true, true)] + public int FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FormatID; + return _ParentID; + } + } + private Format _MyParent; + public Format MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FormatID) _MyParent = Format.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Description; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Description != value) + { + _Description = value; + PropertyHasChanged(); + } + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Data != value) + { + _Data = value; + PropertyHasChanged(); + } + } + } + private string _GenMac = string.Empty; + public string GenMac + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GenMac; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_GenMac != value) + { + _GenMac = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _FormatContentCount = 0; + /// + /// Count of FormatContents for this Format + /// + public int FormatContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatContentCount; + } + } + private FormatContents _FormatContents = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FormatContentsConverter))] + public FormatContents FormatContents + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatContentCount > 0 && _FormatContents == null) + _FormatContents = FormatContents.GetByFormatID(FormatID); + else if (_FormatContents == null) + _FormatContents = FormatContents.New(); + return _FormatContents; + } + } + private int _FormatDocVersionCount = 0; + /// + /// Count of FormatDocVersions for this Format + /// + public int FormatDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatDocVersionCount; + } + } + private FormatDocVersions _FormatDocVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FormatDocVersionsConverter))] + public FormatDocVersions FormatDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatDocVersionCount > 0 && _FormatDocVersions == null) + _FormatDocVersions = FormatDocVersions.GetByFormatID(FormatID); + else if (_FormatDocVersions == null) + _FormatDocVersions = FormatDocVersions.New(); + return _FormatDocVersions; + } + } + private int _FormatFolderCount = 0; + /// + /// Count of FormatFolders for this Format + /// + public int FormatFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatFolderCount; + } + } + private FormatFolders _FormatFolders = null; + /// + /// Related Field + /// + [TypeConverter(typeof(FormatFoldersConverter))] + public FormatFolders FormatFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatFolderCount > 0 && _FormatFolders == null) + _FormatFolders = FormatFolders.GetByFormatID(FormatID); + else if (_FormatFolders == null) + _FormatFolders = FormatFolders.New(); + return _FormatFolders; + } + } + private int _ChildFormatCount = 0; + /// + /// Count of ChildFormats for this Format + /// + public int ChildFormatCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ChildFormatCount; + } + } + private ChildFormats _ChildFormats = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ChildFormatsConverter))] + public ChildFormats ChildFormats + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFormatCount > 0 && _ChildFormats == null) + _ChildFormats = ChildFormats.GetByParentID(FormatID); + else if (_ChildFormats == null) + _ChildFormats = ChildFormats.New(); + return _ChildFormats; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_FormatContents == null ? false : _FormatContents.IsDirty) || (_FormatDocVersions == null ? false : _FormatDocVersions.IsDirty) || (_FormatFolders == null ? false : _FormatFolders.IsDirty) || (_ChildFormats == null ? false : _ChildFormats.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_FormatContents == null ? true : _FormatContents.IsValid) && (_FormatDocVersions == null ? true : _FormatDocVersions.IsValid) && (_FormatFolders == null ? true : _FormatFolders.IsValid) && (_ChildFormats == null ? true : _ChildFormats.IsValid); } + } + // TODO: Replace base Format.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Format + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Format.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Format + protected override object GetIdValue() + { + return _FormatID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_FormatFolders != null && (hasBrokenRules = _FormatFolders.HasBrokenRules) != null) return hasBrokenRules; + if (_FormatContents != null && (hasBrokenRules = _FormatContents.HasBrokenRules) != null) return hasBrokenRules; + if (_FormatDocVersions != null && (hasBrokenRules = _FormatDocVersions.HasBrokenRules) != null) return hasBrokenRules; + if (_ChildFormats != null && (hasBrokenRules = _ChildFormats.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 20)); + 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)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("GenMac", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _FormatExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _FormatExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Description, ""); + //AuthorizationRules.AllowRead(Data, ""); + //AuthorizationRules.AllowRead(GenMac, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Description, ""); + //AuthorizationRules.AllowWrite(Data, ""); + //AuthorizationRules.AllowWrite(GenMac, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _FormatExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _FormatExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _FormatUnique = 0; + protected static int FormatUnique + { get { return ++_FormatUnique; } } + private int _MyFormatUnique = FormatUnique; + public int MyFormatUnique + { get { return _MyFormatUnique; } } + protected Format() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) + { + List listFormat = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items + while (listFormat.Contains(this)) listFormat.Remove(this); // Remove the item from the list + if (listFormat.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByParentID_Name.Keys) + if (_CacheByParentID_Name[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listFormat = _CacheByParentID_Name[myKey]; // Get the list of items + listFormat.Remove(this); // Remove the item from the list + if (listFormat.Count == 0) //If there are no items left in the list + _CacheByParentID_Name.Remove(myKey); // remove the list + } + } + public static Format New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Format"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.New", ex); + } + } + public static Format New(Format myParent, string name, string data) + { + Format tmp = Format.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.Data = data; + return tmp; + } + public static Format New(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) + { + Format tmp = Format.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.Description = description; + tmp.Data = data; + tmp.GenMac = genMac; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) + { + Format tmp = Format.New(myParent, name, description, data, genMac, dts, userID); + if (tmp.IsSavable) + { + Format tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Format New(Format myParent, string name, string description, string data, string genMac) + { + Format tmp = Format.New(); + tmp.MyParent = myParent; + tmp.Name = name; + tmp.Description = description; + tmp.Data = data; + tmp.GenMac = genMac; + return tmp; + } + public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac) + { + Format tmp = Format.New(myParent, name, description, data, genMac); + if (tmp.IsSavable) + { + Format tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(formatID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Format + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.Get", ex); + } + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new ParentID_NameCriteria(parentID, name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Format + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.GetByParentID_Name", ex); + } + } + public static Format Get(SafeDataReader dr, Format parent) + { + if (dr.Read()) return new Format(dr, parent); + return null; + } + internal Format(SafeDataReader dr) + { + ReadData(dr); + } + private Format(SafeDataReader dr, Format parent) + { + ReadData(dr); + MarkAsChild(); + } + internal Format(SafeDataReader dr, int parentID) + { + ReadData(dr); + MarkAsChild(); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.Delete", ex); + } + } + 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(); + Format format = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(format);//Refresh the item in AllList + ProcessRefreshList(); + return format; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _FormatID; + public int FormatID + { get { return _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; } } + public ParentID_NameCriteria(int parentID, string name) + { + _ParentID = parentID; + _Name = name; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _FormatID = NextFormatID; + // Database Defaults + _ParentID = _FormatExtension.DefaultParentID; + _DTS = _FormatExtension.DefaultDTS; + _UserID = _FormatExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.ReadData", GetHashCode()); + try + { + _FormatID = dr.GetInt32("FormatID"); + _ParentID = dr.GetInt32("ParentID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _Data = dr.GetString("Data"); + _GenMac = dr.GetString("GenMac"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _FormatContentCount = dr.GetInt32("ContentCount"); + _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); + _FormatFolderCount = dr.GetInt32("FolderCount"); + _ChildFormatCount = dr.GetInt32("ChildCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormat"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _FormatContents = FormatContents.Get(dr); + // load child objects + dr.NextResult(); + _FormatDocVersions = FormatDocVersions.Get(dr); + // load child objects + dr.NextResult(); + _FormatFolders = FormatFolders.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(ParentID_NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormatByParentID_Name"; + cm.Parameters.AddWithValue("@ParentID", criteria.ParentID); + cm.Parameters.AddWithValue("@Name", criteria.Name); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Format.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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("@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); + // TODO: 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); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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 genMac, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addFormat"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ParentID", myParent.FormatID); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Description", description); + cm.Parameters.AddWithValue("@Data", data); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + formatID = (int)cm.Parameters["@newFormatID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Add", ex); + throw new DbCslaException("Format.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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("@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); + // TODO: 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _GenMac, _DTS, _UserID); + else + _LastChanged = Format.Update(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _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); + } + internal void DeleteSelf(Format format) + { + // 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"]; + Format.Remove(cn, _FormatID); + MarkNew(); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int formatID, Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateFormat"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FormatID", formatID); + cm.Parameters.AddWithValue("@ParentID", myParent.FormatID); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Description", description); + cm.Parameters.AddWithValue("@Data", data); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteFormat"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteFormat"; + // Input PK Fields + cm.Parameters.AddWithValue("@FormatID", formatID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.Remove", ex); + throw new DbCslaException("Format.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int formatID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(formatID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Format.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _FormatID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int formatID) + { + _FormatID = formatID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsFormat"; + cm.Parameters.AddWithValue("@FormatID", _FormatID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Format.DataPortal_Execute", ex); + throw new DbCslaException("Format.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + FormatExtension _FormatExtension = new FormatExtension(); + [Serializable()] + partial class FormatExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Format) + { + // Return the ToString value + return ((Format)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatContent.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatContent.cs index 8f5fb7f4..3a8441a6 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatContent.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatContent.cs @@ -19,428 +19,414 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FormatContent Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatContentConverter))] - public partial class FormatContent : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private string _Number = string.Empty; - public string Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Number", true); - return _Number; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Number", true); - if (value == null) value = string.Empty; - if (_Number != value) - { - _Number = value; - PropertyHasChanged(); - } - } - } - private string _Text = string.Empty; - public string Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Text", true); - return _Text; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Text", true); - if (value == null) value = string.Empty; - if (_Text != value) - { - _Text = value; - PropertyHasChanged(); - } - } - } - private int? _Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Type", true); - return _Type; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Type", true); - if (_Type != value) - { - _Type = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check FormatContent.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatContent - protected override object GetIdValue() - { - return _ContentID; - } - // TODO: Replace base FormatContent.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatContent - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 30)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(Number, ""); - //AuthorizationRules.AllowWrite(Number, ""); - //AuthorizationRules.AllowRead(Text, ""); - //AuthorizationRules.AllowWrite(Text, ""); - //AuthorizationRules.AllowRead(Type, ""); - //AuthorizationRules.AllowWrite(Type, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static FormatContent New() - { - return new FormatContent(); - } - internal static FormatContent Get(SafeDataReader dr) - { - return new FormatContent(dr); - } - public FormatContent() - { - MarkAsChild(); - _ContentID = Content.NextContentID; - _DTS = _FormatContentExtension.DefaultDTS; - _UserID = _FormatContentExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - internal FormatContent(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatContent.FetchDR", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _Number = dr.GetString("Number"); - _Text = dr.GetString("Text"); - _Type = (int?)dr.GetValue("Type"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatContent.FetchDR", ex); - throw new DbCslaException("FormatContent.Fetch", ex); - } - MarkOld(); - } - 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 = 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, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FormatContentExtension _FormatContentExtension = new FormatContentExtension(); - [Serializable()] - partial class FormatContentExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatContentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatContent) - { - // Return the ToString value - return ((FormatContent)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FormatContent Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatContentConverter))] + public partial class FormatContent : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private string _Number = string.Empty; + public string Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Number; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Number != value) + { + _Number = value; + PropertyHasChanged(); + } + } + } + private string _Text = string.Empty; + public string Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Text; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Text != value) + { + _Text = value; + PropertyHasChanged(); + } + } + } + private int? _Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Type; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Type != value) + { + _Type = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check FormatContent.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatContent + protected override object GetIdValue() + { + return _ContentID; + } + // TODO: Replace base FormatContent.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatContent + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 30)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(Number, ""); + //AuthorizationRules.AllowWrite(Number, ""); + //AuthorizationRules.AllowRead(Text, ""); + //AuthorizationRules.AllowWrite(Text, ""); + //AuthorizationRules.AllowRead(Type, ""); + //AuthorizationRules.AllowWrite(Type, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static FormatContent New() + { + return new FormatContent(); + } + internal static FormatContent Get(SafeDataReader dr) + { + return new FormatContent(dr); + } + public FormatContent() + { + MarkAsChild(); + _ContentID = Content.NextContentID; + _DTS = _FormatContentExtension.DefaultDTS; + _UserID = _FormatContentExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + internal FormatContent(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatContent.FetchDR", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _Number = dr.GetString("Number"); + _Text = dr.GetString("Text"); + _Type = (int?)dr.GetValue("Type"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatContent.FetchDR", ex); + throw new DbCslaException("FormatContent.Fetch", ex); + } + MarkOld(); + } + 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 = 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, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FormatContentExtension _FormatContentExtension = new FormatContentExtension(); + [Serializable()] + partial class FormatContentExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatContentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatContent) + { + // Return the ToString value + return ((FormatContent)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatDocVersion.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatDocVersion.cs index 97127734..dcb0150a 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatDocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatDocVersion.cs @@ -19,647 +19,617 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FormatDocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatDocVersionConverter))] - public partial class FormatDocVersion : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _ItemID; - public int? ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyItem = value; - _ItemID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - // TODO: Check FormatDocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatDocVersion - protected override object GetIdValue() - { - return _VersionID; - } - // TODO: Replace base FormatDocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatDocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyFolderRequired(FormatDocVersion target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static FormatDocVersion New(Folder myFolder, string name) - { - return new FormatDocVersion(myFolder, name); - } - internal static FormatDocVersion Get(SafeDataReader dr) - { - return new FormatDocVersion(dr); - } - public FormatDocVersion() - { - MarkAsChild(); - _VersionID = DocVersion.NextVersionID; - _VersionType = _FormatDocVersionExtension.DefaultVersionType; - _DTS = _FormatDocVersionExtension.DefaultDTS; - _UserID = _FormatDocVersionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private FormatDocVersion(Folder myFolder, string name) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _VersionType = _FormatDocVersionExtension.DefaultVersionType; - _DTS = _FormatDocVersionExtension.DefaultDTS; - _UserID = _FormatDocVersionExtension.DefaultUserID; - _MyFolder = myFolder; - _Name = name; - ValidationRules.CheckRules(); - } - internal FormatDocVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatDocVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ItemID = (int?)dr.GetValue("ItemID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatDocVersion.FetchDR", ex); - throw new DbCslaException("FormatDocVersion.Fetch", ex); - } - MarkOld(); - } - 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); - 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, _MyFolder, _VersionType, _Name, _Title, _MyItem, myFormat, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - 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"]; - DocVersion.Remove(cn, _VersionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension(); - [Serializable()] - partial class FormatDocVersionExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatDocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatDocVersion) - { - // Return the ToString value - return ((FormatDocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FormatDocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatDocVersionConverter))] + public partial class FormatDocVersion : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _ItemID; + public int? ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != null) _MyItem = Item.Get((int)_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyItem = value; + _ItemID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + // TODO: Check FormatDocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatDocVersion + protected override object GetIdValue() + { + return _VersionID; + } + // TODO: Replace base FormatDocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatDocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyFolderRequired(FormatDocVersion target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static FormatDocVersion New(Folder myFolder, string name) + { + return new FormatDocVersion(myFolder, name); + } + internal static FormatDocVersion Get(SafeDataReader dr) + { + return new FormatDocVersion(dr); + } + public FormatDocVersion() + { + MarkAsChild(); + _VersionID = DocVersion.NextVersionID; + _VersionType = _FormatDocVersionExtension.DefaultVersionType; + _DTS = _FormatDocVersionExtension.DefaultDTS; + _UserID = _FormatDocVersionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private FormatDocVersion(Folder myFolder, string name) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _VersionType = _FormatDocVersionExtension.DefaultVersionType; + _DTS = _FormatDocVersionExtension.DefaultDTS; + _UserID = _FormatDocVersionExtension.DefaultUserID; + _MyFolder = myFolder; + _Name = name; + ValidationRules.CheckRules(); + } + internal FormatDocVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatDocVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ItemID = (int?)dr.GetValue("ItemID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatDocVersion.FetchDR", ex); + throw new DbCslaException("FormatDocVersion.Fetch", ex); + } + MarkOld(); + } + 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); + 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, _MyFolder, _VersionType, _Name, _Title, _MyItem, myFormat, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + 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"]; + DocVersion.Remove(cn, _VersionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FormatDocVersionExtension _FormatDocVersionExtension = new FormatDocVersionExtension(); + [Serializable()] + partial class FormatDocVersionExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatDocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatDocVersion) + { + // Return the ToString value + return ((FormatDocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatFolder.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatFolder.cs index 601bcd93..2fbf77be 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatFolder.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatFolder.cs @@ -19,659 +19,630 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// FormatFolder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatFolderConverter))] - public partial class FormatFolder : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _FolderID; - [System.ComponentModel.DataObjectField(true, true)] - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - [System.ComponentModel.DataObjectField(true, true)] - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FolderID; - return _ParentID; - } - } - private Folder _MyParent; - public Folder MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); - return _MyParent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyParent", true); - if (_MyParent != value) - { - _MyParent = value; - PropertyHasChanged(); - } - } - } - private int _DBID; - public int DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBID", true); - if (_MyConnection != null) _DBID = _MyConnection.DBID; - return _DBID; - } - } - private Connection _MyConnection; - public Connection MyConnection - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyConnection", true); - if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); - return _MyConnection; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyConnection", true); - if (_MyConnection != value) - { - _MyConnection = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private string _ShortName = string.Empty; - public string ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ShortName", true); - return _ShortName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ShortName", true); - if (value == null) value = string.Empty; - if (_ShortName != value) - { - _ShortName = value; - PropertyHasChanged(); - } - } - } - private double? _ManualOrder; - public double? ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ManualOrder", true); - return _ManualOrder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ManualOrder", true); - if (_ManualOrder != value) - { - _ManualOrder = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Connection_Name = string.Empty; - public string Connection_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_Name", true); - return _Connection_Name; - } - } - private string _Connection_Title = string.Empty; - public string Connection_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_Title", true); - return _Connection_Title; - } - } - private string _Connection_ConnectionString = string.Empty; - public string Connection_ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_ConnectionString", true); - return _Connection_ConnectionString; - } - } - private int _Connection_ServerType; - /// - /// 0 SQL Server - /// - public int Connection_ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_ServerType", true); - return _Connection_ServerType; - } - } - private string _Connection_Config = string.Empty; - public string Connection_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_Config", true); - return _Connection_Config; - } - } - private DateTime _Connection_DTS = new DateTime(); - public DateTime Connection_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_DTS", true); - return _Connection_DTS; - } - } - private string _Connection_UsrID = string.Empty; - public string Connection_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Connection_UsrID", true); - return _Connection_UsrID; - } - } - // TODO: Check FormatFolder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatFolder - protected override object GetIdValue() - { - return _FolderID; - } - // TODO: Replace base FormatFolder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatFolder - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyConnection == null ? false : _MyConnection.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyConnection == null ? true : _MyConnection.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ShortName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool MyFolderRequired(FormatFolder target, Csla.Validation.RuleArgs e) - { - if (target._ParentID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyConnectionRequired(FormatFolder target, Csla.Validation.RuleArgs e) - { - if (target._DBID == 0 && target._MyConnection == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowRead(ParentID, ""); - //AuthorizationRules.AllowWrite(ParentID, ""); - //AuthorizationRules.AllowRead(DBID, ""); - //AuthorizationRules.AllowWrite(DBID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(ShortName, ""); - //AuthorizationRules.AllowWrite(ShortName, ""); - //AuthorizationRules.AllowRead(ManualOrder, ""); - //AuthorizationRules.AllowWrite(ManualOrder, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - 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); - } - public FormatFolder() - { - MarkAsChild(); - _FolderID = Folder.NextFolderID; - _ParentID = _FormatFolderExtension.DefaultParentID; - _DBID = _FormatFolderExtension.DefaultDBID; - _DTS = _FormatFolderExtension.DefaultDTS; - _UsrID = _FormatFolderExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private FormatFolder(Folder myParent, string name, string shortName) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _ParentID = _FormatFolderExtension.DefaultParentID; - _DBID = _FormatFolderExtension.DefaultDBID; - _DTS = _FormatFolderExtension.DefaultDTS; - _UsrID = _FormatFolderExtension.DefaultUsrID; - _MyParent = myParent; - _Name = name; - _ShortName = shortName; - ValidationRules.CheckRules(); - } - internal FormatFolder(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatFolder.FetchDR", GetHashCode()); - try - { - _FolderID = dr.GetInt32("FolderID"); - _ParentID = dr.GetInt32("ParentID"); - _DBID = dr.GetInt32("DBID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _ShortName = dr.GetString("ShortName"); - _ManualOrder = (double?)dr.GetValue("ManualOrder"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Connection_Name = dr.GetString("Connection_Name"); - _Connection_Title = dr.GetString("Connection_Title"); - _Connection_ConnectionString = dr.GetString("Connection_ConnectionString"); - _Connection_ServerType = dr.GetInt32("Connection_ServerType"); - _Connection_Config = dr.GetString("Connection_Config"); - _Connection_DTS = dr.GetDateTime("Connection_DTS"); - _Connection_UsrID = dr.GetString("Connection_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatFolder.FetchDR", ex); - throw new DbCslaException("FormatFolder.Fetch", ex); - } - MarkOld(); - } - 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); - 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, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - 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"]; - Folder.Remove(cn, _FolderID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension(); - [Serializable()] - partial class FormatFolderExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class FormatFolderConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatFolder) - { - // Return the ToString value - return ((FormatFolder)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// FormatFolder Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatFolderConverter))] + public partial class FormatFolder : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _FolderID; + [System.ComponentModel.DataObjectField(true, true)] + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + [System.ComponentModel.DataObjectField(true, true)] + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FolderID; + return _ParentID; + } + } + private Folder _MyParent; + public Folder MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FolderID) _MyParent = Folder.Get(_ParentID); + return _MyParent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyParent != value) + { + _MyParent = value; + PropertyHasChanged(); + } + } + } + private int _DBID; + public int DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection != null) _DBID = _MyConnection.DBID; + return _DBID; + } + } + private Connection _MyConnection; + public Connection MyConnection + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyConnection == null && _DBID != 0) _MyConnection = Connection.Get(_DBID); + return _MyConnection; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyConnection != value) + { + _MyConnection = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private string _ShortName = string.Empty; + public string ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ShortName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ShortName != value) + { + _ShortName = value; + PropertyHasChanged(); + } + } + } + private double? _ManualOrder; + public double? ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ManualOrder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ManualOrder != value) + { + _ManualOrder = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Connection_Name = string.Empty; + public string Connection_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_Name; + } + } + private string _Connection_Title = string.Empty; + public string Connection_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_Title; + } + } + private string _Connection_ConnectionString = string.Empty; + public string Connection_ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_ConnectionString; + } + } + private int _Connection_ServerType; + /// + /// 0 SQL Server + /// + public int Connection_ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_ServerType; + } + } + private string _Connection_Config = string.Empty; + public string Connection_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_Config; + } + } + private DateTime _Connection_DTS = new DateTime(); + public DateTime Connection_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_DTS; + } + } + private string _Connection_UsrID = string.Empty; + public string Connection_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Connection_UsrID; + } + } + // TODO: Check FormatFolder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatFolder + protected override object GetIdValue() + { + return _FolderID; + } + // TODO: Replace base FormatFolder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatFolder + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty) || (_MyConnection == null ? false : _MyConnection.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid) && (_MyConnection == null ? true : _MyConnection.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyConnection != null && (hasBrokenRules = _MyConnection.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule(MyConnectionRequired, "MyConnection"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ShortName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ShortName", 20)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool MyFolderRequired(FormatFolder target, Csla.Validation.RuleArgs e) + { + if (target._ParentID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyConnectionRequired(FormatFolder target, Csla.Validation.RuleArgs e) + { + if (target._DBID == 0 && target._MyConnection == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowRead(ParentID, ""); + //AuthorizationRules.AllowWrite(ParentID, ""); + //AuthorizationRules.AllowRead(DBID, ""); + //AuthorizationRules.AllowWrite(DBID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(ShortName, ""); + //AuthorizationRules.AllowWrite(ShortName, ""); + //AuthorizationRules.AllowRead(ManualOrder, ""); + //AuthorizationRules.AllowWrite(ManualOrder, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + 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); + } + public FormatFolder() + { + MarkAsChild(); + _FolderID = Folder.NextFolderID; + _ParentID = _FormatFolderExtension.DefaultParentID; + _DBID = _FormatFolderExtension.DefaultDBID; + _DTS = _FormatFolderExtension.DefaultDTS; + _UsrID = _FormatFolderExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private FormatFolder(Folder myParent, string name, string shortName) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _ParentID = _FormatFolderExtension.DefaultParentID; + _DBID = _FormatFolderExtension.DefaultDBID; + _DTS = _FormatFolderExtension.DefaultDTS; + _UsrID = _FormatFolderExtension.DefaultUsrID; + _MyParent = myParent; + _Name = name; + _ShortName = shortName; + ValidationRules.CheckRules(); + } + internal FormatFolder(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatFolder.FetchDR", GetHashCode()); + try + { + _FolderID = dr.GetInt32("FolderID"); + _ParentID = dr.GetInt32("ParentID"); + _DBID = dr.GetInt32("DBID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _ShortName = dr.GetString("ShortName"); + _ManualOrder = (double?)dr.GetValue("ManualOrder"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Connection_Name = dr.GetString("Connection_Name"); + _Connection_Title = dr.GetString("Connection_Title"); + _Connection_ConnectionString = dr.GetString("Connection_ConnectionString"); + _Connection_ServerType = dr.GetInt32("Connection_ServerType"); + _Connection_Config = dr.GetString("Connection_Config"); + _Connection_DTS = dr.GetDateTime("Connection_DTS"); + _Connection_UsrID = dr.GetString("Connection_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatFolder.FetchDR", ex); + throw new DbCslaException("FormatFolder.Fetch", ex); + } + MarkOld(); + } + 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); + 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, Folder.Get(_ParentID), _MyConnection, _Name, _Title, _ShortName, myFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + 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"]; + Folder.Remove(cn, _FolderID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + FormatFolderExtension _FormatFolderExtension = new FormatFolderExtension(); + [Serializable()] + partial class FormatFolderExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class FormatFolderConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatFolder) + { + // Return the ToString value + return ((FormatFolder)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatInfo.cs index 0578157d..d620ce93 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/FormatInfo.cs @@ -19,520 +19,503 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void FormatInfoEvent(object sender); - /// - /// FormatInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(FormatInfoConverter))] - public partial class FormatInfo : ReadOnlyBase, IDisposable - { - public event FormatInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(FormatInfo formatInfo) - { - if (!_CacheList.Contains(formatInfo)) _CacheList.Add(formatInfo); // In AddToCache - } - protected static void RemoveFromCache(FormatInfo formatInfo) - { - while (_CacheList.Contains(formatInfo)) _CacheList.Remove(formatInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (FormatInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.FormatID.ToString())) - { - _CacheByPrimaryKey[tmp.FormatID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (FormatInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(FormatInfoList lst) - { - foreach (FormatInfo item in lst) AddToCache(item); - } - protected static FormatInfo GetCachedByPrimaryKey(int formatID) - { - ConvertListToDictionary(); - string key = formatID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - return _FormatID; - } - } - private int _ParentID; - public int ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ParentID", true); - if (_MyParent != null) _ParentID = _MyParent.FormatID; - return _ParentID; - } - } - private FormatInfo _MyParent; - public FormatInfo MyParent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyParent", true); - if (_MyParent == null && _ParentID != _FormatID) _MyParent = FormatInfo.Get(_ParentID); - return _MyParent; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Description = string.Empty; - public string Description - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Description", true); - return _Description; - } - } - private string _Data = string.Empty; - public string Data - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Data", true); - return _Data; - } - } - private string _GenMac = string.Empty; - public string GenMac - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GenMac", true); - return _GenMac; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _FormatContentCount = 0; - /// - /// Count of FormatContents for this Format - /// - public int FormatContentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContentCount", true); - return _FormatContentCount; - } - } - private ContentInfoList _FormatContents = null; - [TypeConverter(typeof(ContentInfoListConverter))] - public ContentInfoList FormatContents - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatContents", true); - if (_FormatContentCount < 0 || (_FormatContentCount > 0 && _FormatContents == null)) - _FormatContents = ContentInfoList.GetByFormatID(_FormatID); - if (_FormatContentCount < 0) - _FormatContentCount = _FormatContents.Count; - return _FormatContents; - } - } - public void RefreshFormatContents() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) - tmp._FormatContentCount = -1; // This will cause the data to be requeried - } - private int _FormatDocVersionCount = 0; - /// - /// Count of FormatDocVersions for this Format - /// - public int FormatDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersionCount", true); - return _FormatDocVersionCount; - } - } - private DocVersionInfoList _FormatDocVersions = null; - [TypeConverter(typeof(DocVersionInfoListConverter))] - public DocVersionInfoList FormatDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatDocVersions", true); - if (_FormatDocVersionCount < 0 || (_FormatDocVersionCount > 0 && _FormatDocVersions == null)) - _FormatDocVersions = DocVersionInfoList.GetByFormatID(_FormatID); - if (_FormatDocVersionCount < 0) - _FormatDocVersionCount = _FormatDocVersions.Count; - return _FormatDocVersions; - } - } - public void RefreshFormatDocVersions() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) - tmp._FormatDocVersionCount = -1; // This will cause the data to be requeried - } - private int _FormatFolderCount = 0; - /// - /// Count of FormatFolders for this Format - /// - public int FormatFolderCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolderCount", true); - return _FormatFolderCount; - } - } - private FolderInfoList _FormatFolders = null; - [TypeConverter(typeof(FolderInfoListConverter))] - public FolderInfoList FormatFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatFolders", true); - if (_FormatFolderCount < 0 || (_FormatFolderCount > 0 && _FormatFolders == null)) - _FormatFolders = FolderInfoList.GetByFormatID(_FormatID); - if (_FormatFolderCount < 0) - _FormatFolderCount = _FormatFolders.Count; - return _FormatFolders; - } - } - public void RefreshFormatFolders() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) - tmp._FormatFolderCount = -1; // This will cause the data to be requeried - } - private int _ChildFormatCount = 0; - /// - /// Count of ChildFormats for this Format - /// - public int ChildFormatCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormatCount", true); - return _ChildFormatCount; - } - } - private FormatInfoList _ChildFormats = null; - [TypeConverter(typeof(FormatInfoListConverter))] - public FormatInfoList ChildFormats - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ChildFormats", true); - if (_ChildFormatCount < 0 || (_ChildFormatCount > 0 && _ChildFormats == null)) - _ChildFormats = FormatInfoList.GetChildren(_FormatID); - if (_ChildFormatCount < 0) - _ChildFormatCount = _ChildFormats.Count; - return _ChildFormats; - } - } - public void RefreshChildFormats() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) - foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) - tmp._ChildFormatCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base FormatInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FormatInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check FormatInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FormatInfo - protected override object GetIdValue() - { - return _FormatID; - } - #endregion - #region Factory Methods - private static int _FormatInfoUnique = 0; - private static int FormatInfoUnique - { get { return ++_FormatInfoUnique; } } - private int _MyFormatInfoUnique = FormatInfoUnique; - public int MyFormatInfoUnique - { get { return _MyFormatInfoUnique; } } - protected FormatInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) return; - List listFormatInfo = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items - while (listFormatInfo.Contains(this)) listFormatInfo.Remove(this); // Remove the item from the list - if (listFormatInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list - } - public virtual Format Get() - { - return _Editable = Format.Get(_FormatID); - } - public static void Refresh(Format tmp) - { - string key = tmp.FormatID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (FormatInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Format tmp) - { - if (_ParentID != tmp.ParentID) - { - if (MyParent != null) 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 - _Name = tmp.Name; - _Description = tmp.Description; - _Data = tmp.Data; - _GenMac = tmp.GenMac; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _FormatInfoExtension.Refresh(this); - if(_MyParent != null) - { - _MyParent.Dispose();// Dispose related value - _MyParent = null;// Reset related value - } - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(formatID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up FormatInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on FormatInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal FormatInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.Constructor", ex); - throw new DbCslaException("FormatInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _FormatID; - public int FormatID - { get { return _FormatID; } } - public PKCriteria(int formatID) - { - _FormatID = formatID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.ReadData", GetHashCode()); - try - { - _FormatID = dr.GetInt32("FormatID"); - _ParentID = dr.GetInt32("ParentID"); - _Name = dr.GetString("Name"); - _Description = dr.GetString("Description"); - _Data = dr.GetString("Data"); - _GenMac = dr.GetString("GenMac"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _FormatContentCount = dr.GetInt32("ContentCount"); - _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); - _FormatFolderCount = dr.GetInt32("FolderCount"); - _ChildFormatCount = dr.GetInt32("ChildCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FormatInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFormat"; - cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension(); - [Serializable()] - partial class FormatInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(FormatInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class FormatInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is FormatInfo) - { - // Return the ToString value - return ((FormatInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void FormatInfoEvent(object sender); + /// + /// FormatInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(FormatInfoConverter))] + public partial class FormatInfo : ReadOnlyBase, IDisposable + { + public event FormatInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(FormatInfo formatInfo) + { + if (!_CacheList.Contains(formatInfo)) _CacheList.Add(formatInfo); // In AddToCache + } + protected static void RemoveFromCache(FormatInfo formatInfo) + { + while (_CacheList.Contains(formatInfo)) _CacheList.Remove(formatInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (FormatInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.FormatID.ToString())) + { + _CacheByPrimaryKey[tmp.FormatID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (FormatInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(FormatInfoList lst) + { + foreach (FormatInfo item in lst) AddToCache(item); + } + protected static FormatInfo GetCachedByPrimaryKey(int formatID) + { + ConvertListToDictionary(); + string key = formatID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatID; + } + } + private int _ParentID; + public int ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent != null) _ParentID = _MyParent.FormatID; + return _ParentID; + } + } + private FormatInfo _MyParent; + public FormatInfo MyParent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyParent == null && _ParentID != _FormatID) _MyParent = FormatInfo.Get(_ParentID); + return _MyParent; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Description = string.Empty; + public string Description + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Description; + } + } + private string _Data = string.Empty; + public string Data + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Data; + } + } + private string _GenMac = string.Empty; + public string GenMac + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GenMac; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _FormatContentCount = 0; + /// + /// Count of FormatContents for this Format + /// + public int FormatContentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatContentCount; + } + } + private ContentInfoList _FormatContents = null; + [TypeConverter(typeof(ContentInfoListConverter))] + public ContentInfoList FormatContents + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatContentCount < 0 || (_FormatContentCount > 0 && _FormatContents == null)) + _FormatContents = ContentInfoList.GetByFormatID(_FormatID); + if (_FormatContentCount < 0) + _FormatContentCount = _FormatContents.Count; + return _FormatContents; + } + } + public void RefreshFormatContents() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) + tmp._FormatContentCount = -1; // This will cause the data to be requeried + } + private int _FormatDocVersionCount = 0; + /// + /// Count of FormatDocVersions for this Format + /// + public int FormatDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatDocVersionCount; + } + } + private DocVersionInfoList _FormatDocVersions = null; + [TypeConverter(typeof(DocVersionInfoListConverter))] + public DocVersionInfoList FormatDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatDocVersionCount < 0 || (_FormatDocVersionCount > 0 && _FormatDocVersions == null)) + _FormatDocVersions = DocVersionInfoList.GetByFormatID(_FormatID); + if (_FormatDocVersionCount < 0) + _FormatDocVersionCount = _FormatDocVersions.Count; + return _FormatDocVersions; + } + } + public void RefreshFormatDocVersions() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) + tmp._FormatDocVersionCount = -1; // This will cause the data to be requeried + } + private int _FormatFolderCount = 0; + /// + /// Count of FormatFolders for this Format + /// + public int FormatFolderCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FormatFolderCount; + } + } + private FolderInfoList _FormatFolders = null; + [TypeConverter(typeof(FolderInfoListConverter))] + public FolderInfoList FormatFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_FormatFolderCount < 0 || (_FormatFolderCount > 0 && _FormatFolders == null)) + _FormatFolders = FolderInfoList.GetByFormatID(_FormatID); + if (_FormatFolderCount < 0) + _FormatFolderCount = _FormatFolders.Count; + return _FormatFolders; + } + } + public void RefreshFormatFolders() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) + tmp._FormatFolderCount = -1; // This will cause the data to be requeried + } + private int _ChildFormatCount = 0; + /// + /// Count of ChildFormats for this Format + /// + public int ChildFormatCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ChildFormatCount; + } + } + private FormatInfoList _ChildFormats = null; + [TypeConverter(typeof(FormatInfoListConverter))] + public FormatInfoList ChildFormats + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ChildFormatCount < 0 || (_ChildFormatCount > 0 && _ChildFormats == null)) + _ChildFormats = FormatInfoList.GetChildren(_FormatID); + if (_ChildFormatCount < 0) + _ChildFormatCount = _ChildFormats.Count; + return _ChildFormats; + } + } + public void RefreshChildFormats() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_FormatID.ToString())) + foreach (FormatInfo tmp in _CacheByPrimaryKey[_FormatID.ToString()]) + tmp._ChildFormatCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base FormatInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FormatInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check FormatInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FormatInfo + protected override object GetIdValue() + { + return _FormatID; + } + #endregion + #region Factory Methods + private static int _FormatInfoUnique = 0; + private static int FormatInfoUnique + { get { return ++_FormatInfoUnique; } } + private int _MyFormatInfoUnique = FormatInfoUnique; + public int MyFormatInfoUnique + { get { return _MyFormatInfoUnique; } } + protected FormatInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(FormatID.ToString())) return; + List listFormatInfo = _CacheByPrimaryKey[FormatID.ToString()]; // Get the list of items + while (listFormatInfo.Contains(this)) listFormatInfo.Remove(this); // Remove the item from the list + if (listFormatInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(FormatID.ToString()); // remove the list + } + public virtual Format Get() + { + return _Editable = Format.Get(_FormatID); + } + public static void Refresh(Format tmp) + { + string key = tmp.FormatID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (FormatInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Format tmp) + { + if (_ParentID != tmp.ParentID) + { + if (MyParent != null) 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 + _Name = tmp.Name; + _Description = tmp.Description; + _Data = tmp.Data; + _GenMac = tmp.GenMac; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _FormatInfoExtension.Refresh(this); + if (_MyParent != null) + { + _MyParent.Dispose();// Dispose related value + _MyParent = null;// Reset related value + } + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(formatID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FormatInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal FormatInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.Constructor", ex); + throw new DbCslaException("FormatInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _FormatID; + public int FormatID + { get { return _FormatID; } } + public PKCriteria(int formatID) + { + _FormatID = formatID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.ReadData", GetHashCode()); + try + { + _FormatID = dr.GetInt32("FormatID"); + _ParentID = dr.GetInt32("ParentID"); + _Name = dr.GetString("Name"); + _Description = dr.GetString("Description"); + _Data = dr.GetString("Data"); + _GenMac = dr.GetString("GenMac"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _FormatContentCount = dr.GetInt32("ContentCount"); + _FormatDocVersionCount = dr.GetInt32("DocVersionCount"); + _FormatFolderCount = dr.GetInt32("FolderCount"); + _ChildFormatCount = dr.GetInt32("ChildCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FormatInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormat"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension(); + [Serializable()] + partial class FormatInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(FormatInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class FormatInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is FormatInfo) + { + // Return the ToString value + return ((FormatInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Group.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Group.cs index e17a73fb..7da64e38 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Group.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Group.cs @@ -20,1176 +20,1161 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Group Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupConverter))] - public partial class Group : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshGroups = new List(); - private List _RefreshGroupAssignments = new List(); - private List _RefreshGroupMemberships = new List(); - private void AddToRefreshList(List refreshGroups, List refreshGroupAssignments, List refreshGroupMemberships) - { - if (IsDirty) - refreshGroups.Add(this); - if (_GroupAssignments != null && _GroupAssignments.IsDirty) - { - foreach (GroupAssignment tmp in _GroupAssignments) - { - if (tmp.IsDirty) refreshGroupAssignments.Add(tmp); - } - } - if (_GroupMemberships != null && _GroupMemberships.IsDirty) - { - foreach (GroupMembership tmp in _GroupMemberships) - { - if (tmp.IsDirty) refreshGroupMemberships.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshGroups = new List(); - _RefreshGroupAssignments = new List(); - _RefreshGroupMemberships = new List(); - AddToRefreshList(_RefreshGroups, _RefreshGroupAssignments, _RefreshGroupMemberships); - } - private void ProcessRefreshList() - { - foreach (Group tmp in _RefreshGroups) - { - GroupInfo.Refresh(tmp); - } - foreach (GroupAssignment tmp in _RefreshGroupAssignments) - { - AssignmentInfo.Refresh(tmp); - } - foreach (GroupMembership tmp in _RefreshGroupMemberships) - { - MembershipInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Group group) - { - if (!_CacheList.Contains(group)) _CacheList.Add(group); // In AddToCache - } - protected static void RemoveFromCache(Group group) - { - while (_CacheList.Contains(group)) _CacheList.Remove(group); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByGroupName = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Group tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.GID.ToString())) - { - _CacheByPrimaryKey[tmp.GID.ToString()] = new List(); // Add new list for PrimaryKey - _CacheByGroupName[tmp.GroupName.ToString()] = new List(); // Add new list for GroupName - } - _CacheByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list - _CacheByGroupName[tmp.GroupName.ToString()].Add(tmp); // Unique Index - remove.Add(tmp); - } - foreach (Group tmp in remove) - RemoveFromCache(tmp); - } - protected static Group GetCachedByPrimaryKey(int gid) - { - ConvertListToDictionary(); - string key = gid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Group GetCachedByGroupName(string groupName) - { - ConvertListToDictionary(); - string key = groupName.ToString(); - if (_CacheByGroupName.ContainsKey(key)) return _CacheByGroupName[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextGID = -1; - public static int NextGID - { - get { return _nextGID--; } - } - private int _GID; - [System.ComponentModel.DataObjectField(true, true)] - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - return _GID; - } - } - private string _GroupName = string.Empty; - public string GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupName", true); - return _GroupName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("GroupName", true); - if (value == null) value = string.Empty; - if (_GroupName != value) - { - _GroupName = value; - PropertyHasChanged(); - } - } - } - private int? _GroupType; - public int? GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupType", true); - return _GroupType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("GroupType", true); - if (_GroupType != value) - { - _GroupType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _GroupAssignmentCount = 0; - /// - /// Count of GroupAssignments for this Group - /// - public int GroupAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignmentCount", true); - return _GroupAssignmentCount; - } - } - private GroupAssignments _GroupAssignments = null; - /// - /// Related Field - /// - [TypeConverter(typeof(GroupAssignmentsConverter))] - public GroupAssignments GroupAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignments", true); - if (_GroupAssignmentCount > 0 && _GroupAssignments == null) - _GroupAssignments = GroupAssignments.GetByGID(GID); - else if (_GroupAssignments == null) - _GroupAssignments = GroupAssignments.New(); - return _GroupAssignments; - } - } - private int _GroupMembershipCount = 0; - /// - /// Count of GroupMemberships for this Group - /// - public int GroupMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMembershipCount", true); - return _GroupMembershipCount; - } - } - private GroupMemberships _GroupMemberships = null; - /// - /// Related Field - /// - [TypeConverter(typeof(GroupMembershipsConverter))] - public GroupMemberships GroupMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMemberships", true); - if (_GroupMembershipCount > 0 && _GroupMemberships == null) - _GroupMemberships = GroupMemberships.GetByGID(GID); - else if (_GroupMemberships == null) - _GroupMemberships = GroupMemberships.New(); - return _GroupMemberships; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_GroupAssignments == null ? false : _GroupAssignments.IsDirty) || (_GroupMemberships == null ? false : _GroupMemberships.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_GroupAssignments == null ? true : _GroupAssignments.IsValid) && (_GroupMemberships == null ? true : _GroupMemberships.IsValid); } - } - // TODO: Replace base Group.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Group - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Group.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Group - protected override object GetIdValue() - { - return _GID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_GroupAssignments != null && (hasBrokenRules = _GroupAssignments.HasBrokenRules) != null) return hasBrokenRules; - if (_GroupMemberships != null && (hasBrokenRules = _GroupMemberships.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "GroupName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("GroupName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _GroupExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _GroupExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowRead(GroupName, ""); - //AuthorizationRules.AllowRead(GroupType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(GroupName, ""); - //AuthorizationRules.AllowWrite(GroupType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _GroupExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _GroupExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _GroupUnique = 0; - protected static int GroupUnique - { get { return ++_GroupUnique; } } - private int _MyGroupUnique = GroupUnique; - public int MyGroupUnique - { get { return _MyGroupUnique; } } - protected Group() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(GID.ToString())) - { - List listGroup = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items - while (listGroup.Contains(this)) listGroup.Remove(this); // Remove the item from the list - if (listGroup.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(GID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByGroupName.Keys) - if (_CacheByGroupName[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listGroup = _CacheByGroupName[myKey]; // Get the list of items - listGroup.Remove(this); // Remove the item from the list - if (listGroup.Count == 0) //If there are no items left in the list - _CacheByGroupName.Remove(myKey); // remove the list - } - } - public static Group New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Group"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.New", ex); - } - } - public static Group New(string groupName) - { - Group tmp = Group.New(); - tmp.GroupName = groupName; - return tmp; - } - public static Group New(string groupName, int? groupType, string config, DateTime dts, string usrID) - { - Group tmp = Group.New(); - tmp.GroupName = groupName; - tmp.GroupType = groupType; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Group MakeGroup(string groupName, int? groupType, string config, DateTime dts, string usrID) - { - Group tmp = Group.New(groupName, groupType, config, dts, usrID); - if (tmp.IsSavable) - { - Group tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Group New(string groupName, int? groupType, string config) - { - Group tmp = Group.New(); - tmp.GroupName = groupName; - tmp.GroupType = groupType; - tmp.Config = config; - return tmp; - } - public static Group MakeGroup(string groupName, int? groupType, string config) - { - Group tmp = Group.New(groupName, groupType, config); - if (tmp.IsSavable) - { - Group tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(gid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Group - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.Get", ex); - } - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new GroupNameCriteria(groupName)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Group - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.GetByGroupName", ex); - } - } - public static Group Get(SafeDataReader dr) - { - if (dr.Read()) return new Group(dr); - return null; - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.Delete", ex); - } - } - 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(); - Group group = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(group);//Refresh the item in AllList - ProcessRefreshList(); - return group; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _GID; - public int GID - { get { return _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; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _GID = NextGID; - // Database Defaults - _DTS = _GroupExtension.DefaultDTS; - _UsrID = _GroupExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.ReadData", GetHashCode()); - try - { - _GID = dr.GetInt32("GID"); - _GroupName = dr.GetString("GroupName"); - _GroupType = (int?)dr.GetValue("GroupType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); - _GroupMembershipCount = dr.GetInt32("MembershipCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGroup"; - cm.Parameters.AddWithValue("@GID", criteria.GID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _GroupAssignments = GroupAssignments.Get(dr); - // load child objects - dr.NextResult(); - _GroupMemberships = GroupMemberships.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(GroupNameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGroupByGroupName"; - cm.Parameters.AddWithValue("@GroupName", criteria.GroupName); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Group.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - gid = (int)cm.Parameters["@newGID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Add", ex); - throw new DbCslaException("Group.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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 (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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); - MarkOld(); - } - if (_GroupAssignments != null) _GroupAssignments.Update(this); - if (_GroupMemberships != null) _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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateGroup"; - // Input All Fields - Except Calculated Columns - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteGroup"; - cm.Parameters.AddWithValue("@GID", criteria.GID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteGroup"; - // Input PK Fields - cm.Parameters.AddWithValue("@GID", gid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Remove", ex); - throw new DbCslaException("Group.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int gid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(gid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Group.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _GID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int gid) - { - _GID = gid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsGroup"; - cm.Parameters.AddWithValue("@GID", _GID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Execute", ex); - throw new DbCslaException("Group.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - GroupExtension _GroupExtension = new GroupExtension(); - [Serializable()] - partial class GroupExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GroupConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Group) - { - // Return the ToString value - return ((Group)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Group Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupConverter))] + public partial class Group : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshGroups = new List(); + private List _RefreshGroupAssignments = new List(); + private List _RefreshGroupMemberships = new List(); + private void AddToRefreshList(List refreshGroups, List refreshGroupAssignments, List refreshGroupMemberships) + { + if (IsDirty) + refreshGroups.Add(this); + if (_GroupAssignments != null && _GroupAssignments.IsDirty) + { + foreach (GroupAssignment tmp in _GroupAssignments) + { + if (tmp.IsDirty) refreshGroupAssignments.Add(tmp); + } + } + if (_GroupMemberships != null && _GroupMemberships.IsDirty) + { + foreach (GroupMembership tmp in _GroupMemberships) + { + if (tmp.IsDirty) refreshGroupMemberships.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshGroups = new List(); + _RefreshGroupAssignments = new List(); + _RefreshGroupMemberships = new List(); + AddToRefreshList(_RefreshGroups, _RefreshGroupAssignments, _RefreshGroupMemberships); + } + private void ProcessRefreshList() + { + foreach (Group tmp in _RefreshGroups) + { + GroupInfo.Refresh(tmp); + } + foreach (GroupAssignment tmp in _RefreshGroupAssignments) + { + AssignmentInfo.Refresh(tmp); + } + foreach (GroupMembership tmp in _RefreshGroupMemberships) + { + MembershipInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Group group) + { + if (!_CacheList.Contains(group)) _CacheList.Add(group); // In AddToCache + } + protected static void RemoveFromCache(Group group) + { + while (_CacheList.Contains(group)) _CacheList.Remove(group); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByGroupName = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Group tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.GID.ToString())) + { + _CacheByPrimaryKey[tmp.GID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByGroupName[tmp.GroupName.ToString()] = new List(); // Add new list for GroupName + } + _CacheByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByGroupName[tmp.GroupName.ToString()].Add(tmp); // Unique Index + remove.Add(tmp); + } + foreach (Group tmp in remove) + RemoveFromCache(tmp); + } + protected static Group GetCachedByPrimaryKey(int gid) + { + ConvertListToDictionary(); + string key = gid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Group GetCachedByGroupName(string groupName) + { + ConvertListToDictionary(); + string key = groupName.ToString(); + if (_CacheByGroupName.ContainsKey(key)) return _CacheByGroupName[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextGID = -1; + public static int NextGID + { + get { return _nextGID--; } + } + private int _GID; + [System.ComponentModel.DataObjectField(true, true)] + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GID; + } + } + private string _GroupName = string.Empty; + public string GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_GroupName != value) + { + _GroupName = value; + PropertyHasChanged(); + } + } + } + private int? _GroupType; + public int? GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_GroupType != value) + { + _GroupType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _GroupAssignmentCount = 0; + /// + /// Count of GroupAssignments for this Group + /// + public int GroupAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupAssignmentCount; + } + } + private GroupAssignments _GroupAssignments = null; + /// + /// Related Field + /// + [TypeConverter(typeof(GroupAssignmentsConverter))] + public GroupAssignments GroupAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupAssignmentCount > 0 && _GroupAssignments == null) + _GroupAssignments = GroupAssignments.GetByGID(GID); + else if (_GroupAssignments == null) + _GroupAssignments = GroupAssignments.New(); + return _GroupAssignments; + } + } + private int _GroupMembershipCount = 0; + /// + /// Count of GroupMemberships for this Group + /// + public int GroupMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupMembershipCount; + } + } + private GroupMemberships _GroupMemberships = null; + /// + /// Related Field + /// + [TypeConverter(typeof(GroupMembershipsConverter))] + public GroupMemberships GroupMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupMembershipCount > 0 && _GroupMemberships == null) + _GroupMemberships = GroupMemberships.GetByGID(GID); + else if (_GroupMemberships == null) + _GroupMemberships = GroupMemberships.New(); + return _GroupMemberships; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_GroupAssignments == null ? false : _GroupAssignments.IsDirty) || (_GroupMemberships == null ? false : _GroupMemberships.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_GroupAssignments == null ? true : _GroupAssignments.IsValid) && (_GroupMemberships == null ? true : _GroupMemberships.IsValid); } + } + // TODO: Replace base Group.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Group + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Group.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Group + protected override object GetIdValue() + { + return _GID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_GroupAssignments != null && (hasBrokenRules = _GroupAssignments.HasBrokenRules) != null) return hasBrokenRules; + if (_GroupMemberships != null && (hasBrokenRules = _GroupMemberships.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "GroupName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("GroupName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _GroupExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _GroupExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowRead(GroupName, ""); + //AuthorizationRules.AllowRead(GroupType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(GroupName, ""); + //AuthorizationRules.AllowWrite(GroupType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _GroupExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _GroupExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _GroupUnique = 0; + protected static int GroupUnique + { get { return ++_GroupUnique; } } + private int _MyGroupUnique = GroupUnique; + public int MyGroupUnique + { get { return _MyGroupUnique; } } + protected Group() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(GID.ToString())) + { + List listGroup = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items + while (listGroup.Contains(this)) listGroup.Remove(this); // Remove the item from the list + if (listGroup.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(GID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByGroupName.Keys) + if (_CacheByGroupName[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listGroup = _CacheByGroupName[myKey]; // Get the list of items + listGroup.Remove(this); // Remove the item from the list + if (listGroup.Count == 0) //If there are no items left in the list + _CacheByGroupName.Remove(myKey); // remove the list + } + } + public static Group New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Group"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.New", ex); + } + } + public static Group New(string groupName) + { + Group tmp = Group.New(); + tmp.GroupName = groupName; + return tmp; + } + public static Group New(string groupName, int? groupType, string config, DateTime dts, string usrID) + { + Group tmp = Group.New(); + tmp.GroupName = groupName; + tmp.GroupType = groupType; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Group MakeGroup(string groupName, int? groupType, string config, DateTime dts, string usrID) + { + Group tmp = Group.New(groupName, groupType, config, dts, usrID); + if (tmp.IsSavable) + { + Group tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Group New(string groupName, int? groupType, string config) + { + Group tmp = Group.New(); + tmp.GroupName = groupName; + tmp.GroupType = groupType; + tmp.Config = config; + return tmp; + } + public static Group MakeGroup(string groupName, int? groupType, string config) + { + Group tmp = Group.New(groupName, groupType, config); + if (tmp.IsSavable) + { + Group tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(gid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Group + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.Get", ex); + } + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new GroupNameCriteria(groupName)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Group + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.GetByGroupName", ex); + } + } + public static Group Get(SafeDataReader dr) + { + if (dr.Read()) return new Group(dr); + return null; + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.Delete", ex); + } + } + 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(); + Group group = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(group);//Refresh the item in AllList + ProcessRefreshList(); + return group; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _GID; + public int GID + { get { return _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; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _GID = NextGID; + // Database Defaults + _DTS = _GroupExtension.DefaultDTS; + _UsrID = _GroupExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.ReadData", GetHashCode()); + try + { + _GID = dr.GetInt32("GID"); + _GroupName = dr.GetString("GroupName"); + _GroupType = (int?)dr.GetValue("GroupType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); + _GroupMembershipCount = dr.GetInt32("MembershipCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroup"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _GroupAssignments = GroupAssignments.Get(dr); + // load child objects + dr.NextResult(); + _GroupMemberships = GroupMemberships.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(GroupNameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroupByGroupName"; + cm.Parameters.AddWithValue("@GroupName", criteria.GroupName); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Group.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + gid = (int)cm.Parameters["@newGID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Add", ex); + throw new DbCslaException("Group.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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 (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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); + MarkOld(); + } + if (_GroupAssignments != null) _GroupAssignments.Update(this); + if (_GroupMemberships != null) _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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateGroup"; + // Input All Fields - Except Calculated Columns + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteGroup"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteGroup"; + // Input PK Fields + cm.Parameters.AddWithValue("@GID", gid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.Remove", ex); + throw new DbCslaException("Group.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int gid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(gid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Group.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _GID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int gid) + { + _GID = gid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Group.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsGroup"; + cm.Parameters.AddWithValue("@GID", _GID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Group.DataPortal_Execute", ex); + throw new DbCslaException("Group.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + GroupExtension _GroupExtension = new GroupExtension(); + [Serializable()] + partial class GroupExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GroupConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Group) + { + // Return the ToString value + return ((Group)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupAssignment.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupAssignment.cs index d85321ec..6db324b0 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupAssignment.cs @@ -19,687 +19,657 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// GroupAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupAssignmentConverter))] - public partial class GroupAssignment : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - if (_MyAssignment != null) _AID = _MyAssignment.AID; - return _AID; - } - } - private Assignment _MyAssignment; - [System.ComponentModel.DataObjectField(true, true)] - public Assignment MyAssignment - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssignment", true); - if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); - return _MyAssignment; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private Role _MyRole; - public Role MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); - return _MyRole; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRole", true); - if (_MyRole != value) - { - _MyRole = value; - PropertyHasChanged(); - } - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - private string _Role_Name = string.Empty; - public string Role_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Name", true); - return _Role_Name; - } - } - private string _Role_Title = string.Empty; - public string Role_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_Title", true); - return _Role_Title; - } - } - private DateTime _Role_DTS = new DateTime(); - public DateTime Role_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_DTS", true); - return _Role_DTS; - } - } - private string _Role_UsrID = string.Empty; - public string Role_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Role_UsrID", true); - return _Role_UsrID; - } - } - // TODO: Check GroupAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupAssignment - protected override object GetIdValue() - { - return _AID; - } - // TODO: Replace base GroupAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirty) || (_MyFolder == null ? false : _MyFolder.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRoleRequired, "MyRole"); - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool StartDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyRoleRequired(GroupAssignment target, Csla.Validation.RuleArgs e) - { - if (target._RID == 0 && target._MyRole == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyFolderRequired(GroupAssignment target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AID, ""); - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowWrite(RID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static GroupAssignment New(Role myRole, Folder myFolder) - { - return new GroupAssignment(myRole, myFolder); - } - internal static GroupAssignment Get(SafeDataReader dr) - { - return new GroupAssignment(dr); - } - public GroupAssignment() - { - MarkAsChild(); - _AID = Assignment.NextAID; - _StartDate = _GroupAssignmentExtension.DefaultStartDate; - _DTS = _GroupAssignmentExtension.DefaultDTS; - _UsrID = _GroupAssignmentExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private GroupAssignment(Role myRole, Folder myFolder) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _StartDate = _GroupAssignmentExtension.DefaultStartDate; - _DTS = _GroupAssignmentExtension.DefaultDTS; - _UsrID = _GroupAssignmentExtension.DefaultUsrID; - _MyRole = myRole; - _MyFolder = myFolder; - ValidationRules.CheckRules(); - } - internal GroupAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupAssignment.FetchDR", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _RID = dr.GetInt32("RID"); - _FolderID = dr.GetInt32("FolderID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - _Role_Name = dr.GetString("Role_Name"); - _Role_Title = dr.GetString("Role_Title"); - _Role_DTS = dr.GetDateTime("Role_DTS"); - _Role_UsrID = dr.GetString("Role_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupAssignment.FetchDR", ex); - throw new DbCslaException("GroupAssignment.Fetch", ex); - } - MarkOld(); - } - 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 = 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, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - GroupAssignmentExtension _GroupAssignmentExtension = new GroupAssignmentExtension(); - [Serializable()] - partial class GroupAssignmentExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GroupAssignmentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GroupAssignment) - { - // Return the ToString value - return ((GroupAssignment)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// GroupAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupAssignmentConverter))] + public partial class GroupAssignment : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment != null) _AID = _MyAssignment.AID; + return _AID; + } + } + private Assignment _MyAssignment; + [System.ComponentModel.DataObjectField(true, true)] + public Assignment MyAssignment + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); + return _MyAssignment; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private Role _MyRole; + public Role MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); + return _MyRole; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRole != value) + { + _MyRole = value; + PropertyHasChanged(); + } + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + private string _Role_Name = string.Empty; + public string Role_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Name; + } + } + private string _Role_Title = string.Empty; + public string Role_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_Title; + } + } + private DateTime _Role_DTS = new DateTime(); + public DateTime Role_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_DTS; + } + } + private string _Role_UsrID = string.Empty; + public string Role_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Role_UsrID; + } + } + // TODO: Check GroupAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupAssignment + protected override object GetIdValue() + { + return _AID; + } + // TODO: Replace base GroupAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirty) || (_MyFolder == null ? false : _MyFolder.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRoleRequired, "MyRole"); + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool StartDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(GroupAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyRoleRequired(GroupAssignment target, Csla.Validation.RuleArgs e) + { + if (target._RID == 0 && target._MyRole == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyFolderRequired(GroupAssignment target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(AID, ""); + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowWrite(RID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static GroupAssignment New(Role myRole, Folder myFolder) + { + return new GroupAssignment(myRole, myFolder); + } + internal static GroupAssignment Get(SafeDataReader dr) + { + return new GroupAssignment(dr); + } + public GroupAssignment() + { + MarkAsChild(); + _AID = Assignment.NextAID; + _StartDate = _GroupAssignmentExtension.DefaultStartDate; + _DTS = _GroupAssignmentExtension.DefaultDTS; + _UsrID = _GroupAssignmentExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private GroupAssignment(Role myRole, Folder myFolder) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _StartDate = _GroupAssignmentExtension.DefaultStartDate; + _DTS = _GroupAssignmentExtension.DefaultDTS; + _UsrID = _GroupAssignmentExtension.DefaultUsrID; + _MyRole = myRole; + _MyFolder = myFolder; + ValidationRules.CheckRules(); + } + internal GroupAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupAssignment.FetchDR", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _RID = dr.GetInt32("RID"); + _FolderID = dr.GetInt32("FolderID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + _Role_Name = dr.GetString("Role_Name"); + _Role_Title = dr.GetString("Role_Title"); + _Role_DTS = dr.GetDateTime("Role_DTS"); + _Role_UsrID = dr.GetString("Role_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupAssignment.FetchDR", ex); + throw new DbCslaException("GroupAssignment.Fetch", ex); + } + MarkOld(); + } + 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 = 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, _MyRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + GroupAssignmentExtension _GroupAssignmentExtension = new GroupAssignmentExtension(); + [Serializable()] + partial class GroupAssignmentExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GroupAssignmentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupAssignment) + { + // Return the ToString value + return ((GroupAssignment)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupInfo.cs index 4b00a128..08715aaf 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupInfo.cs @@ -19,401 +19,391 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void GroupInfoEvent(object sender); - /// - /// GroupInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupInfoConverter))] - public partial class GroupInfo : ReadOnlyBase, IDisposable - { - public event GroupInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(GroupInfo groupInfo) - { - if (!_CacheList.Contains(groupInfo)) _CacheList.Add(groupInfo); // In AddToCache - } - protected static void RemoveFromCache(GroupInfo groupInfo) - { - while (_CacheList.Contains(groupInfo)) _CacheList.Remove(groupInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (GroupInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.GID.ToString())) - { - _CacheByPrimaryKey[tmp.GID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (GroupInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(GroupInfoList lst) - { - foreach (GroupInfo item in lst) AddToCache(item); - } - protected static GroupInfo GetCachedByPrimaryKey(int gid) - { - ConvertListToDictionary(); - string key = gid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - 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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - return _GID; - } - } - private string _GroupName = string.Empty; - public string GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupName", true); - return _GroupName; - } - } - private int? _GroupType; - public int? GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupType", true); - return _GroupType; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _GroupAssignmentCount = 0; - /// - /// Count of GroupAssignments for this Group - /// - public int GroupAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignmentCount", true); - return _GroupAssignmentCount; - } - } - private AssignmentInfoList _GroupAssignments = null; - [TypeConverter(typeof(AssignmentInfoListConverter))] - public AssignmentInfoList GroupAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupAssignments", true); - if (_GroupAssignmentCount < 0 || (_GroupAssignmentCount > 0 && _GroupAssignments == null)) - _GroupAssignments = AssignmentInfoList.GetByGID(_GID); - if (_GroupAssignmentCount < 0) - _GroupAssignmentCount = _GroupAssignments.Count; - return _GroupAssignments; - } - } - public void RefreshGroupAssignments() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) - foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()]) - tmp._GroupAssignmentCount = -1; // This will cause the data to be requeried - } - private int _GroupMembershipCount = 0; - /// - /// Count of GroupMemberships for this Group - /// - public int GroupMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMembershipCount", true); - return _GroupMembershipCount; - } - } - private MembershipInfoList _GroupMemberships = null; - [TypeConverter(typeof(MembershipInfoListConverter))] - public MembershipInfoList GroupMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GroupMemberships", true); - if (_GroupMembershipCount < 0 || (_GroupMembershipCount > 0 && _GroupMemberships == null)) - _GroupMemberships = MembershipInfoList.GetByGID(_GID); - if (_GroupMembershipCount < 0) - _GroupMembershipCount = _GroupMemberships.Count; - return _GroupMemberships; - } - } - public void RefreshGroupMemberships() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) - foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()]) - tmp._GroupMembershipCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base GroupInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check GroupInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupInfo - protected override object GetIdValue() - { - return _GID; - } - #endregion - #region Factory Methods - private static int _GroupInfoUnique = 0; - private static int GroupInfoUnique - { get { return ++_GroupInfoUnique; } } - private int _MyGroupInfoUnique = GroupInfoUnique; - public int MyGroupInfoUnique - { get { return _MyGroupInfoUnique; } } - protected GroupInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(GID.ToString())) return; - List listGroupInfo = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items - while (listGroupInfo.Contains(this)) listGroupInfo.Remove(this); // Remove the item from the list - 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 static void Refresh(Group tmp) - { - string key = tmp.GID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (GroupInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Group tmp) - { - _GroupName = tmp.GroupName; - _GroupType = tmp.GroupType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _GroupInfoExtension.Refresh(this); - OnChange();// raise an event - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(gid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up GroupInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on GroupInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal GroupInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.Constructor", ex); - throw new DbCslaException("GroupInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _GID; - public int GID - { get { return _GID; } } - public PKCriteria(int gid) - { - _GID = gid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.ReadData", GetHashCode()); - try - { - _GID = dr.GetInt32("GID"); - _GroupName = dr.GetString("GroupName"); - _GroupType = (int?)dr.GetValue("GroupType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); - _GroupMembershipCount = dr.GetInt32("MembershipCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GroupInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGroup"; - cm.Parameters.AddWithValue("@GID", criteria.GID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("GroupInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - GroupInfoExtension _GroupInfoExtension = new GroupInfoExtension(); - [Serializable()] - partial class GroupInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(GroupInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class GroupInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GroupInfo) - { - // Return the ToString value - return ((GroupInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void GroupInfoEvent(object sender); + /// + /// GroupInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupInfoConverter))] + public partial class GroupInfo : ReadOnlyBase, IDisposable + { + public event GroupInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(GroupInfo groupInfo) + { + if (!_CacheList.Contains(groupInfo)) _CacheList.Add(groupInfo); // In AddToCache + } + protected static void RemoveFromCache(GroupInfo groupInfo) + { + while (_CacheList.Contains(groupInfo)) _CacheList.Remove(groupInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (GroupInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.GID.ToString())) + { + _CacheByPrimaryKey[tmp.GID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.GID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (GroupInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(GroupInfoList lst) + { + foreach (GroupInfo item in lst) AddToCache(item); + } + protected static GroupInfo GetCachedByPrimaryKey(int gid) + { + ConvertListToDictionary(); + string key = gid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + 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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GID; + } + } + private string _GroupName = string.Empty; + public string GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupName; + } + } + private int? _GroupType; + public int? GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupType; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _GroupAssignmentCount = 0; + /// + /// Count of GroupAssignments for this Group + /// + public int GroupAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupAssignmentCount; + } + } + private AssignmentInfoList _GroupAssignments = null; + [TypeConverter(typeof(AssignmentInfoListConverter))] + public AssignmentInfoList GroupAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupAssignmentCount < 0 || (_GroupAssignmentCount > 0 && _GroupAssignments == null)) + _GroupAssignments = AssignmentInfoList.GetByGID(_GID); + if (_GroupAssignmentCount < 0) + _GroupAssignmentCount = _GroupAssignments.Count; + return _GroupAssignments; + } + } + public void RefreshGroupAssignments() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) + foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()]) + tmp._GroupAssignmentCount = -1; // This will cause the data to be requeried + } + private int _GroupMembershipCount = 0; + /// + /// Count of GroupMemberships for this Group + /// + public int GroupMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _GroupMembershipCount; + } + } + private MembershipInfoList _GroupMemberships = null; + [TypeConverter(typeof(MembershipInfoListConverter))] + public MembershipInfoList GroupMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_GroupMembershipCount < 0 || (_GroupMembershipCount > 0 && _GroupMemberships == null)) + _GroupMemberships = MembershipInfoList.GetByGID(_GID); + if (_GroupMembershipCount < 0) + _GroupMembershipCount = _GroupMemberships.Count; + return _GroupMemberships; + } + } + public void RefreshGroupMemberships() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_GID.ToString())) + foreach (GroupInfo tmp in _CacheByPrimaryKey[_GID.ToString()]) + tmp._GroupMembershipCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base GroupInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check GroupInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupInfo + protected override object GetIdValue() + { + return _GID; + } + #endregion + #region Factory Methods + private static int _GroupInfoUnique = 0; + private static int GroupInfoUnique + { get { return ++_GroupInfoUnique; } } + private int _MyGroupInfoUnique = GroupInfoUnique; + public int MyGroupInfoUnique + { get { return _MyGroupInfoUnique; } } + protected GroupInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(GID.ToString())) return; + List listGroupInfo = _CacheByPrimaryKey[GID.ToString()]; // Get the list of items + while (listGroupInfo.Contains(this)) listGroupInfo.Remove(this); // Remove the item from the list + 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 static void Refresh(Group tmp) + { + string key = tmp.GID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (GroupInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Group tmp) + { + _GroupName = tmp.GroupName; + _GroupType = tmp.GroupType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _GroupInfoExtension.Refresh(this); + OnChange();// raise an event + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(gid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up GroupInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on GroupInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal GroupInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.Constructor", ex); + throw new DbCslaException("GroupInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _GID; + public int GID + { get { return _GID; } } + public PKCriteria(int gid) + { + _GID = gid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.ReadData", GetHashCode()); + try + { + _GID = dr.GetInt32("GID"); + _GroupName = dr.GetString("GroupName"); + _GroupType = (int?)dr.GetValue("GroupType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _GroupAssignmentCount = dr.GetInt32("AssignmentCount"); + _GroupMembershipCount = dr.GetInt32("MembershipCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GroupInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroup"; + cm.Parameters.AddWithValue("@GID", criteria.GID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("GroupInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + GroupInfoExtension _GroupInfoExtension = new GroupInfoExtension(); + [Serializable()] + partial class GroupInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(GroupInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class GroupInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupInfo) + { + // Return the ToString value + return ((GroupInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupMembership.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupMembership.cs index c7c3966b..1e5460e3 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupMembership.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/GroupMembership.cs @@ -19,656 +19,628 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// GroupMembership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(GroupMembershipConverter))] - public partial class GroupMembership : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - if (_MyMembership != null) _UGID = _MyMembership.UGID; - return _UGID; - } - } - private Membership _MyMembership; - [System.ComponentModel.DataObjectField(true, true)] - public Membership MyMembership - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyMembership", true); - if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); - return _MyMembership; - } - } - private int _UID; - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - if (_MyUser != null) _UID = _MyUser.UID; - return _UID; - } - } - private User _MyUser; - public User MyUser - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyUser", true); - if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); - return _MyUser; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyUser", true); - if (_MyUser != value) - { - _MyUser = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _User_UserID = string.Empty; - public string User_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UserID", true); - return _User_UserID; - } - } - private string _User_FirstName = string.Empty; - public string User_FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_FirstName", true); - return _User_FirstName; - } - } - private string _User_MiddleName = string.Empty; - public string User_MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_MiddleName", true); - return _User_MiddleName; - } - } - private string _User_LastName = string.Empty; - public string User_LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_LastName", true); - return _User_LastName; - } - } - private string _User_Suffix = string.Empty; - public string User_Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_Suffix", true); - return _User_Suffix; - } - } - private string _User_CourtesyTitle = string.Empty; - public string User_CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_CourtesyTitle", true); - return _User_CourtesyTitle; - } - } - private string _User_PhoneNumber = string.Empty; - public string User_PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_PhoneNumber", true); - return _User_PhoneNumber; - } - } - private string _User_CFGName = string.Empty; - public string User_CFGName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_CFGName", true); - return _User_CFGName; - } - } - private string _User_UserLogin = string.Empty; - public string User_UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UserLogin", true); - return _User_UserLogin; - } - } - private string _User_UserName = string.Empty; - public string User_UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UserName", true); - return _User_UserName; - } - } - private string _User_Config = string.Empty; - public string User_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_Config", true); - return _User_Config; - } - } - private DateTime _User_DTS = new DateTime(); - public DateTime User_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_DTS", true); - return _User_DTS; - } - } - private string _User_UsrID = string.Empty; - public string User_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("User_UsrID", true); - return _User_UsrID; - } - } - // TODO: Check GroupMembership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupMembership - protected override object GetIdValue() - { - return _UGID; - } - // TODO: Replace base GroupMembership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupMembership - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyUser == null ? false : _MyUser.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyUser == null ? true : _MyUser.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyUserRequired, "MyUser"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool StartDateValid(GroupMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(GroupMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyUserRequired(GroupMembership target, Csla.Validation.RuleArgs e) - { - if (target._UID == 0 && target._MyUser == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(UGID, ""); - //AuthorizationRules.AllowRead(UID, ""); - //AuthorizationRules.AllowWrite(UID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static GroupMembership New(User myUser) - { - return new GroupMembership(myUser); - } - internal static GroupMembership Get(SafeDataReader dr) - { - return new GroupMembership(dr); - } - public GroupMembership() - { - MarkAsChild(); - _UGID = Membership.NextUGID; - _StartDate = _GroupMembershipExtension.DefaultStartDate; - _DTS = _GroupMembershipExtension.DefaultDTS; - _UsrID = _GroupMembershipExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private GroupMembership(User myUser) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _StartDate = _GroupMembershipExtension.DefaultStartDate; - _DTS = _GroupMembershipExtension.DefaultDTS; - _UsrID = _GroupMembershipExtension.DefaultUsrID; - _MyUser = myUser; - ValidationRules.CheckRules(); - } - internal GroupMembership(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupMembership.FetchDR", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _UID = dr.GetInt32("UID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _User_UserID = dr.GetString("User_UserID"); - _User_FirstName = dr.GetString("User_FirstName"); - _User_MiddleName = dr.GetString("User_MiddleName"); - _User_LastName = dr.GetString("User_LastName"); - _User_Suffix = dr.GetString("User_Suffix"); - _User_CourtesyTitle = dr.GetString("User_CourtesyTitle"); - _User_PhoneNumber = dr.GetString("User_PhoneNumber"); - _User_CFGName = dr.GetString("User_CFGName"); - _User_UserLogin = dr.GetString("User_UserLogin"); - _User_UserName = dr.GetString("User_UserName"); - _User_Config = dr.GetString("User_Config"); - _User_DTS = dr.GetDateTime("User_DTS"); - _User_UsrID = dr.GetString("User_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupMembership.FetchDR", ex); - throw new DbCslaException("GroupMembership.Fetch", ex); - } - MarkOld(); - } - 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); - 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, _MyUser, myGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - 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"]; - Membership.Remove(cn, _UGID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - GroupMembershipExtension _GroupMembershipExtension = new GroupMembershipExtension(); - [Serializable()] - partial class GroupMembershipExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class GroupMembershipConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is GroupMembership) - { - // Return the ToString value - return ((GroupMembership)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// GroupMembership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(GroupMembershipConverter))] + public partial class GroupMembership : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership != null) _UGID = _MyMembership.UGID; + return _UGID; + } + } + private Membership _MyMembership; + [System.ComponentModel.DataObjectField(true, true)] + public Membership MyMembership + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); + return _MyMembership; + } + } + private int _UID; + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser != null) _UID = _MyUser.UID; + return _UID; + } + } + private User _MyUser; + public User MyUser + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); + return _MyUser; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyUser != value) + { + _MyUser = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _User_UserID = string.Empty; + public string User_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UserID; + } + } + private string _User_FirstName = string.Empty; + public string User_FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_FirstName; + } + } + private string _User_MiddleName = string.Empty; + public string User_MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_MiddleName; + } + } + private string _User_LastName = string.Empty; + public string User_LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_LastName; + } + } + private string _User_Suffix = string.Empty; + public string User_Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_Suffix; + } + } + private string _User_CourtesyTitle = string.Empty; + public string User_CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_CourtesyTitle; + } + } + private string _User_PhoneNumber = string.Empty; + public string User_PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_PhoneNumber; + } + } + private string _User_CFGName = string.Empty; + public string User_CFGName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_CFGName; + } + } + private string _User_UserLogin = string.Empty; + public string User_UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UserLogin; + } + } + private string _User_UserName = string.Empty; + public string User_UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UserName; + } + } + private string _User_Config = string.Empty; + public string User_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_Config; + } + } + private DateTime _User_DTS = new DateTime(); + public DateTime User_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_DTS; + } + } + private string _User_UsrID = string.Empty; + public string User_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _User_UsrID; + } + } + // TODO: Check GroupMembership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupMembership + protected override object GetIdValue() + { + return _UGID; + } + // TODO: Replace base GroupMembership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupMembership + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyUser == null ? false : _MyUser.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyUser == null ? true : _MyUser.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyUserRequired, "MyUser"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool StartDateValid(GroupMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(GroupMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyUserRequired(GroupMembership target, Csla.Validation.RuleArgs e) + { + if (target._UID == 0 && target._MyUser == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(UGID, ""); + //AuthorizationRules.AllowRead(UID, ""); + //AuthorizationRules.AllowWrite(UID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static GroupMembership New(User myUser) + { + return new GroupMembership(myUser); + } + internal static GroupMembership Get(SafeDataReader dr) + { + return new GroupMembership(dr); + } + public GroupMembership() + { + MarkAsChild(); + _UGID = Membership.NextUGID; + _StartDate = _GroupMembershipExtension.DefaultStartDate; + _DTS = _GroupMembershipExtension.DefaultDTS; + _UsrID = _GroupMembershipExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private GroupMembership(User myUser) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _StartDate = _GroupMembershipExtension.DefaultStartDate; + _DTS = _GroupMembershipExtension.DefaultDTS; + _UsrID = _GroupMembershipExtension.DefaultUsrID; + _MyUser = myUser; + ValidationRules.CheckRules(); + } + internal GroupMembership(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] GroupMembership.FetchDR", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _UID = dr.GetInt32("UID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _User_UserID = dr.GetString("User_UserID"); + _User_FirstName = dr.GetString("User_FirstName"); + _User_MiddleName = dr.GetString("User_MiddleName"); + _User_LastName = dr.GetString("User_LastName"); + _User_Suffix = dr.GetString("User_Suffix"); + _User_CourtesyTitle = dr.GetString("User_CourtesyTitle"); + _User_PhoneNumber = dr.GetString("User_PhoneNumber"); + _User_CFGName = dr.GetString("User_CFGName"); + _User_UserLogin = dr.GetString("User_UserLogin"); + _User_UserName = dr.GetString("User_UserName"); + _User_Config = dr.GetString("User_Config"); + _User_DTS = dr.GetDateTime("User_DTS"); + _User_UsrID = dr.GetString("User_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("GroupMembership.FetchDR", ex); + throw new DbCslaException("GroupMembership.Fetch", ex); + } + MarkOld(); + } + 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); + 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, _MyUser, myGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + 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"]; + Membership.Remove(cn, _UGID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + GroupMembershipExtension _GroupMembershipExtension = new GroupMembershipExtension(); + [Serializable()] + partial class GroupMembershipExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class GroupMembershipConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is GroupMembership) + { + // Return the ToString value + return ((GroupMembership)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Item.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Item.cs index 743c337d..07cc77d7 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Item.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Item.cs @@ -20,1307 +20,1284 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Item Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemConverter))] - public partial class Item : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshItems = new List(); - private List _RefreshItemAnnotations = new List(); - private List _RefreshItemDocVersions = new List(); - private List _RefreshItemParts = new List(); - private List _RefreshItemTransitions_RangeID = new List(); - private List _RefreshItemTransitions_ToID = new List(); - private void AddToRefreshList(List refreshItems, List refreshItemAnnotations, List refreshItemDocVersions, List refreshItemParts, List refreshItemTransitions_RangeID, List refreshItemTransitions_ToID) - { - if (IsDirty) - refreshItems.Add(this); - if (_ItemAnnotations != null && _ItemAnnotations.IsDirty) - { - foreach (ItemAnnotation tmp in _ItemAnnotations) - { - if (tmp.IsDirty) refreshItemAnnotations.Add(tmp); - } - } - if (_ItemDocVersions != null && _ItemDocVersions.IsDirty) - { - foreach (ItemDocVersion tmp in _ItemDocVersions) - { - if (tmp.IsDirty) refreshItemDocVersions.Add(tmp); - } - } - if (_NextItems != null && _NextItems.IsDirty) - { - foreach (Item tmp in _NextItems) - { - tmp.AddToRefreshList(refreshItems, refreshItemAnnotations, refreshItemDocVersions, refreshItemParts, refreshItemTransitions_RangeID, refreshItemTransitions_ToID); - } - } - if (_ItemParts != null && _ItemParts.IsDirty) - { - foreach (ItemPart tmp in _ItemParts) - { - if (tmp.IsDirty) refreshItemParts.Add(tmp); - } - } - if (_ItemTransitions_RangeID != null && _ItemTransitions_RangeID.IsDirty) - { - foreach (ItemTransition_RangeID tmp in _ItemTransitions_RangeID) - { - if (tmp.IsDirty) refreshItemTransitions_RangeID.Add(tmp); - } - } - if (_ItemTransitions_ToID != null && _ItemTransitions_ToID.IsDirty) - { - foreach (ItemTransition_ToID tmp in _ItemTransitions_ToID) - { - if (tmp.IsDirty) refreshItemTransitions_ToID.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshItems = new List(); - _RefreshItemAnnotations = new List(); - _RefreshItemDocVersions = new List(); - _RefreshItemParts = new List(); - _RefreshItemTransitions_RangeID = new List(); - _RefreshItemTransitions_ToID = new List(); - AddToRefreshList(_RefreshItems, _RefreshItemAnnotations, _RefreshItemDocVersions, _RefreshItemParts, _RefreshItemTransitions_RangeID, _RefreshItemTransitions_ToID); - } - private void ProcessRefreshList() - { - foreach (Item tmp in _RefreshItems) - { - ItemInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - } - foreach (ItemAnnotation tmp in _RefreshItemAnnotations) - { - AnnotationInfo.Refresh(tmp); - } - foreach (ItemDocVersion tmp in _RefreshItemDocVersions) - { - DocVersionInfo.Refresh(tmp); - } - foreach (ItemPart tmp in _RefreshItemParts) - { - PartInfo.Refresh(tmp); - } - foreach (ItemTransition_RangeID tmp in _RefreshItemTransitions_RangeID) - { - TransitionInfo.Refresh(tmp); - } - foreach (ItemTransition_ToID tmp in _RefreshItemTransitions_ToID) - { - TransitionInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Item item) - { - if (!_CacheList.Contains(item)) _CacheList.Add(item); // In AddToCache - } - protected static void RemoveFromCache(Item item) - { - while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Item tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ItemID.ToString())) - { - _CacheByPrimaryKey[tmp.ItemID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Item tmp in remove) - RemoveFromCache(tmp); - } - protected static Item GetCachedByPrimaryKey(int itemID) - { - ConvertListToDictionary(); - string key = itemID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextItemID = -1; - public static int NextItemID - { - get { return _nextItemID--; } - } - private int _ItemID; - [System.ComponentModel.DataObjectField(true, true)] - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; - return _PreviousID; - } - } - private Item _MyPrevious; - public Item MyPrevious - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPrevious", true); - if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); - return _MyPrevious; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyPrevious", true); - if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) - { - _MyPrevious = value; - _PreviousID = (value == null ? null : (int?)value.ItemID); - PropertyHasChanged(); - } - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ItemAnnotationCount = 0; - /// - /// Count of ItemAnnotations for this Item - /// - public int ItemAnnotationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotationCount", true); - return _ItemAnnotationCount; - } - } - private ItemAnnotations _ItemAnnotations = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemAnnotationsConverter))] - public ItemAnnotations ItemAnnotations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotations", true); - if (_ItemAnnotationCount > 0 && _ItemAnnotations == null) - _ItemAnnotations = ItemAnnotations.GetByItemID(ItemID); - else if (_ItemAnnotations == null) - _ItemAnnotations = ItemAnnotations.New(); - return _ItemAnnotations; - } - } - private int _ItemDocVersionCount = 0; - /// - /// Count of ItemDocVersions for this Item - /// - public int ItemDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersionCount", true); - return _ItemDocVersionCount; - } - } - private ItemDocVersions _ItemDocVersions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemDocVersionsConverter))] - public ItemDocVersions ItemDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersions", true); - if (_ItemDocVersionCount > 0 && _ItemDocVersions == null) - _ItemDocVersions = ItemDocVersions.GetByItemID(ItemID); - else if (_ItemDocVersions == null) - _ItemDocVersions = ItemDocVersions.New(); - return _ItemDocVersions; - } - } - private int _NextItemCount = 0; - /// - /// Count of NextItems for this Item - /// - public int NextItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItemCount", true); - return _NextItemCount; - } - } - private NextItems _NextItems = null; - /// - /// Related Field - /// - [TypeConverter(typeof(NextItemsConverter))] - public NextItems NextItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItems", true); - if (_NextItemCount > 0 && _NextItems == null) - _NextItems = NextItems.GetByPreviousID(ItemID); - else if (_NextItems == null) - _NextItems = NextItems.New(); - return _NextItems; - } - } - private int _ItemPartCount = 0; - /// - /// Count of ItemParts for this Item - /// - public int ItemPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemPartCount", true); - return _ItemPartCount; - } - } - private ItemParts _ItemParts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemPartsConverter))] - public ItemParts ItemParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemParts", true); - if (_ItemPartCount > 0 && _ItemParts == null) - _ItemParts = ItemParts.GetByItemID(ItemID); - else if (_ItemParts == null) - _ItemParts = ItemParts.New(); - return _ItemParts; - } - } - private int _ItemTransition_RangeIDCount = 0; - /// - /// Count of ItemTransitions for this Item - /// - public int ItemTransition_RangeIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_RangeIDCount", true); - return _ItemTransition_RangeIDCount; - } - } - private ItemTransitions_RangeID _ItemTransitions_RangeID = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemTransitions_RangeIDConverter))] - public ItemTransitions_RangeID ItemTransitions_RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_RangeID", true); - if (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null) - _ItemTransitions_RangeID = ItemTransitions_RangeID.GetByRangeID(ItemID); - else if (_ItemTransitions_RangeID == null) - _ItemTransitions_RangeID = ItemTransitions_RangeID.New(); - return _ItemTransitions_RangeID; - } - } - private int _ItemTransition_ToIDCount = 0; - /// - /// Count of ItemTransitions for this Item - /// - public int ItemTransition_ToIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_ToIDCount", true); - return _ItemTransition_ToIDCount; - } - } - private ItemTransitions_ToID _ItemTransitions_ToID = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ItemTransitions_ToIDConverter))] - public ItemTransitions_ToID ItemTransitions_ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_ToID", true); - if (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null) - _ItemTransitions_ToID = ItemTransitions_ToID.GetByToID(ItemID); - else if (_ItemTransitions_ToID == null) - _ItemTransitions_ToID = ItemTransitions_ToID.New(); - return _ItemTransitions_ToID; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_ItemAnnotations == null ? false : _ItemAnnotations.IsDirty) || (_ItemDocVersions == null ? false : _ItemDocVersions.IsDirty) || (_NextItems == null ? false : _NextItems.IsDirty) || (_ItemParts == null ? false : _ItemParts.IsDirty) || (_ItemTransitions_RangeID == null ? false : _ItemTransitions_RangeID.IsDirty) || (_ItemTransitions_ToID == null ? false : _ItemTransitions_ToID.IsDirty) || (_MyContent == null ? false : _MyContent.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ItemAnnotations == null ? true : _ItemAnnotations.IsValid) && (_ItemDocVersions == null ? true : _ItemDocVersions.IsValid) && (_NextItems == null ? true : _NextItems.IsValid) && (_ItemParts == null ? true : _ItemParts.IsValid) && (_ItemTransitions_RangeID == null ? true : _ItemTransitions_RangeID.IsValid) && (_ItemTransitions_ToID == null ? true : _ItemTransitions_ToID.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } - } - // TODO: Replace base Item.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Item - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Item.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Item - protected override object GetIdValue() - { - return _ItemID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ItemAnnotations != null && (hasBrokenRules = _ItemAnnotations.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemDocVersions != null && (hasBrokenRules = _ItemDocVersions.HasBrokenRules) != null) return hasBrokenRules; - if (_NextItems != null && (hasBrokenRules = _NextItems.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemParts != null && (hasBrokenRules = _ItemParts.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemTransitions_RangeID != null && (hasBrokenRules = _ItemTransitions_RangeID.HasBrokenRules) != null) return hasBrokenRules; - if (_ItemTransitions_ToID != null && (hasBrokenRules = _ItemTransitions_ToID.HasBrokenRules) != null) return hasBrokenRules; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ItemExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ItemExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyContentRequired(Item target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(PreviousID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(PreviousID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ItemExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ItemExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ItemUnique = 0; - protected static int ItemUnique - { get { return ++_ItemUnique; } } - private int _MyItemUnique = ItemUnique; - public int MyItemUnique - { get { return _MyItemUnique; } } - protected Item() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) - { - List listItem = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items - while (listItem.Contains(this)) listItem.Remove(this); // Remove the item from the list - if (listItem.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list - } - } - public static Item New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Item"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.New", ex); - } - } - public static Item New(Content myContent) - { - Item tmp = Item.New(); - tmp.MyContent = myContent; - return tmp; - } - public static Item New(Item myPrevious, Content myContent, DateTime dts, string userID) - { - Item tmp = Item.New(); - tmp.MyPrevious = myPrevious; - tmp.MyContent = myContent; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Item MakeItem(Item myPrevious, Content myContent, DateTime dts, string userID) - { - Item tmp = Item.New(myPrevious, myContent, dts, userID); - if (tmp.IsSavable) - { - Item tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Item New(Item myPrevious, Content myContent) - { - Item tmp = Item.New(); - tmp.MyPrevious = myPrevious; - tmp.MyContent = myContent; - return tmp; - } - public static Item MakeItem(Item myPrevious, Content myContent) - { - Item tmp = Item.New(myPrevious, myContent); - if (tmp.IsSavable) - { - Item tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - 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); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(itemID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Item - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.Get", ex); - } - } - public static Item Get(SafeDataReader dr, Item previous) - { - if (dr.Read()) return new Item(dr, previous); - return null; - } - internal Item(SafeDataReader dr) - { - ReadData(dr); - } - private Item(SafeDataReader dr, Item previous) - { - ReadData(dr); - MarkAsChild(); - } - internal Item(SafeDataReader dr, int parentID) - { - ReadData(dr); - MarkAsChild(); - } - 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)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.Delete", ex); - } - } - 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(); - Item item = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(item);//Refresh the item in AllList - ProcessRefreshList(); - return item; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ItemID; - public int ItemID - { get { return _ItemID; } } - public PKCriteria(int itemID) - { - _ItemID = itemID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ItemID = NextItemID; - // Database Defaults - _DTS = _ItemExtension.DefaultDTS; - _UserID = _ItemExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.ReadData", GetHashCode()); - try - { - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); - _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); - _NextItemCount = dr.GetInt32("NextCount"); - _ItemPartCount = dr.GetInt32("PartCount"); - _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); - _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Item.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItem"; - cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ItemAnnotations = ItemAnnotations.Get(dr); - // load child objects - dr.NextResult(); - _ItemDocVersions = ItemDocVersions.Get(dr); - // load child objects - dr.NextResult(); - _ItemParts = ItemParts.Get(dr); - // load child objects - dr.NextResult(); - _ItemTransitions_RangeID = ItemTransitions_RangeID.Get(dr); - // load child objects - dr.NextResult(); - _ItemTransitions_ToID = ItemTransitions_ToID.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Item.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Item.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLInsert", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addItem"; - // Input All Fields - Except Calculated Columns - if (myPrevious != null) cm.Parameters.AddWithValue("@PreviousID", myPrevious.ItemID); - cm.Parameters.AddWithValue("@ContentID", myContent.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - itemID = (int)cm.Parameters["@newItemID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Add", ex); - throw new DbCslaException("Item.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - // TODO: 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); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.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, _MyPrevious, _MyContent, _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); - } - internal void DeleteSelf(Item item) - { - // 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"]; - Item.Remove(cn, _ItemID); - MarkNew(); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int itemID, Item myPrevious, Content myContent, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateItem"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ItemID", itemID); - if (myPrevious != null) cm.Parameters.AddWithValue("@PreviousID", myPrevious.ItemID); - cm.Parameters.AddWithValue("@ContentID", myContent.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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Update", ex); - 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()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteItem"; - cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - 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); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteItem"; - // Input PK Fields - cm.Parameters.AddWithValue("@ItemID", itemID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Remove", ex); - throw new DbCslaException("Item.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int itemID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(itemID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Item.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ItemID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int itemID) - { - _ItemID = itemID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsItem"; - cm.Parameters.AddWithValue("@ItemID", _ItemID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Execute", ex); - throw new DbCslaException("Item.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ItemExtension _ItemExtension = new ItemExtension(); - [Serializable()] - partial class ItemExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Item) - { - // Return the ToString value - return ((Item)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Item Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemConverter))] + public partial class Item : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshItems = new List(); + private List _RefreshItemAnnotations = new List(); + private List _RefreshItemDocVersions = new List(); + private List _RefreshItemParts = new List(); + private List _RefreshItemTransitions_RangeID = new List(); + private List _RefreshItemTransitions_ToID = new List(); + private void AddToRefreshList(List refreshItems, List refreshItemAnnotations, List refreshItemDocVersions, List refreshItemParts, List refreshItemTransitions_RangeID, List refreshItemTransitions_ToID) + { + if (IsDirty) + refreshItems.Add(this); + if (_ItemAnnotations != null && _ItemAnnotations.IsDirty) + { + foreach (ItemAnnotation tmp in _ItemAnnotations) + { + if (tmp.IsDirty) refreshItemAnnotations.Add(tmp); + } + } + if (_ItemDocVersions != null && _ItemDocVersions.IsDirty) + { + foreach (ItemDocVersion tmp in _ItemDocVersions) + { + if (tmp.IsDirty) refreshItemDocVersions.Add(tmp); + } + } + if (_NextItems != null && _NextItems.IsDirty) + { + foreach (Item tmp in _NextItems) + { + tmp.AddToRefreshList(refreshItems, refreshItemAnnotations, refreshItemDocVersions, refreshItemParts, refreshItemTransitions_RangeID, refreshItemTransitions_ToID); + } + } + if (_ItemParts != null && _ItemParts.IsDirty) + { + foreach (ItemPart tmp in _ItemParts) + { + if (tmp.IsDirty) refreshItemParts.Add(tmp); + } + } + if (_ItemTransitions_RangeID != null && _ItemTransitions_RangeID.IsDirty) + { + foreach (ItemTransition_RangeID tmp in _ItemTransitions_RangeID) + { + if (tmp.IsDirty) refreshItemTransitions_RangeID.Add(tmp); + } + } + if (_ItemTransitions_ToID != null && _ItemTransitions_ToID.IsDirty) + { + foreach (ItemTransition_ToID tmp in _ItemTransitions_ToID) + { + if (tmp.IsDirty) refreshItemTransitions_ToID.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshItems = new List(); + _RefreshItemAnnotations = new List(); + _RefreshItemDocVersions = new List(); + _RefreshItemParts = new List(); + _RefreshItemTransitions_RangeID = new List(); + _RefreshItemTransitions_ToID = new List(); + AddToRefreshList(_RefreshItems, _RefreshItemAnnotations, _RefreshItemDocVersions, _RefreshItemParts, _RefreshItemTransitions_RangeID, _RefreshItemTransitions_ToID); + } + private void ProcessRefreshList() + { + foreach (Item tmp in _RefreshItems) + { + ItemInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + } + foreach (ItemAnnotation tmp in _RefreshItemAnnotations) + { + AnnotationInfo.Refresh(tmp); + } + foreach (ItemDocVersion tmp in _RefreshItemDocVersions) + { + DocVersionInfo.Refresh(tmp); + } + foreach (ItemPart tmp in _RefreshItemParts) + { + PartInfo.Refresh(tmp); + } + foreach (ItemTransition_RangeID tmp in _RefreshItemTransitions_RangeID) + { + TransitionInfo.Refresh(tmp); + } + foreach (ItemTransition_ToID tmp in _RefreshItemTransitions_ToID) + { + TransitionInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Item item) + { + if (!_CacheList.Contains(item)) _CacheList.Add(item); // In AddToCache + } + protected static void RemoveFromCache(Item item) + { + while (_CacheList.Contains(item)) _CacheList.Remove(item); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Item tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ItemID.ToString())) + { + _CacheByPrimaryKey[tmp.ItemID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Item tmp in remove) + RemoveFromCache(tmp); + } + protected static Item GetCachedByPrimaryKey(int itemID) + { + ConvertListToDictionary(); + string key = itemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextItemID = -1; + public static int NextItemID + { + get { return _nextItemID--; } + } + private int _ItemID; + [System.ComponentModel.DataObjectField(true, true)] + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; + return _PreviousID; + } + } + private Item _MyPrevious; + public Item MyPrevious + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious == null && _PreviousID != null) _MyPrevious = Item.Get((int)_PreviousID); + return _MyPrevious; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyPrevious == null ? _PreviousID : (int?)_MyPrevious.ItemID) != (value == null ? null : (int?)value.ItemID)) + { + _MyPrevious = value; + _PreviousID = (value == null ? null : (int?)value.ItemID); + PropertyHasChanged(); + } + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ItemAnnotationCount = 0; + /// + /// Count of ItemAnnotations for this Item + /// + public int ItemAnnotationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemAnnotationCount; + } + } + private ItemAnnotations _ItemAnnotations = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemAnnotationsConverter))] + public ItemAnnotations ItemAnnotations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemAnnotationCount > 0 && _ItemAnnotations == null) + _ItemAnnotations = ItemAnnotations.GetByItemID(ItemID); + else if (_ItemAnnotations == null) + _ItemAnnotations = ItemAnnotations.New(); + return _ItemAnnotations; + } + } + private int _ItemDocVersionCount = 0; + /// + /// Count of ItemDocVersions for this Item + /// + public int ItemDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemDocVersionCount; + } + } + private ItemDocVersions _ItemDocVersions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemDocVersionsConverter))] + public ItemDocVersions ItemDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemDocVersionCount > 0 && _ItemDocVersions == null) + _ItemDocVersions = ItemDocVersions.GetByItemID(ItemID); + else if (_ItemDocVersions == null) + _ItemDocVersions = ItemDocVersions.New(); + return _ItemDocVersions; + } + } + private int _NextItemCount = 0; + /// + /// Count of NextItems for this Item + /// + public int NextItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _NextItemCount; + } + } + private NextItems _NextItems = null; + /// + /// Related Field + /// + [TypeConverter(typeof(NextItemsConverter))] + public NextItems NextItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_NextItemCount > 0 && _NextItems == null) + _NextItems = NextItems.GetByPreviousID(ItemID); + else if (_NextItems == null) + _NextItems = NextItems.New(); + return _NextItems; + } + } + private int _ItemPartCount = 0; + /// + /// Count of ItemParts for this Item + /// + public int ItemPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemPartCount; + } + } + private ItemParts _ItemParts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemPartsConverter))] + public ItemParts ItemParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemPartCount > 0 && _ItemParts == null) + _ItemParts = ItemParts.GetByItemID(ItemID); + else if (_ItemParts == null) + _ItemParts = ItemParts.New(); + return _ItemParts; + } + } + private int _ItemTransition_RangeIDCount = 0; + /// + /// Count of ItemTransitions for this Item + /// + public int ItemTransition_RangeIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemTransition_RangeIDCount; + } + } + private ItemTransitions_RangeID _ItemTransitions_RangeID = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemTransitions_RangeIDConverter))] + public ItemTransitions_RangeID ItemTransitions_RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null) + _ItemTransitions_RangeID = ItemTransitions_RangeID.GetByRangeID(ItemID); + else if (_ItemTransitions_RangeID == null) + _ItemTransitions_RangeID = ItemTransitions_RangeID.New(); + return _ItemTransitions_RangeID; + } + } + private int _ItemTransition_ToIDCount = 0; + /// + /// Count of ItemTransitions for this Item + /// + public int ItemTransition_ToIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemTransition_ToIDCount; + } + } + private ItemTransitions_ToID _ItemTransitions_ToID = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ItemTransitions_ToIDConverter))] + public ItemTransitions_ToID ItemTransitions_ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null) + _ItemTransitions_ToID = ItemTransitions_ToID.GetByToID(ItemID); + else if (_ItemTransitions_ToID == null) + _ItemTransitions_ToID = ItemTransitions_ToID.New(); + return _ItemTransitions_ToID; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_ItemAnnotations == null ? false : _ItemAnnotations.IsDirty) || (_ItemDocVersions == null ? false : _ItemDocVersions.IsDirty) || (_NextItems == null ? false : _NextItems.IsDirty) || (_ItemParts == null ? false : _ItemParts.IsDirty) || (_ItemTransitions_RangeID == null ? false : _ItemTransitions_RangeID.IsDirty) || (_ItemTransitions_ToID == null ? false : _ItemTransitions_ToID.IsDirty) || (_MyContent == null ? false : _MyContent.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ItemAnnotations == null ? true : _ItemAnnotations.IsValid) && (_ItemDocVersions == null ? true : _ItemDocVersions.IsValid) && (_NextItems == null ? true : _NextItems.IsValid) && (_ItemParts == null ? true : _ItemParts.IsValid) && (_ItemTransitions_RangeID == null ? true : _ItemTransitions_RangeID.IsValid) && (_ItemTransitions_ToID == null ? true : _ItemTransitions_ToID.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } + } + // TODO: Replace base Item.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Item + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Item.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Item + protected override object GetIdValue() + { + return _ItemID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ItemAnnotations != null && (hasBrokenRules = _ItemAnnotations.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemDocVersions != null && (hasBrokenRules = _ItemDocVersions.HasBrokenRules) != null) return hasBrokenRules; + if (_NextItems != null && (hasBrokenRules = _NextItems.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemParts != null && (hasBrokenRules = _ItemParts.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemTransitions_RangeID != null && (hasBrokenRules = _ItemTransitions_RangeID.HasBrokenRules) != null) return hasBrokenRules; + if (_ItemTransitions_ToID != null && (hasBrokenRules = _ItemTransitions_ToID.HasBrokenRules) != null) return hasBrokenRules; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ItemExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ItemExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyContentRequired(Item target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(PreviousID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(PreviousID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ItemExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ItemExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ItemUnique = 0; + protected static int ItemUnique + { get { return ++_ItemUnique; } } + private int _MyItemUnique = ItemUnique; + public int MyItemUnique + { get { return _MyItemUnique; } } + protected Item() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) + { + List listItem = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items + while (listItem.Contains(this)) listItem.Remove(this); // Remove the item from the list + if (listItem.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list + } + } + public static Item New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Item"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.New", ex); + } + } + public static Item New(Content myContent) + { + Item tmp = Item.New(); + tmp.MyContent = myContent; + return tmp; + } + public static Item New(Item myPrevious, Content myContent, DateTime dts, string userID) + { + Item tmp = Item.New(); + tmp.MyPrevious = myPrevious; + tmp.MyContent = myContent; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Item MakeItem(Item myPrevious, Content myContent, DateTime dts, string userID) + { + Item tmp = Item.New(myPrevious, myContent, dts, userID); + if (tmp.IsSavable) + { + Item tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Item New(Item myPrevious, Content myContent) + { + Item tmp = Item.New(); + tmp.MyPrevious = myPrevious; + tmp.MyContent = myContent; + return tmp; + } + public static Item MakeItem(Item myPrevious, Content myContent) + { + Item tmp = Item.New(myPrevious, myContent); + if (tmp.IsSavable) + { + Item tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + 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); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Item + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Get", ex); + } + } + public static Item Get(SafeDataReader dr, Item previous) + { + if (dr.Read()) return new Item(dr, previous); + return null; + } + internal Item(SafeDataReader dr) + { + ReadData(dr); + } + private Item(SafeDataReader dr, Item previous) + { + ReadData(dr); + MarkAsChild(); + } + internal Item(SafeDataReader dr, int parentID) + { + ReadData(dr); + MarkAsChild(); + } + 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)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Delete", ex); + } + } + 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(); + Item item = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(item);//Refresh the item in AllList + ProcessRefreshList(); + return item; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + public PKCriteria(int itemID) + { + _ItemID = itemID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ItemID = NextItemID; + // Database Defaults + _DTS = _ItemExtension.DefaultDTS; + _UserID = _ItemExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.ReadData", GetHashCode()); + try + { + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); + _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); + _NextItemCount = dr.GetInt32("NextCount"); + _ItemPartCount = dr.GetInt32("PartCount"); + _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); + _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Item.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItem"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ItemAnnotations = ItemAnnotations.Get(dr); + // load child objects + dr.NextResult(); + _ItemDocVersions = ItemDocVersions.Get(dr); + // load child objects + dr.NextResult(); + _ItemParts = ItemParts.Get(dr); + // load child objects + dr.NextResult(); + _ItemTransitions_RangeID = ItemTransitions_RangeID.Get(dr); + // load child objects + dr.NextResult(); + _ItemTransitions_ToID = ItemTransitions_ToID.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Item.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Item.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLInsert", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addItem"; + // Input All Fields - Except Calculated Columns + if (myPrevious != null) cm.Parameters.AddWithValue("@PreviousID", myPrevious.ItemID); + cm.Parameters.AddWithValue("@ContentID", myContent.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + itemID = (int)cm.Parameters["@newItemID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Add", ex); + throw new DbCslaException("Item.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + // TODO: 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); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.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, _MyPrevious, _MyContent, _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); + } + internal void DeleteSelf(Item item) + { + // 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"]; + Item.Remove(cn, _ItemID); + MarkNew(); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int itemID, Item myPrevious, Content myContent, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateItem"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ItemID", itemID); + if (myPrevious != null) cm.Parameters.AddWithValue("@PreviousID", myPrevious.ItemID); + cm.Parameters.AddWithValue("@ContentID", myContent.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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Update", ex); + 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()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteItem"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + 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); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteItem"; + // Input PK Fields + cm.Parameters.AddWithValue("@ItemID", itemID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.Remove", ex); + throw new DbCslaException("Item.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int itemID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(itemID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Item.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ItemID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int itemID) + { + _ItemID = itemID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Item.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsItem"; + cm.Parameters.AddWithValue("@ItemID", _ItemID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Item.DataPortal_Execute", ex); + throw new DbCslaException("Item.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ItemExtension _ItemExtension = new ItemExtension(); + [Serializable()] + partial class ItemExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Item) + { + // Return the ToString value + return ((Item)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemAnnotation.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemAnnotation.cs index c1d21322..b0cbd41b 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemAnnotation.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemAnnotation.cs @@ -19,509 +19,490 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemAnnotation Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemAnnotationConverter))] - public partial class ItemAnnotation : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _AnnotationID; - [System.ComponentModel.DataObjectField(true, true)] - public int AnnotationID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationID", true); - if (_MyAnnotation != null) _AnnotationID = _MyAnnotation.AnnotationID; - return _AnnotationID; - } - } - private Annotation _MyAnnotation; - [System.ComponentModel.DataObjectField(true, true)] - public Annotation MyAnnotation - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAnnotation", true); - if (_MyAnnotation == null && _AnnotationID != 0) _MyAnnotation = Annotation.Get(_AnnotationID); - return _MyAnnotation; - } - } - private int _TypeID; - public int TypeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TypeID", true); - if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; - return _TypeID; - } - } - private AnnotationType _MyAnnotationType; - public AnnotationType MyAnnotationType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAnnotationType", true); - if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID); - return _MyAnnotationType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyAnnotationType", true); - if (_MyAnnotationType != value) - { - _MyAnnotationType = value; - PropertyHasChanged(); - } - } - } - private string _RtfText = string.Empty; - public string RtfText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RtfText", true); - return _RtfText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("RtfText", true); - if (value == null) value = string.Empty; - if (_RtfText != value) - { - _RtfText = value; - PropertyHasChanged(); - } - } - } - private string _SearchText = string.Empty; - public string SearchText - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("SearchText", true); - return _SearchText; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("SearchText", true); - if (value == null) value = string.Empty; - if (_SearchText != value) - { - _SearchText = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _AnnotationType_Name = string.Empty; - public string AnnotationType_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_Name", true); - return _AnnotationType_Name; - } - } - private string _AnnotationType_Config = string.Empty; - public string AnnotationType_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_Config", true); - return _AnnotationType_Config; - } - } - private DateTime _AnnotationType_DTS = new DateTime(); - public DateTime AnnotationType_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_DTS", true); - return _AnnotationType_DTS; - } - } - private string _AnnotationType_UserID = string.Empty; - public string AnnotationType_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AnnotationType_UserID", true); - return _AnnotationType_UserID; - } - } - // TODO: Check ItemAnnotation.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemAnnotation - protected override object GetIdValue() - { - return _AnnotationID; - } - // TODO: Replace base ItemAnnotation.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemAnnotation - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyAnnotationTypeRequired, "MyAnnotationType"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyAnnotationTypeRequired(ItemAnnotation target, Csla.Validation.RuleArgs e) - { - if (target._TypeID == 0 && target._MyAnnotationType == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AnnotationID, ""); - //AuthorizationRules.AllowRead(TypeID, ""); - //AuthorizationRules.AllowWrite(TypeID, ""); - //AuthorizationRules.AllowRead(RtfText, ""); - //AuthorizationRules.AllowWrite(RtfText, ""); - //AuthorizationRules.AllowRead(SearchText, ""); - //AuthorizationRules.AllowWrite(SearchText, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ItemAnnotation New(AnnotationType myAnnotationType) - { - return new ItemAnnotation(myAnnotationType); - } - internal static ItemAnnotation Get(SafeDataReader dr) - { - return new ItemAnnotation(dr); - } - public ItemAnnotation() - { - MarkAsChild(); - _AnnotationID = Annotation.NextAnnotationID; - _DTS = _ItemAnnotationExtension.DefaultDTS; - _UserID = _ItemAnnotationExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemAnnotation(AnnotationType myAnnotationType) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ItemAnnotationExtension.DefaultDTS; - _UserID = _ItemAnnotationExtension.DefaultUserID; - _MyAnnotationType = myAnnotationType; - ValidationRules.CheckRules(); - } - internal ItemAnnotation(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAnnotation.FetchDR", GetHashCode()); - try - { - _AnnotationID = dr.GetInt32("AnnotationID"); - _TypeID = dr.GetInt32("TypeID"); - _RtfText = dr.GetString("RtfText"); - _SearchText = dr.GetString("SearchText"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _AnnotationType_Name = dr.GetString("AnnotationType_Name"); - _AnnotationType_Config = dr.GetString("AnnotationType_Config"); - _AnnotationType_DTS = dr.GetDateTime("AnnotationType_DTS"); - _AnnotationType_UserID = dr.GetString("AnnotationType_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAnnotation.FetchDR", ex); - throw new DbCslaException("ItemAnnotation.Fetch", ex); - } - MarkOld(); - } - 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); - 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, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - 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"]; - Annotation.Remove(cn, _AnnotationID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension(); - [Serializable()] - partial class ItemAnnotationExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemAnnotationConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemAnnotation) - { - // Return the ToString value - return ((ItemAnnotation)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemAnnotation Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemAnnotationConverter))] + public partial class ItemAnnotation : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _AnnotationID; + [System.ComponentModel.DataObjectField(true, true)] + public int AnnotationID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotation != null) _AnnotationID = _MyAnnotation.AnnotationID; + return _AnnotationID; + } + } + private Annotation _MyAnnotation; + [System.ComponentModel.DataObjectField(true, true)] + public Annotation MyAnnotation + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotation == null && _AnnotationID != 0) _MyAnnotation = Annotation.Get(_AnnotationID); + return _MyAnnotation; + } + } + private int _TypeID; + public int TypeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType != null) _TypeID = _MyAnnotationType.TypeID; + return _TypeID; + } + } + private AnnotationType _MyAnnotationType; + public AnnotationType MyAnnotationType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAnnotationType == null && _TypeID != 0) _MyAnnotationType = AnnotationType.Get(_TypeID); + return _MyAnnotationType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyAnnotationType != value) + { + _MyAnnotationType = value; + PropertyHasChanged(); + } + } + } + private string _RtfText = string.Empty; + public string RtfText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RtfText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_RtfText != value) + { + _RtfText = value; + PropertyHasChanged(); + } + } + } + private string _SearchText = string.Empty; + public string SearchText + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _SearchText; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_SearchText != value) + { + _SearchText = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _AnnotationType_Name = string.Empty; + public string AnnotationType_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_Name; + } + } + private string _AnnotationType_Config = string.Empty; + public string AnnotationType_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_Config; + } + } + private DateTime _AnnotationType_DTS = new DateTime(); + public DateTime AnnotationType_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_DTS; + } + } + private string _AnnotationType_UserID = string.Empty; + public string AnnotationType_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _AnnotationType_UserID; + } + } + // TODO: Check ItemAnnotation.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemAnnotation + protected override object GetIdValue() + { + return _AnnotationID; + } + // TODO: Replace base ItemAnnotation.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemAnnotation + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyAnnotationType == null ? false : _MyAnnotationType.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyAnnotationType == null ? true : _MyAnnotationType.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyAnnotationType != null && (hasBrokenRules = _MyAnnotationType.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyAnnotationTypeRequired, "MyAnnotationType"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("RtfText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("SearchText", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyAnnotationTypeRequired(ItemAnnotation target, Csla.Validation.RuleArgs e) + { + if (target._TypeID == 0 && target._MyAnnotationType == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(AnnotationID, ""); + //AuthorizationRules.AllowRead(TypeID, ""); + //AuthorizationRules.AllowWrite(TypeID, ""); + //AuthorizationRules.AllowRead(RtfText, ""); + //AuthorizationRules.AllowWrite(RtfText, ""); + //AuthorizationRules.AllowRead(SearchText, ""); + //AuthorizationRules.AllowWrite(SearchText, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ItemAnnotation New(AnnotationType myAnnotationType) + { + return new ItemAnnotation(myAnnotationType); + } + internal static ItemAnnotation Get(SafeDataReader dr) + { + return new ItemAnnotation(dr); + } + public ItemAnnotation() + { + MarkAsChild(); + _AnnotationID = Annotation.NextAnnotationID; + _DTS = _ItemAnnotationExtension.DefaultDTS; + _UserID = _ItemAnnotationExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemAnnotation(AnnotationType myAnnotationType) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ItemAnnotationExtension.DefaultDTS; + _UserID = _ItemAnnotationExtension.DefaultUserID; + _MyAnnotationType = myAnnotationType; + ValidationRules.CheckRules(); + } + internal ItemAnnotation(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemAnnotation.FetchDR", GetHashCode()); + try + { + _AnnotationID = dr.GetInt32("AnnotationID"); + _TypeID = dr.GetInt32("TypeID"); + _RtfText = dr.GetString("RtfText"); + _SearchText = dr.GetString("SearchText"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _AnnotationType_Name = dr.GetString("AnnotationType_Name"); + _AnnotationType_Config = dr.GetString("AnnotationType_Config"); + _AnnotationType_DTS = dr.GetDateTime("AnnotationType_DTS"); + _AnnotationType_UserID = dr.GetString("AnnotationType_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemAnnotation.FetchDR", ex); + throw new DbCslaException("ItemAnnotation.Fetch", ex); + } + MarkOld(); + } + 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); + 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, _MyAnnotationType, _RtfText, _SearchText, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + 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"]; + Annotation.Remove(cn, _AnnotationID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemAnnotationExtension _ItemAnnotationExtension = new ItemAnnotationExtension(); + [Serializable()] + partial class ItemAnnotationExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemAnnotationConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemAnnotation) + { + // Return the ToString value + return ((ItemAnnotation)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemDocVersion.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemDocVersion.cs index 8cca4ccf..c7de8343 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemDocVersion.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemDocVersion.cs @@ -19,647 +19,617 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemDocVersion Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemDocVersionConverter))] - public partial class ItemDocVersion : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private int? _FormatID; - public int? FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FormatID", true); - if (_MyFormat != null) _FormatID = _MyFormat.FormatID; - return _FormatID; - } - } - private Format _MyFormat; - public Format MyFormat - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFormat", true); - if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); - return _MyFormat; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFormat", true); - if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) - { - _MyFormat = value; - _FormatID = (value == null ? null : (int?)value.FormatID); - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - // TODO: Check ItemDocVersion.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemDocVersion - protected override object GetIdValue() - { - return _VersionID; - } - // TODO: Replace base ItemDocVersion.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemDocVersion - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyFolderRequired(ItemDocVersion target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(FormatID, ""); - //AuthorizationRules.AllowWrite(FormatID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ItemDocVersion New(Folder myFolder, string name) - { - return new ItemDocVersion(myFolder, name); - } - internal static ItemDocVersion Get(SafeDataReader dr) - { - return new ItemDocVersion(dr); - } - public ItemDocVersion() - { - MarkAsChild(); - _VersionID = DocVersion.NextVersionID; - _VersionType = _ItemDocVersionExtension.DefaultVersionType; - _DTS = _ItemDocVersionExtension.DefaultDTS; - _UserID = _ItemDocVersionExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemDocVersion(Folder myFolder, string name) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _VersionType = _ItemDocVersionExtension.DefaultVersionType; - _DTS = _ItemDocVersionExtension.DefaultDTS; - _UserID = _ItemDocVersionExtension.DefaultUserID; - _MyFolder = myFolder; - _Name = name; - ValidationRules.CheckRules(); - } - internal ItemDocVersion(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemDocVersion.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _FolderID = dr.GetInt32("FolderID"); - _VersionType = dr.GetInt32("VersionType"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _FormatID = (int?)dr.GetValue("FormatID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemDocVersion.FetchDR", ex); - throw new DbCslaException("ItemDocVersion.Fetch", ex); - } - MarkOld(); - } - 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 = 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, _MyFolder, _VersionType, _Name, _Title, myItem, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension(); - [Serializable()] - partial class ItemDocVersionExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemDocVersionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemDocVersion) - { - // Return the ToString value - return ((ItemDocVersion)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemDocVersion Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemDocVersionConverter))] + public partial class ItemDocVersion : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private int? _FormatID; + public int? FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat != null) _FormatID = _MyFormat.FormatID; + return _FormatID; + } + } + private Format _MyFormat; + public Format MyFormat + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID); + return _MyFormat; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID)) + { + _MyFormat = value; + _FormatID = (value == null ? null : (int?)value.FormatID); + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + // TODO: Check ItemDocVersion.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemDocVersion + protected override object GetIdValue() + { + return _VersionID; + } + // TODO: Replace base ItemDocVersion.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemDocVersion + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyFolder == null ? false : _MyFolder.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyFolderRequired(ItemDocVersion target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(FormatID, ""); + //AuthorizationRules.AllowWrite(FormatID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ItemDocVersion New(Folder myFolder, string name) + { + return new ItemDocVersion(myFolder, name); + } + internal static ItemDocVersion Get(SafeDataReader dr) + { + return new ItemDocVersion(dr); + } + public ItemDocVersion() + { + MarkAsChild(); + _VersionID = DocVersion.NextVersionID; + _VersionType = _ItemDocVersionExtension.DefaultVersionType; + _DTS = _ItemDocVersionExtension.DefaultDTS; + _UserID = _ItemDocVersionExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemDocVersion(Folder myFolder, string name) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _VersionType = _ItemDocVersionExtension.DefaultVersionType; + _DTS = _ItemDocVersionExtension.DefaultDTS; + _UserID = _ItemDocVersionExtension.DefaultUserID; + _MyFolder = myFolder; + _Name = name; + ValidationRules.CheckRules(); + } + internal ItemDocVersion(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemDocVersion.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _FolderID = dr.GetInt32("FolderID"); + _VersionType = dr.GetInt32("VersionType"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _FormatID = (int?)dr.GetValue("FormatID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemDocVersion.FetchDR", ex); + throw new DbCslaException("ItemDocVersion.Fetch", ex); + } + MarkOld(); + } + 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 = 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, _MyFolder, _VersionType, _Name, _Title, myItem, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemDocVersionExtension _ItemDocVersionExtension = new ItemDocVersionExtension(); + [Serializable()] + partial class ItemDocVersionExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemDocVersionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemDocVersion) + { + // Return the ToString value + return ((ItemDocVersion)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemInfo.cs index c5f6ab91..6a730092 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemInfo.cs @@ -19,611 +19,592 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ItemInfoEvent(object sender); - /// - /// ItemInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemInfoConverter))] - public partial class ItemInfo : ReadOnlyBase, IDisposable - { - public event ItemInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ItemInfo itemInfo) - { - if (!_CacheList.Contains(itemInfo)) _CacheList.Add(itemInfo); // In AddToCache - } - protected static void RemoveFromCache(ItemInfo itemInfo) - { - while (_CacheList.Contains(itemInfo)) _CacheList.Remove(itemInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ItemInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ItemID.ToString())) - { - _CacheByPrimaryKey[tmp.ItemID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ItemInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(ItemInfoList lst) - { - foreach (ItemInfo item in lst) AddToCache(item); - } - protected static ItemInfo GetCachedByPrimaryKey(int itemID) - { - ConvertListToDictionary(); - string key = itemID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Item _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ItemID; - [System.ComponentModel.DataObjectField(true, true)] - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - return _ItemID; - } - } - private int? _PreviousID; - public int? PreviousID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PreviousID", true); - if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; - return _PreviousID; - } - } - private ItemInfo _MyPrevious; - public ItemInfo MyPrevious - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPrevious", true); - if (_MyPrevious == null && _PreviousID != null) _MyPrevious = ItemInfo.Get((int)_PreviousID); - return _MyPrevious; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ItemAnnotationCount = 0; - /// - /// Count of ItemAnnotations for this Item - /// - public int ItemAnnotationCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotationCount", true); - return _ItemAnnotationCount; - } - } - private AnnotationInfoList _ItemAnnotations = null; - [TypeConverter(typeof(AnnotationInfoListConverter))] - public AnnotationInfoList ItemAnnotations - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemAnnotations", true); - if (_ItemAnnotationCount < 0 || (_ItemAnnotationCount > 0 && _ItemAnnotations == null)) - _ItemAnnotations = AnnotationInfoList.GetByItemID(_ItemID); - if (_ItemAnnotationCount < 0) - _ItemAnnotationCount = _ItemAnnotations.Count; - return _ItemAnnotations; - } - } - public void RefreshItemAnnotations() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemAnnotationCount = -1; // This will cause the data to be requeried - } - private int _ItemDocVersionCount = 0; - /// - /// Count of ItemDocVersions for this Item - /// - public int ItemDocVersionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersionCount", true); - return _ItemDocVersionCount; - } - } - private DocVersionInfoList _ItemDocVersions = null; - [TypeConverter(typeof(DocVersionInfoListConverter))] - public DocVersionInfoList ItemDocVersions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemDocVersions", true); - if (_ItemDocVersionCount < 0 || (_ItemDocVersionCount > 0 && _ItemDocVersions == null)) - _ItemDocVersions = DocVersionInfoList.GetByItemID(_ItemID); - if (_ItemDocVersionCount < 0) - _ItemDocVersionCount = _ItemDocVersions.Count; - return _ItemDocVersions; - } - } - public void RefreshItemDocVersions() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemDocVersionCount = -1; // This will cause the data to be requeried - } - private int _NextItemCount = 0; - /// - /// Count of NextItems for this Item - /// - public int NextItemCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItemCount", true); - return _NextItemCount; - } - } - private ItemInfoList _NextItems = null; - [TypeConverter(typeof(ItemInfoListConverter))] - public ItemInfoList NextItems - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("NextItems", true); - if (_NextItemCount < 0 || (_NextItemCount > 0 && _NextItems == null)) - _NextItems = ItemInfoList.GetNext(_ItemID); - if (_NextItemCount < 0) - _NextItemCount = _NextItems.Count; - return _NextItems; - } - } - public void RefreshNextItems() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._NextItemCount = -1; // This will cause the data to be requeried - } - private int _ItemPartCount = 0; - /// - /// Count of ItemParts for this Item - /// - public int ItemPartCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemPartCount", true); - return _ItemPartCount; - } - } - private PartInfoList _ItemParts = null; - [TypeConverter(typeof(PartInfoListConverter))] - public PartInfoList ItemParts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemParts", true); - if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) - _ItemParts = PartInfoList.GetByItemID(_ItemID); - if (_ItemPartCount < 0) - _ItemPartCount = _ItemParts.Count; - return _ItemParts; - } - } - public void RefreshItemParts() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemPartCount = -1; // This will cause the data to be requeried - } - private int _ItemTransition_RangeIDCount = 0; - /// - /// Count of ItemTransitions for this Item - /// - public int ItemTransition_RangeIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_RangeIDCount", true); - return _ItemTransition_RangeIDCount; - } - } - private TransitionInfoList _ItemTransitions_RangeID = null; - [TypeConverter(typeof(TransitionInfoListConverter))] - public TransitionInfoList ItemTransitions_RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_RangeID", true); - if (_ItemTransition_RangeIDCount < 0 || (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null)) - _ItemTransitions_RangeID = TransitionInfoList.GetByRangeID(_ItemID); - if (_ItemTransition_RangeIDCount < 0) - _ItemTransition_RangeIDCount = _ItemTransitions_RangeID.Count; - return _ItemTransitions_RangeID; - } - } - public void RefreshItemTransitions_RangeID() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried - } - private int _ItemTransition_ToIDCount = 0; - /// - /// Count of ItemTransitions for this Item - /// - public int ItemTransition_ToIDCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransition_ToIDCount", true); - return _ItemTransition_ToIDCount; - } - } - private TransitionInfoList _ItemTransitions_ToID = null; - [TypeConverter(typeof(TransitionInfoListConverter))] - public TransitionInfoList ItemTransitions_ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemTransitions_ToID", true); - if (_ItemTransition_ToIDCount < 0 || (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null)) - _ItemTransitions_ToID = TransitionInfoList.GetByToID(_ItemID); - if (_ItemTransition_ToIDCount < 0) - _ItemTransition_ToIDCount = _ItemTransitions_ToID.Count; - return _ItemTransitions_ToID; - } - } - public void RefreshItemTransitions_ToID() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) - foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) - tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base ItemInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ItemInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemInfo - protected override object GetIdValue() - { - return _ItemID; - } - #endregion - #region Factory Methods - private static int _ItemInfoUnique = 0; - private static int ItemInfoUnique - { get { return ++_ItemInfoUnique; } } - private int _MyItemInfoUnique = ItemInfoUnique; - public int MyItemInfoUnique - { get { return _MyItemInfoUnique; } } - protected ItemInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) return; - List listItemInfo = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items - while (listItemInfo.Contains(this)) listItemInfo.Remove(this); // Remove the item from the list - if (listItemInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list - } - public virtual Item Get() - { - return _Editable = Item.Get(_ItemID); - } - public static void Refresh(Item tmp) - { - string key = tmp.ItemID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Item tmp) - { - if (_PreviousID != tmp.PreviousID) - { - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value - _PreviousID = tmp.PreviousID; // Update the value - } - _MyPrevious = null; // Reset list so that the next line gets a new list - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value - if (_ContentID != tmp.ContentID) - { - if (MyContent != null) MyContent.RefreshContentItems(); // 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.RefreshContentItems(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ItemInfoExtension.Refresh(this); - if(_MyPrevious != null) - { - _MyPrevious.Dispose();// Dispose related value - _MyPrevious = null;// Reset related value - } - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ContentItem tmp) - { - string key = tmp.ItemID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentItem tmp) - { - if (_PreviousID != tmp.PreviousID) - { - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value - _PreviousID = tmp.PreviousID; // Update the value - } - _MyPrevious = null; // Reset list so that the next line gets a new list - if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ItemInfoExtension.Refresh(this); - if(_MyPrevious != null) - { - _MyPrevious.Dispose();// Dispose related value - _MyPrevious = null;// Reset related value - } - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - OnChange();// raise an event - } - public static ItemInfo Get(int itemID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Item"); - try - { - ItemInfo tmp = GetCachedByPrimaryKey(itemID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(itemID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ItemInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ItemInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ItemInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.Constructor", ex); - throw new DbCslaException("ItemInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ItemID; - public int ItemID - { get { return _ItemID; } } - public PKCriteria(int itemID) - { - _ItemID = itemID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode()); - try - { - _ItemID = dr.GetInt32("ItemID"); - _PreviousID = (int?)dr.GetValue("PreviousID"); - _ContentID = dr.GetInt32("ContentID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); - _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); - _NextItemCount = dr.GetInt32("NextCount"); - _ItemPartCount = dr.GetInt32("PartCount"); - _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); - _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getItem"; - cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ItemInfoExtension _ItemInfoExtension = new ItemInfoExtension(); - [Serializable()] - partial class ItemInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ItemInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ItemInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemInfo) - { - // Return the ToString value - return ((ItemInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ItemInfoEvent(object sender); + /// + /// ItemInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemInfoConverter))] + public partial class ItemInfo : ReadOnlyBase, IDisposable + { + public event ItemInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ItemInfo itemInfo) + { + if (!_CacheList.Contains(itemInfo)) _CacheList.Add(itemInfo); // In AddToCache + } + protected static void RemoveFromCache(ItemInfo itemInfo) + { + while (_CacheList.Contains(itemInfo)) _CacheList.Remove(itemInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ItemInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ItemID.ToString())) + { + _CacheByPrimaryKey[tmp.ItemID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ItemID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ItemInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(ItemInfoList lst) + { + foreach (ItemInfo item in lst) AddToCache(item); + } + protected static ItemInfo GetCachedByPrimaryKey(int itemID) + { + ConvertListToDictionary(); + string key = itemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Item _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ItemID; + [System.ComponentModel.DataObjectField(true, true)] + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemID; + } + } + private int? _PreviousID; + public int? PreviousID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious != null) _PreviousID = _MyPrevious.ItemID; + return _PreviousID; + } + } + private ItemInfo _MyPrevious; + public ItemInfo MyPrevious + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPrevious == null && _PreviousID != null) _MyPrevious = ItemInfo.Get((int)_PreviousID); + return _MyPrevious; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ItemAnnotationCount = 0; + /// + /// Count of ItemAnnotations for this Item + /// + public int ItemAnnotationCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemAnnotationCount; + } + } + private AnnotationInfoList _ItemAnnotations = null; + [TypeConverter(typeof(AnnotationInfoListConverter))] + public AnnotationInfoList ItemAnnotations + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemAnnotationCount < 0 || (_ItemAnnotationCount > 0 && _ItemAnnotations == null)) + _ItemAnnotations = AnnotationInfoList.GetByItemID(_ItemID); + if (_ItemAnnotationCount < 0) + _ItemAnnotationCount = _ItemAnnotations.Count; + return _ItemAnnotations; + } + } + public void RefreshItemAnnotations() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemAnnotationCount = -1; // This will cause the data to be requeried + } + private int _ItemDocVersionCount = 0; + /// + /// Count of ItemDocVersions for this Item + /// + public int ItemDocVersionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemDocVersionCount; + } + } + private DocVersionInfoList _ItemDocVersions = null; + [TypeConverter(typeof(DocVersionInfoListConverter))] + public DocVersionInfoList ItemDocVersions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemDocVersionCount < 0 || (_ItemDocVersionCount > 0 && _ItemDocVersions == null)) + _ItemDocVersions = DocVersionInfoList.GetByItemID(_ItemID); + if (_ItemDocVersionCount < 0) + _ItemDocVersionCount = _ItemDocVersions.Count; + return _ItemDocVersions; + } + } + public void RefreshItemDocVersions() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemDocVersionCount = -1; // This will cause the data to be requeried + } + private int _NextItemCount = 0; + /// + /// Count of NextItems for this Item + /// + public int NextItemCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _NextItemCount; + } + } + private ItemInfoList _NextItems = null; + [TypeConverter(typeof(ItemInfoListConverter))] + public ItemInfoList NextItems + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_NextItemCount < 0 || (_NextItemCount > 0 && _NextItems == null)) + _NextItems = ItemInfoList.GetNext(_ItemID); + if (_NextItemCount < 0) + _NextItemCount = _NextItems.Count; + return _NextItems; + } + } + public void RefreshNextItems() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._NextItemCount = -1; // This will cause the data to be requeried + } + private int _ItemPartCount = 0; + /// + /// Count of ItemParts for this Item + /// + public int ItemPartCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemPartCount; + } + } + private PartInfoList _ItemParts = null; + [TypeConverter(typeof(PartInfoListConverter))] + public PartInfoList ItemParts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemPartCount < 0 || (_ItemPartCount > 0 && _ItemParts == null)) + _ItemParts = PartInfoList.GetByItemID(_ItemID); + if (_ItemPartCount < 0) + _ItemPartCount = _ItemParts.Count; + return _ItemParts; + } + } + public void RefreshItemParts() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemPartCount = -1; // This will cause the data to be requeried + } + private int _ItemTransition_RangeIDCount = 0; + /// + /// Count of ItemTransitions for this Item + /// + public int ItemTransition_RangeIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemTransition_RangeIDCount; + } + } + private TransitionInfoList _ItemTransitions_RangeID = null; + [TypeConverter(typeof(TransitionInfoListConverter))] + public TransitionInfoList ItemTransitions_RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_RangeIDCount < 0 || (_ItemTransition_RangeIDCount > 0 && _ItemTransitions_RangeID == null)) + _ItemTransitions_RangeID = TransitionInfoList.GetByRangeID(_ItemID); + if (_ItemTransition_RangeIDCount < 0) + _ItemTransition_RangeIDCount = _ItemTransitions_RangeID.Count; + return _ItemTransitions_RangeID; + } + } + public void RefreshItemTransitions_RangeID() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemTransition_RangeIDCount = -1; // This will cause the data to be requeried + } + private int _ItemTransition_ToIDCount = 0; + /// + /// Count of ItemTransitions for this Item + /// + public int ItemTransition_ToIDCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ItemTransition_ToIDCount; + } + } + private TransitionInfoList _ItemTransitions_ToID = null; + [TypeConverter(typeof(TransitionInfoListConverter))] + public TransitionInfoList ItemTransitions_ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ItemTransition_ToIDCount < 0 || (_ItemTransition_ToIDCount > 0 && _ItemTransitions_ToID == null)) + _ItemTransitions_ToID = TransitionInfoList.GetByToID(_ItemID); + if (_ItemTransition_ToIDCount < 0) + _ItemTransition_ToIDCount = _ItemTransitions_ToID.Count; + return _ItemTransitions_ToID; + } + } + public void RefreshItemTransitions_ToID() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ItemID.ToString())) + foreach (ItemInfo tmp in _CacheByPrimaryKey[_ItemID.ToString()]) + tmp._ItemTransition_ToIDCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base ItemInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ItemInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemInfo + protected override object GetIdValue() + { + return _ItemID; + } + #endregion + #region Factory Methods + private static int _ItemInfoUnique = 0; + private static int ItemInfoUnique + { get { return ++_ItemInfoUnique; } } + private int _MyItemInfoUnique = ItemInfoUnique; + public int MyItemInfoUnique + { get { return _MyItemInfoUnique; } } + protected ItemInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) return; + List listItemInfo = _CacheByPrimaryKey[ItemID.ToString()]; // Get the list of items + while (listItemInfo.Contains(this)) listItemInfo.Remove(this); // Remove the item from the list + if (listItemInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ItemID.ToString()); // remove the list + } + public virtual Item Get() + { + return _Editable = Item.Get(_ItemID); + } + public static void Refresh(Item tmp) + { + string key = tmp.ItemID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Item tmp) + { + if (_PreviousID != tmp.PreviousID) + { + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value + _PreviousID = tmp.PreviousID; // Update the value + } + _MyPrevious = null; // Reset list so that the next line gets a new list + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value + if (_ContentID != tmp.ContentID) + { + if (MyContent != null) MyContent.RefreshContentItems(); // 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.RefreshContentItems(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ItemInfoExtension.Refresh(this); + if (_MyPrevious != null) + { + _MyPrevious.Dispose();// Dispose related value + _MyPrevious = null;// Reset related value + } + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ContentItem tmp) + { + string key = tmp.ItemID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentItem tmp) + { + if (_PreviousID != tmp.PreviousID) + { + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value + _PreviousID = tmp.PreviousID; // Update the value + } + _MyPrevious = null; // Reset list so that the next line gets a new list + if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ItemInfoExtension.Refresh(this); + if (_MyPrevious != null) + { + _MyPrevious.Dispose();// Dispose related value + _MyPrevious = null;// Reset related value + } + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + OnChange();// raise an event + } + public static ItemInfo Get(int itemID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Item"); + try + { + ItemInfo tmp = GetCachedByPrimaryKey(itemID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(itemID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ItemInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ItemInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.Constructor", ex); + throw new DbCslaException("ItemInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ItemID; + public int ItemID + { get { return _ItemID; } } + public PKCriteria(int itemID) + { + _ItemID = itemID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.ReadData", GetHashCode()); + try + { + _ItemID = dr.GetInt32("ItemID"); + _PreviousID = (int?)dr.GetValue("PreviousID"); + _ContentID = dr.GetInt32("ContentID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _ItemAnnotationCount = dr.GetInt32("AnnotationCount"); + _ItemDocVersionCount = dr.GetInt32("DocVersionCount"); + _NextItemCount = dr.GetInt32("NextCount"); + _ItemPartCount = dr.GetInt32("PartCount"); + _ItemTransition_RangeIDCount = dr.GetInt32("Transition_RangeIDCount"); + _ItemTransition_ToIDCount = dr.GetInt32("Transition_ToIDCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getItem"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ItemInfoExtension _ItemInfoExtension = new ItemInfoExtension(); + [Serializable()] + partial class ItemInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ItemInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ItemInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemInfo) + { + // Return the ToString value + return ((ItemInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemPart.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemPart.cs index 29796097..f277ce4e 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemPart.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemPart.cs @@ -19,424 +19,410 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemPart Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemPartConverter))] - public partial class ItemPart : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // TODO: Check ItemPart.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemPart - protected override object GetIdValue() - { - return (((((_ContentID.ToString() + _FromType.ToString()).GetHashCode().ToString()).GetHashCode().ToString()).GetHashCode().ToString()).GetHashCode().ToString()).GetHashCode(); - } - // TODO: Replace base ItemPart.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemPart - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(FromType, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ItemPart New(Content myContent, int fromType) - { - return new ItemPart(myContent, fromType); - } - internal static ItemPart Get(SafeDataReader dr) - { - return new ItemPart(dr); - } - public ItemPart() - { - MarkAsChild(); + /// + /// ItemPart Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemPartConverter))] + public partial class ItemPart : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // TODO: Check ItemPart.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemPart + protected override object GetIdValue() + { + return (((((_ContentID.ToString() + _FromType.ToString()).GetHashCode().ToString()).GetHashCode().ToString()).GetHashCode().ToString()).GetHashCode().ToString()).GetHashCode(); + } + // TODO: Replace base ItemPart.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemPart + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(FromType, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ItemPart New(Content myContent, int fromType) + { + return new ItemPart(myContent, fromType); + } + internal static ItemPart Get(SafeDataReader dr) + { + return new ItemPart(dr); + } + public ItemPart() + { + MarkAsChild(); - _DTS = _ItemPartExtension.DefaultDTS; - _UserID = _ItemPartExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemPart(Content myContent, int fromType) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ItemPartExtension.DefaultDTS; - _UserID = _ItemPartExtension.DefaultUserID; - _MyContent = myContent; - _FromType = fromType; - ValidationRules.CheckRules(); - } - internal ItemPart(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemPart.FetchDR", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemPart.FetchDR", ex); - throw new DbCslaException("ItemPart.Fetch", ex); - } - MarkOld(); - } - 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 = Part.Add(cn, _MyContent, _FromType, myItem, _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 = Part.Update(cn, _MyContent, _FromType, myItem, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - 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"]; - Part.Remove(cn, _ContentID, _FromType); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemPartExtension _ItemPartExtension = new ItemPartExtension(); - [Serializable()] - partial class ItemPartExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemPartConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemPart) - { - // Return the ToString value - return ((ItemPart)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _ItemPartExtension.DefaultDTS; + _UserID = _ItemPartExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemPart(Content myContent, int fromType) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ItemPartExtension.DefaultDTS; + _UserID = _ItemPartExtension.DefaultUserID; + _MyContent = myContent; + _FromType = fromType; + ValidationRules.CheckRules(); + } + internal ItemPart(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemPart.FetchDR", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemPart.FetchDR", ex); + throw new DbCslaException("ItemPart.Fetch", ex); + } + MarkOld(); + } + 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 = Part.Add(cn, _MyContent, _FromType, myItem, _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 = Part.Update(cn, _MyContent, _FromType, myItem, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + 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"]; + Part.Remove(cn, _ContentID, _FromType); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemPartExtension _ItemPartExtension = new ItemPartExtension(); + [Serializable()] + partial class ItemPartExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemPartConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemPart) + { + // Return the ToString value + return ((ItemPart)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_RangeID.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_RangeID.cs index 3c3f50ea..77122eb3 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_RangeID.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_RangeID.cs @@ -19,559 +19,536 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemTransition_RangeID Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemTransition_RangeIDConverter))] - public partial class ItemTransition_RangeID : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - PropertyHasChanged(); - } - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private Item _MyItemToID; - public Item MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); - return _MyItemToID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemToID", true); - if (_MyItemToID != value) - { - _MyItemToID = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // TODO: Check ItemTransition_RangeID.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemTransition_RangeID - protected override object GetIdValue() - { - return _TransitionID; - } - // TODO: Replace base ItemTransition_RangeID.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemTransition_RangeID - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyContentRequired(ItemTransition_RangeID target, Csla.Validation.RuleArgs e) - { - if (target._FromID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(TransitionID, ""); - //AuthorizationRules.AllowRead(FromID, ""); - //AuthorizationRules.AllowWrite(FromID, ""); - //AuthorizationRules.AllowRead(ToID, ""); - //AuthorizationRules.AllowWrite(ToID, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ItemTransition_RangeID New(Content myContent, Item myItemToID) - { - return new ItemTransition_RangeID(myContent, myItemToID); - } - internal static ItemTransition_RangeID Get(SafeDataReader dr) - { - return new ItemTransition_RangeID(dr); - } - public ItemTransition_RangeID() - { - MarkAsChild(); - _TransitionID = Transition.NextTransitionID; - _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; - _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; - _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemTransition_RangeID(Content myContent, Item myItemToID) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; - _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; - _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; - _MyContent = myContent; - _MyItemToID = myItemToID; - ValidationRules.CheckRules(); - } - internal ItemTransition_RangeID(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_RangeID.FetchDR", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _ToID = dr.GetInt32("ToID"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_RangeID.FetchDR", ex); - throw new DbCslaException("ItemTransition_RangeID.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Item myItemRangeID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _TranType, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Item myItemRangeID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Update(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Item myItemRangeID) - { - // 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"]; - Transition.Remove(cn, _TransitionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemTransition_RangeIDExtension _ItemTransition_RangeIDExtension = new ItemTransition_RangeIDExtension(); - [Serializable()] - partial class ItemTransition_RangeIDExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemTransition_RangeIDConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemTransition_RangeID) - { - // Return the ToString value - return ((ItemTransition_RangeID)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemTransition_RangeID Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemTransition_RangeIDConverter))] + public partial class ItemTransition_RangeID : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + PropertyHasChanged(); + } + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private Item _MyItemToID; + public Item MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); + return _MyItemToID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemToID != value) + { + _MyItemToID = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // TODO: Check ItemTransition_RangeID.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemTransition_RangeID + protected override object GetIdValue() + { + return _TransitionID; + } + // TODO: Replace base ItemTransition_RangeID.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemTransition_RangeID + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyContentRequired(ItemTransition_RangeID target, Csla.Validation.RuleArgs e) + { + if (target._FromID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(TransitionID, ""); + //AuthorizationRules.AllowRead(FromID, ""); + //AuthorizationRules.AllowWrite(FromID, ""); + //AuthorizationRules.AllowRead(ToID, ""); + //AuthorizationRules.AllowWrite(ToID, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ItemTransition_RangeID New(Content myContent, Item myItemToID) + { + return new ItemTransition_RangeID(myContent, myItemToID); + } + internal static ItemTransition_RangeID Get(SafeDataReader dr) + { + return new ItemTransition_RangeID(dr); + } + public ItemTransition_RangeID() + { + MarkAsChild(); + _TransitionID = Transition.NextTransitionID; + _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; + _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; + _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemTransition_RangeID(Content myContent, Item myItemToID) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _TranType = _ItemTransition_RangeIDExtension.DefaultTranType; + _DTS = _ItemTransition_RangeIDExtension.DefaultDTS; + _UserID = _ItemTransition_RangeIDExtension.DefaultUserID; + _MyContent = myContent; + _MyItemToID = myItemToID; + ValidationRules.CheckRules(); + } + internal ItemTransition_RangeID(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_RangeID.FetchDR", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _ToID = dr.GetInt32("ToID"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_RangeID.FetchDR", ex); + throw new DbCslaException("ItemTransition_RangeID.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Item myItemRangeID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _TranType, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Item myItemRangeID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Update(cn, ref _TransitionID, _MyContent, _MyItemToID, myItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Item myItemRangeID) + { + // 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"]; + Transition.Remove(cn, _TransitionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemTransition_RangeIDExtension _ItemTransition_RangeIDExtension = new ItemTransition_RangeIDExtension(); + [Serializable()] + partial class ItemTransition_RangeIDExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemTransition_RangeIDConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemTransition_RangeID) + { + // Return the ToString value + return ((ItemTransition_RangeID)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_ToID.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_ToID.cs index 2079bfd4..c2dddb61 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_ToID.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ItemTransition_ToID.cs @@ -19,556 +19,533 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ItemTransition_ToID Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ItemTransition_ToIDConverter))] - public partial class ItemTransition_ToID : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - PropertyHasChanged(); - } - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private Item _MyItemRangeID; - public Item MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); - return _MyItemRangeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemRangeID", true); - if (_MyItemRangeID != value) - { - _MyItemRangeID = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // TODO: Check ItemTransition_ToID.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ItemTransition_ToID - protected override object GetIdValue() - { - return _TransitionID; - } - // TODO: Replace base ItemTransition_ToID.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ItemTransition_ToID - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyContentRequired(ItemTransition_ToID target, Csla.Validation.RuleArgs e) - { - if (target._FromID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(TransitionID, ""); - //AuthorizationRules.AllowRead(FromID, ""); - //AuthorizationRules.AllowWrite(FromID, ""); - //AuthorizationRules.AllowRead(RangeID, ""); - //AuthorizationRules.AllowWrite(RangeID, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ItemTransition_ToID New(Content myContent, Item myItemRangeID) - { - return new ItemTransition_ToID(myContent, myItemRangeID); - } - internal static ItemTransition_ToID Get(SafeDataReader dr) - { - return new ItemTransition_ToID(dr); - } - public ItemTransition_ToID() - { - MarkAsChild(); - _TransitionID = Transition.NextTransitionID; - _TranType = _ItemTransition_ToIDExtension.DefaultTranType; - _DTS = _ItemTransition_ToIDExtension.DefaultDTS; - _UserID = _ItemTransition_ToIDExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ItemTransition_ToID(Content myContent, Item myItemRangeID) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _TranType = _ItemTransition_ToIDExtension.DefaultTranType; - _DTS = _ItemTransition_ToIDExtension.DefaultDTS; - _UserID = _ItemTransition_ToIDExtension.DefaultUserID; - _MyContent = myContent; - _MyItemRangeID = myItemRangeID; - ValidationRules.CheckRules(); - } - internal ItemTransition_ToID(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_ToID.FetchDR", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _RangeID = dr.GetInt32("RangeID"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_ToID.FetchDR", ex); - throw new DbCslaException("ItemTransition_ToID.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Item myItemToID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID); - MarkOld(); - } - internal void Update(Item myItemToID) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Transition.Update(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Item myItemToID) - { - // 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"]; - Transition.Remove(cn, _TransitionID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ItemTransition_ToIDExtension _ItemTransition_ToIDExtension = new ItemTransition_ToIDExtension(); - [Serializable()] - partial class ItemTransition_ToIDExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ItemTransition_ToIDConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ItemTransition_ToID) - { - // Return the ToString value - return ((ItemTransition_ToID)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ItemTransition_ToID Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ItemTransition_ToIDConverter))] + public partial class ItemTransition_ToID : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + PropertyHasChanged(); + } + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private Item _MyItemRangeID; + public Item MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); + return _MyItemRangeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemRangeID != value) + { + _MyItemRangeID = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // TODO: Check ItemTransition_ToID.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ItemTransition_ToID + protected override object GetIdValue() + { + return _TransitionID; + } + // TODO: Replace base ItemTransition_ToID.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ItemTransition_ToID + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyContentRequired(ItemTransition_ToID target, Csla.Validation.RuleArgs e) + { + if (target._FromID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(TransitionID, ""); + //AuthorizationRules.AllowRead(FromID, ""); + //AuthorizationRules.AllowWrite(FromID, ""); + //AuthorizationRules.AllowRead(RangeID, ""); + //AuthorizationRules.AllowWrite(RangeID, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ItemTransition_ToID New(Content myContent, Item myItemRangeID) + { + return new ItemTransition_ToID(myContent, myItemRangeID); + } + internal static ItemTransition_ToID Get(SafeDataReader dr) + { + return new ItemTransition_ToID(dr); + } + public ItemTransition_ToID() + { + MarkAsChild(); + _TransitionID = Transition.NextTransitionID; + _TranType = _ItemTransition_ToIDExtension.DefaultTranType; + _DTS = _ItemTransition_ToIDExtension.DefaultDTS; + _UserID = _ItemTransition_ToIDExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ItemTransition_ToID(Content myContent, Item myItemRangeID) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _TranType = _ItemTransition_ToIDExtension.DefaultTranType; + _DTS = _ItemTransition_ToIDExtension.DefaultDTS; + _UserID = _ItemTransition_ToIDExtension.DefaultUserID; + _MyContent = myContent; + _MyItemRangeID = myItemRangeID; + ValidationRules.CheckRules(); + } + internal ItemTransition_ToID(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemTransition_ToID.FetchDR", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _RangeID = dr.GetInt32("RangeID"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemTransition_ToID.FetchDR", ex); + throw new DbCslaException("ItemTransition_ToID.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Item myItemToID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID); + MarkOld(); + } + internal void Update(Item myItemToID) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Transition.Update(cn, ref _TransitionID, _MyContent, myItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Item myItemToID) + { + // 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"]; + Transition.Remove(cn, _TransitionID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ItemTransition_ToIDExtension _ItemTransition_ToIDExtension = new ItemTransition_ToIDExtension(); + [Serializable()] + partial class ItemTransition_ToIDExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ItemTransition_ToIDConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ItemTransition_ToID) + { + // Return the ToString value + return ((ItemTransition_ToID)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Membership.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Membership.cs index c5fe3e86..039c31a5 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Membership.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Membership.cs @@ -20,1125 +20,1108 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Membership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(MembershipConverter))] - public partial class Membership : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshMemberships = new List(); - private void AddToRefreshList(List refreshMemberships) - { - if (IsDirty) - refreshMemberships.Add(this); - } - private void BuildRefreshList() - { - _RefreshMemberships = new List(); - AddToRefreshList(_RefreshMemberships); - } - private void ProcessRefreshList() - { - foreach (Membership tmp in _RefreshMemberships) - { - MembershipInfo.Refresh(tmp); - if (tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup); - if (tmp._MyUser != null) UserInfo.Refresh(tmp._MyUser); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Membership membership) - { - if (!_CacheList.Contains(membership)) _CacheList.Add(membership); // In AddToCache - } - protected static void RemoveFromCache(Membership membership) - { - while (_CacheList.Contains(membership)) _CacheList.Remove(membership); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Membership tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString())) - { - _CacheByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Membership tmp in remove) - RemoveFromCache(tmp); - } - protected static Membership GetCachedByPrimaryKey(int ugid) - { - ConvertListToDictionary(); - string key = ugid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextUGID = -1; - public static int NextUGID - { - get { return _nextUGID--; } - } - private int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - return _UGID; - } - } - private int _UID; - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - if (_MyUser != null) _UID = _MyUser.UID; - return _UID; - } - } - private User _MyUser; - public User MyUser - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyUser", true); - if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); - return _MyUser; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyUser", true); - if (_MyUser != value) - { - _MyUser = value; - PropertyHasChanged(); - } - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyUser == null ? false : _MyUser.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyUser == null ? true : _MyUser.IsValid); } - } - // TODO: Replace base Membership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Membership - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Membership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Membership - protected override object GetIdValue() - { - return _UGID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyUserRequired, "MyUser"); - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _MembershipExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _MembershipExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool StartDateValid(Membership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(Membership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyUserRequired(Membership target, Csla.Validation.RuleArgs e) - { - if (target._UID == 0 && target._MyUser == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyGroupRequired(Membership target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(UGID, ""); - //AuthorizationRules.AllowRead(UID, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _MembershipExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _MembershipExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _MembershipUnique = 0; - protected static int MembershipUnique - { get { return ++_MembershipUnique; } } - private int _MyMembershipUnique = MembershipUnique; - public int MyMembershipUnique - { get { return _MyMembershipUnique; } } - protected Membership() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(UGID.ToString())) - { - List listMembership = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items - while (listMembership.Contains(this)) listMembership.Remove(this); // Remove the item from the list - if (listMembership.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list - } - } - public static Membership New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Membership"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.New", ex); - } - } - public static Membership New(User myUser, Group myGroup) - { - Membership tmp = Membership.New(); - tmp.MyUser = myUser; - tmp.MyGroup = myGroup; - return tmp; - } - public static Membership New(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Membership tmp = Membership.New(); - tmp.MyUser = myUser; - tmp.MyGroup = myGroup; - tmp.StartDate = startDate; - tmp.EndDate = endDate; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Membership MakeMembership(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID); - if (tmp.IsSavable) - { - Membership tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Membership New(User myUser, Group myGroup, string endDate, string config) - { - Membership tmp = Membership.New(); - tmp.MyUser = myUser; - tmp.MyGroup = myGroup; - tmp.EndDate = endDate; - tmp.Config = config; - return tmp; - } - public static Membership MakeMembership(User myUser, Group myGroup, string endDate, string config) - { - Membership tmp = Membership.New(myUser, myGroup, endDate, config); - if (tmp.IsSavable) - { - Membership tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Membership Get(int ugid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Membership"); - try - { - Membership tmp = GetCachedByPrimaryKey(ugid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ugid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Membership - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.Get", ex); - } - } - public static Membership Get(SafeDataReader dr) - { - if (dr.Read()) return new Membership(dr); - return null; - } - internal Membership(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int ugid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Membership"); - try - { - DataPortal.Delete(new PKCriteria(ugid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.Delete", ex); - } - } - public override Membership Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Membership"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Membership"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Membership"); - try - { - BuildRefreshList(); - Membership membership = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(membership);//Refresh the item in AllList - ProcessRefreshList(); - return membership; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _UGID; - public int UGID - { get { return _UGID; } } - public PKCriteria(int ugid) - { - _UGID = ugid; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _UGID = NextUGID; - // Database Defaults - _StartDate = _MembershipExtension.DefaultStartDate; - _DTS = _MembershipExtension.DefaultDTS; - _UsrID = _MembershipExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.ReadData", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _UID = dr.GetInt32("UID"); - _GID = dr.GetInt32("GID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getMembership"; - cm.Parameters.AddWithValue("@UGID", criteria.UGID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyGroup != null) _MyGroup.Update(); - if (_MyUser != null) _MyUser.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addMembership"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UID", UID); - cm.Parameters.AddWithValue("@GID", GID); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); - param_UGID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UGID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _UGID = (int)cm.Parameters["@newUGID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addMembership"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UID", myUser.UID); - cm.Parameters.AddWithValue("@GID", myGroup.GID); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); - param_UGID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UGID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - ugid = (int)cm.Parameters["@newUGID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Add", ex); - throw new DbCslaException("Membership.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Membership.SQLUpdate", GetHashCode()); - try - { - if (_MyGroup != null) _MyGroup.Update(); - if (_MyUser != null) _MyUser.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateMembership"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@UGID", _UGID); - cm.Parameters.AddWithValue("@UID", UID); - cm.Parameters.AddWithValue("@GID", GID); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Membership.Add(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); - else - _LastChanged = Membership.Update(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateMembership"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UGID", ugid); - cm.Parameters.AddWithValue("@UID", myUser.UID); - cm.Parameters.AddWithValue("@GID", myGroup.GID); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Update", ex); - throw new DbCslaException("Membership.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_UGID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteMembership"; - cm.Parameters.AddWithValue("@UGID", criteria.UGID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Membership.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int ugid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteMembership"; - // Input PK Fields - cm.Parameters.AddWithValue("@UGID", ugid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Remove", ex); - throw new DbCslaException("Membership.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int ugid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(ugid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Membership.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _UGID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int ugid) - { - _UGID = ugid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsMembership"; - cm.Parameters.AddWithValue("@UGID", _UGID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Execute", ex); - throw new DbCslaException("Membership.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - MembershipExtension _MembershipExtension = new MembershipExtension(); - [Serializable()] - partial class MembershipExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class MembershipConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Membership) - { - // Return the ToString value - return ((Membership)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Membership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(MembershipConverter))] + public partial class Membership : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshMemberships = new List(); + private void AddToRefreshList(List refreshMemberships) + { + if (IsDirty) + refreshMemberships.Add(this); + } + private void BuildRefreshList() + { + _RefreshMemberships = new List(); + AddToRefreshList(_RefreshMemberships); + } + private void ProcessRefreshList() + { + foreach (Membership tmp in _RefreshMemberships) + { + MembershipInfo.Refresh(tmp); + if (tmp._MyGroup != null) GroupInfo.Refresh(tmp._MyGroup); + if (tmp._MyUser != null) UserInfo.Refresh(tmp._MyUser); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Membership membership) + { + if (!_CacheList.Contains(membership)) _CacheList.Add(membership); // In AddToCache + } + protected static void RemoveFromCache(Membership membership) + { + while (_CacheList.Contains(membership)) _CacheList.Remove(membership); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Membership tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString())) + { + _CacheByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Membership tmp in remove) + RemoveFromCache(tmp); + } + protected static Membership GetCachedByPrimaryKey(int ugid) + { + ConvertListToDictionary(); + string key = ugid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextUGID = -1; + public static int NextUGID + { + get { return _nextUGID--; } + } + private int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UGID; + } + } + private int _UID; + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser != null) _UID = _MyUser.UID; + return _UID; + } + } + private User _MyUser; + public User MyUser + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser == null && _UID != 0) _MyUser = User.Get(_UID); + return _MyUser; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyUser != value) + { + _MyUser = value; + PropertyHasChanged(); + } + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyUser == null ? false : _MyUser.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyUser == null ? true : _MyUser.IsValid); } + } + // TODO: Replace base Membership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Membership + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Membership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Membership + protected override object GetIdValue() + { + return _UGID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyUser != null && (hasBrokenRules = _MyUser.HasBrokenRules) != null) return hasBrokenRules; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyUserRequired, "MyUser"); + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _MembershipExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _MembershipExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool StartDateValid(Membership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(Membership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyUserRequired(Membership target, Csla.Validation.RuleArgs e) + { + if (target._UID == 0 && target._MyUser == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyGroupRequired(Membership target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(UGID, ""); + //AuthorizationRules.AllowRead(UID, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _MembershipExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _MembershipExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _MembershipUnique = 0; + protected static int MembershipUnique + { get { return ++_MembershipUnique; } } + private int _MyMembershipUnique = MembershipUnique; + public int MyMembershipUnique + { get { return _MyMembershipUnique; } } + protected Membership() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(UGID.ToString())) + { + List listMembership = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items + while (listMembership.Contains(this)) listMembership.Remove(this); // Remove the item from the list + if (listMembership.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list + } + } + public static Membership New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Membership"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.New", ex); + } + } + public static Membership New(User myUser, Group myGroup) + { + Membership tmp = Membership.New(); + tmp.MyUser = myUser; + tmp.MyGroup = myGroup; + return tmp; + } + public static Membership New(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Membership tmp = Membership.New(); + tmp.MyUser = myUser; + tmp.MyGroup = myGroup; + tmp.StartDate = startDate; + tmp.EndDate = endDate; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Membership MakeMembership(User myUser, Group myGroup, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Membership tmp = Membership.New(myUser, myGroup, startDate, endDate, config, dts, usrID); + if (tmp.IsSavable) + { + Membership tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Membership New(User myUser, Group myGroup, string endDate, string config) + { + Membership tmp = Membership.New(); + tmp.MyUser = myUser; + tmp.MyGroup = myGroup; + tmp.EndDate = endDate; + tmp.Config = config; + return tmp; + } + public static Membership MakeMembership(User myUser, Group myGroup, string endDate, string config) + { + Membership tmp = Membership.New(myUser, myGroup, endDate, config); + if (tmp.IsSavable) + { + Membership tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Membership Get(int ugid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Membership"); + try + { + Membership tmp = GetCachedByPrimaryKey(ugid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ugid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Membership + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.Get", ex); + } + } + public static Membership Get(SafeDataReader dr) + { + if (dr.Read()) return new Membership(dr); + return null; + } + internal Membership(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int ugid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Membership"); + try + { + DataPortal.Delete(new PKCriteria(ugid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.Delete", ex); + } + } + public override Membership Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Membership"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Membership"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Membership"); + try + { + BuildRefreshList(); + Membership membership = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(membership);//Refresh the item in AllList + ProcessRefreshList(); + return membership; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _UGID; + public int UGID + { get { return _UGID; } } + public PKCriteria(int ugid) + { + _UGID = ugid; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _UGID = NextUGID; + // Database Defaults + _StartDate = _MembershipExtension.DefaultStartDate; + _DTS = _MembershipExtension.DefaultDTS; + _UsrID = _MembershipExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.ReadData", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _UID = dr.GetInt32("UID"); + _GID = dr.GetInt32("GID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembership"; + cm.Parameters.AddWithValue("@UGID", criteria.UGID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyGroup != null) _MyGroup.Update(); + if (_MyUser != null) _MyUser.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addMembership"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UID", UID); + cm.Parameters.AddWithValue("@GID", GID); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); + param_UGID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UGID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _UGID = (int)cm.Parameters["@newUGID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addMembership"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UID", myUser.UID); + cm.Parameters.AddWithValue("@GID", myGroup.GID); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + 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_UGID = new SqlParameter("@newUGID", SqlDbType.Int); + param_UGID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UGID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + ugid = (int)cm.Parameters["@newUGID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Add", ex); + throw new DbCslaException("Membership.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Membership.SQLUpdate", GetHashCode()); + try + { + if (_MyGroup != null) _MyGroup.Update(); + if (_MyUser != null) _MyUser.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateMembership"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@UGID", _UGID); + cm.Parameters.AddWithValue("@UID", UID); + cm.Parameters.AddWithValue("@GID", GID); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Membership.Add(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); + else + _LastChanged = Membership.Update(cn, ref _UGID, _MyUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int ugid, User myUser, Group myGroup, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateMembership"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UGID", ugid); + cm.Parameters.AddWithValue("@UID", myUser.UID); + cm.Parameters.AddWithValue("@GID", myGroup.GID); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Update", ex); + throw new DbCslaException("Membership.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_UGID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteMembership"; + cm.Parameters.AddWithValue("@UGID", criteria.UGID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Membership.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int ugid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteMembership"; + // Input PK Fields + cm.Parameters.AddWithValue("@UGID", ugid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.Remove", ex); + throw new DbCslaException("Membership.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int ugid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(ugid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Membership.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _UGID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int ugid) + { + _UGID = ugid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Membership.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsMembership"; + cm.Parameters.AddWithValue("@UGID", _UGID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Membership.DataPortal_Execute", ex); + throw new DbCslaException("Membership.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + MembershipExtension _MembershipExtension = new MembershipExtension(); + [Serializable()] + partial class MembershipExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class MembershipConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Membership) + { + // Return the ToString value + return ((Membership)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/MembershipInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/MembershipInfo.cs index 864545b4..7139e7ac 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/MembershipInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/MembershipInfo.cs @@ -19,469 +19,459 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void MembershipInfoEvent(object sender); - /// - /// MembershipInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(MembershipInfoConverter))] - public partial class MembershipInfo : ReadOnlyBase, IDisposable - { - public event MembershipInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(MembershipInfo membershipInfo) - { - if (!_CacheList.Contains(membershipInfo)) _CacheList.Add(membershipInfo); // In AddToCache - } - protected static void RemoveFromCache(MembershipInfo membershipInfo) - { - while (_CacheList.Contains(membershipInfo)) _CacheList.Remove(membershipInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (MembershipInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString())) - { - _CacheByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (MembershipInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(MembershipInfoList lst) - { - foreach (MembershipInfo item in lst) AddToCache(item); - } - protected static MembershipInfo GetCachedByPrimaryKey(int ugid) - { - ConvertListToDictionary(); - string key = ugid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Membership _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - return _UGID; - } - } - private int _UID; - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - if (_MyUser != null) _UID = _MyUser.UID; - return _UID; - } - } - private UserInfo _MyUser; - public UserInfo MyUser - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyUser", true); - if (_MyUser == null && _UID != 0) _MyUser = UserInfo.Get(_UID); - return _MyUser; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private GroupInfo _MyGroup; - public GroupInfo MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); - return _MyGroup; - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - // TODO: Replace base MembershipInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current MembershipInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check MembershipInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current MembershipInfo - protected override object GetIdValue() - { - return _UGID; - } - #endregion - #region Factory Methods - private static int _MembershipInfoUnique = 0; - private static int MembershipInfoUnique - { get { return ++_MembershipInfoUnique; } } - private int _MyMembershipInfoUnique = MembershipInfoUnique; - public int MyMembershipInfoUnique - { get { return _MyMembershipInfoUnique; } } - protected MembershipInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(UGID.ToString())) return; - List listMembershipInfo = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items - while (listMembershipInfo.Contains(this)) listMembershipInfo.Remove(this); // Remove the item from the list - if (listMembershipInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list - } - public virtual Membership Get() - { - return _Editable = Membership.Get(_UGID); - } - public static void Refresh(Membership tmp) - { - string key = tmp.UGID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Membership tmp) - { - if (_UID != tmp.UID) - { - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value - _UID = tmp.UID; // Update the value - } - _MyUser = null; // Reset list so that the next line gets a new list - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _MembershipInfoExtension.Refresh(this); - if(_MyUser != null) - { - _MyUser.Dispose();// Dispose related value - _MyUser = null;// Reset related value - } - if(_MyGroup != null) - { - _MyGroup.Dispose();// Dispose related value - _MyGroup = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(GroupMembership tmp) - { - string key = tmp.UGID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(GroupMembership tmp) - { - if (_UID != tmp.UID) - { - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value - _UID = tmp.UID; // Update the value - } - _MyUser = null; // Reset list so that the next line gets a new list - if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _MembershipInfoExtension.Refresh(this); - if(_MyUser != null) - { - _MyUser.Dispose();// Dispose related value - _MyUser = null;// Reset related value - } - if(_MyGroup != null) - { - _MyGroup.Dispose();// Dispose related value - _MyGroup = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(UserMembership tmp) - { - string key = tmp.UGID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(UserMembership tmp) - { - if (_GID != tmp.GID) - { - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value - _GID = tmp.GID; // Update the value - } - _MyGroup = null; // Reset list so that the next line gets a new list - if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _MembershipInfoExtension.Refresh(this); - if(_MyUser != null) - { - _MyUser.Dispose();// Dispose related value - _MyUser = null;// Reset related value - } - if(_MyGroup != null) - { - _MyGroup.Dispose();// Dispose related value - _MyGroup = null;// Reset related value - } - OnChange();// raise an event - } - public static MembershipInfo Get(int ugid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Membership"); - try - { - MembershipInfo tmp = GetCachedByPrimaryKey(ugid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(ugid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up MembershipInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on MembershipInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal MembershipInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.Constructor", ex); - throw new DbCslaException("MembershipInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _UGID; - public int UGID - { get { return _UGID; } } - public PKCriteria(int ugid) - { - _UGID = ugid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.ReadData", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _UID = dr.GetInt32("UID"); - _GID = dr.GetInt32("GID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("MembershipInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getMembership"; - cm.Parameters.AddWithValue("@UGID", criteria.UGID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("MembershipInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - MembershipInfoExtension _MembershipInfoExtension = new MembershipInfoExtension(); - [Serializable()] - partial class MembershipInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(MembershipInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class MembershipInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is MembershipInfo) - { - // Return the ToString value - return ((MembershipInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void MembershipInfoEvent(object sender); + /// + /// MembershipInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(MembershipInfoConverter))] + public partial class MembershipInfo : ReadOnlyBase, IDisposable + { + public event MembershipInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(MembershipInfo membershipInfo) + { + if (!_CacheList.Contains(membershipInfo)) _CacheList.Add(membershipInfo); // In AddToCache + } + protected static void RemoveFromCache(MembershipInfo membershipInfo) + { + while (_CacheList.Contains(membershipInfo)) _CacheList.Remove(membershipInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (MembershipInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.UGID.ToString())) + { + _CacheByPrimaryKey[tmp.UGID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.UGID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (MembershipInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(MembershipInfoList lst) + { + foreach (MembershipInfo item in lst) AddToCache(item); + } + protected static MembershipInfo GetCachedByPrimaryKey(int ugid) + { + ConvertListToDictionary(); + string key = ugid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Membership _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UGID; + } + } + private int _UID; + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser != null) _UID = _MyUser.UID; + return _UID; + } + } + private UserInfo _MyUser; + public UserInfo MyUser + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyUser == null && _UID != 0) _MyUser = UserInfo.Get(_UID); + return _MyUser; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private GroupInfo _MyGroup; + public GroupInfo MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = GroupInfo.Get(_GID); + return _MyGroup; + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + // TODO: Replace base MembershipInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current MembershipInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check MembershipInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current MembershipInfo + protected override object GetIdValue() + { + return _UGID; + } + #endregion + #region Factory Methods + private static int _MembershipInfoUnique = 0; + private static int MembershipInfoUnique + { get { return ++_MembershipInfoUnique; } } + private int _MyMembershipInfoUnique = MembershipInfoUnique; + public int MyMembershipInfoUnique + { get { return _MyMembershipInfoUnique; } } + protected MembershipInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(UGID.ToString())) return; + List listMembershipInfo = _CacheByPrimaryKey[UGID.ToString()]; // Get the list of items + while (listMembershipInfo.Contains(this)) listMembershipInfo.Remove(this); // Remove the item from the list + if (listMembershipInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(UGID.ToString()); // remove the list + } + public virtual Membership Get() + { + return _Editable = Membership.Get(_UGID); + } + public static void Refresh(Membership tmp) + { + string key = tmp.UGID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Membership tmp) + { + if (_UID != tmp.UID) + { + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value + _UID = tmp.UID; // Update the value + } + _MyUser = null; // Reset list so that the next line gets a new list + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + if (_MyUser != null) + { + _MyUser.Dispose();// Dispose related value + _MyUser = null;// Reset related value + } + if (_MyGroup != null) + { + _MyGroup.Dispose();// Dispose related value + _MyGroup = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(GroupMembership tmp) + { + string key = tmp.UGID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(GroupMembership tmp) + { + if (_UID != tmp.UID) + { + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for old value + _UID = tmp.UID; // Update the value + } + _MyUser = null; // Reset list so that the next line gets a new list + if (MyUser != null) MyUser.RefreshUserMemberships(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + if (_MyUser != null) + { + _MyUser.Dispose();// Dispose related value + _MyUser = null;// Reset related value + } + if (_MyGroup != null) + { + _MyGroup.Dispose();// Dispose related value + _MyGroup = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(UserMembership tmp) + { + string key = tmp.UGID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (MembershipInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(UserMembership tmp) + { + if (_GID != tmp.GID) + { + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for old value + _GID = tmp.GID; // Update the value + } + _MyGroup = null; // Reset list so that the next line gets a new list + if (MyGroup != null) MyGroup.RefreshGroupMemberships(); // Update List for new value + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _MembershipInfoExtension.Refresh(this); + if (_MyUser != null) + { + _MyUser.Dispose();// Dispose related value + _MyUser = null;// Reset related value + } + if (_MyGroup != null) + { + _MyGroup.Dispose();// Dispose related value + _MyGroup = null;// Reset related value + } + OnChange();// raise an event + } + public static MembershipInfo Get(int ugid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Membership"); + try + { + MembershipInfo tmp = GetCachedByPrimaryKey(ugid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(ugid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up MembershipInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on MembershipInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal MembershipInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.Constructor", ex); + throw new DbCslaException("MembershipInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _UGID; + public int UGID + { get { return _UGID; } } + public PKCriteria(int ugid) + { + _UGID = ugid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.ReadData", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _UID = dr.GetInt32("UID"); + _GID = dr.GetInt32("GID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("MembershipInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] MembershipInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembership"; + cm.Parameters.AddWithValue("@UGID", criteria.UGID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("MembershipInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("MembershipInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + MembershipInfoExtension _MembershipInfoExtension = new MembershipInfoExtension(); + [Serializable()] + partial class MembershipInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(MembershipInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class MembershipInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is MembershipInfo) + { + // Return the ToString value + return ((MembershipInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Part.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Part.cs index 01303193..c687501f 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Part.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Part.cs @@ -20,954 +20,944 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Part Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PartConverter))] - public partial class Part : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshParts = new List(); - private void AddToRefreshList(List refreshParts) - { - if (IsDirty) - refreshParts.Add(this); - } - private void BuildRefreshList() - { - _RefreshParts = new List(); - AddToRefreshList(_RefreshParts); - } - private void ProcessRefreshList() - { - foreach (Part tmp in _RefreshParts) - { - PartInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Part part) - { - if (!_CacheList.Contains(part)) _CacheList.Add(part); // In AddToCache - } - protected static void RemoveFromCache(Part part) - { - while (_CacheList.Contains(part)) _CacheList.Remove(part); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Part tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Part tmp in remove) - RemoveFromCache(tmp); - } - protected static Part GetCachedByPrimaryKey(int contentID, int fromType) - { - ConvertListToDictionary(); - string key = contentID.ToString() + "_" + fromType.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private Item _MyItem; - public Item MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); - return _MyItem; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItem", true); - if (_MyItem != value) - { - _MyItem = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } - } - // TODO: Replace base Part.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Part - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Part.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Part - protected override object GetIdValue() - { - return (_ContentID.ToString() + "." + _FromType.ToString()).GetHashCode(); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyItemRequired, "MyItem"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _PartExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _PartExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyItemRequired(Part target, Csla.Validation.RuleArgs e) - { - if (target._ItemID == 0 && target._MyItem == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(FromType, ""); - //AuthorizationRules.AllowRead(ItemID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ItemID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _PartExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _PartExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _PartUnique = 0; - protected static int PartUnique - { get { return ++_PartUnique; } } - private int _MyPartUnique = PartUnique; - public int MyPartUnique - { get { return _MyPartUnique; } } - protected Part() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) - { - List listPart = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items - while (listPart.Contains(this)) listPart.Remove(this); // Remove the item from the list - if (listPart.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list - } - } - public static Part New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Part"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.New", ex); - } - } - public static Part New(Content myContent, int fromType, Item myItem) - { - Part tmp = Part.New(); - tmp._MyContent = myContent; - tmp._FromType = fromType; - tmp.MyItem = myItem; - return tmp; - } - public static Part MakePart(Content myContent, int fromType, Item myItem) - { - Part tmp = Part.New(myContent, fromType, myItem); - if (tmp.IsSavable) - { - Part tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Part New(Content myContent, int fromType, Item myItem, DateTime dts, string userID) - { - Part tmp = Part.New(); - tmp._MyContent = myContent; - tmp._FromType = fromType; - tmp.MyItem = myItem; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Part MakePart(Content myContent, int fromType, Item myItem, DateTime dts, string userID) - { - Part tmp = Part.New(myContent, fromType, myItem, dts, userID); - if (tmp.IsSavable) - { - Part tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Part Get(int contentID, int fromType) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Part"); - try - { - Part tmp = GetCachedByPrimaryKey(contentID, fromType); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Part - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.Get", ex); - } - } - public static Part Get(SafeDataReader dr) - { - if (dr.Read()) return new Part(dr); - return null; - } - internal Part(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int contentID, int fromType) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Part"); - try - { - DataPortal.Delete(new PKCriteria(contentID, fromType)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.Delete", ex); - } - } - public override Part Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Part"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Part"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Part"); - try - { - BuildRefreshList(); - Part part = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(part);//Refresh the item in AllList - ProcessRefreshList(); - return part; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - private int _FromType; - public int FromType - { get { return _FromType; } } - public PKCriteria(int contentID, int fromType) - { - _ContentID = contentID; - _FromType = fromType; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// Part Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartConverter))] + public partial class Part : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshParts = new List(); + private void AddToRefreshList(List refreshParts) + { + if (IsDirty) + refreshParts.Add(this); + } + private void BuildRefreshList() + { + _RefreshParts = new List(); + AddToRefreshList(_RefreshParts); + } + private void ProcessRefreshList() + { + foreach (Part tmp in _RefreshParts) + { + PartInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + if (tmp._MyItem != null) ItemInfo.Refresh(tmp._MyItem); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Part part) + { + if (!_CacheList.Contains(part)) _CacheList.Add(part); // In AddToCache + } + protected static void RemoveFromCache(Part part) + { + while (_CacheList.Contains(part)) _CacheList.Remove(part); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Part tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Part tmp in remove) + RemoveFromCache(tmp); + } + protected static Part GetCachedByPrimaryKey(int contentID, int fromType) + { + ConvertListToDictionary(); + string key = contentID.ToString() + "_" + fromType.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private Item _MyItem; + public Item MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = Item.Get(_ItemID); + return _MyItem; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItem != value) + { + _MyItem = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyItem == null ? false : _MyItem.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyItem == null ? true : _MyItem.IsValid); } + } + // TODO: Replace base Part.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Part + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Part.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Part + protected override object GetIdValue() + { + return (_ContentID.ToString() + "." + _FromType.ToString()).GetHashCode(); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyItem != null && (hasBrokenRules = _MyItem.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyItemRequired, "MyItem"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _PartExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _PartExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyItemRequired(Part target, Csla.Validation.RuleArgs e) + { + if (target._ItemID == 0 && target._MyItem == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(FromType, ""); + //AuthorizationRules.AllowRead(ItemID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ItemID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _PartExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _PartExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _PartUnique = 0; + protected static int PartUnique + { get { return ++_PartUnique; } } + private int _MyPartUnique = PartUnique; + public int MyPartUnique + { get { return _MyPartUnique; } } + protected Part() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) + { + List listPart = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items + while (listPart.Contains(this)) listPart.Remove(this); // Remove the item from the list + if (listPart.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list + } + } + public static Part New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Part"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.New", ex); + } + } + public static Part New(Content myContent, int fromType, Item myItem) + { + Part tmp = Part.New(); + tmp._MyContent = myContent; + tmp._FromType = fromType; + tmp.MyItem = myItem; + return tmp; + } + public static Part MakePart(Content myContent, int fromType, Item myItem) + { + Part tmp = Part.New(myContent, fromType, myItem); + if (tmp.IsSavable) + { + Part tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Part New(Content myContent, int fromType, Item myItem, DateTime dts, string userID) + { + Part tmp = Part.New(); + tmp._MyContent = myContent; + tmp._FromType = fromType; + tmp.MyItem = myItem; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Part MakePart(Content myContent, int fromType, Item myItem, DateTime dts, string userID) + { + Part tmp = Part.New(myContent, fromType, myItem, dts, userID); + if (tmp.IsSavable) + { + Part tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Part Get(int contentID, int fromType) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Part"); + try + { + Part tmp = GetCachedByPrimaryKey(contentID, fromType); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Part + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.Get", ex); + } + } + public static Part Get(SafeDataReader dr) + { + if (dr.Read()) return new Part(dr); + return null; + } + internal Part(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int contentID, int fromType) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Part"); + try + { + DataPortal.Delete(new PKCriteria(contentID, fromType)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.Delete", ex); + } + } + public override Part Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Part"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Part"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Part"); + try + { + BuildRefreshList(); + Part part = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(part);//Refresh the item in AllList + ProcessRefreshList(); + return part; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + private int _FromType; + public int FromType + { get { return _FromType; } } + public PKCriteria(int contentID, int fromType) + { + _ContentID = contentID; + _FromType = fromType; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _PartExtension.DefaultDTS; - _UserID = _PartExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPart"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.Parameters.AddWithValue("@FromType", criteria.FromType); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addPart"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - cm.Parameters.AddWithValue("@ItemID", ItemID); - 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); - // TODO: 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}] Part.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addPart"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@FromType", fromType); - cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Add", ex); - throw new DbCslaException("Part.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Part.SQLUpdate", GetHashCode()); - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItem != null) _MyItem.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updatePart"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - cm.Parameters.AddWithValue("@ItemID", ItemID); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Part.Add(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID); - else - _LastChanged = Part.Update(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updatePart"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@FromType", fromType); - cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Update", ex); - throw new DbCslaException("Part.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ContentID, _FromType)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deletePart"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.Parameters.AddWithValue("@FromType", criteria.FromType); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Part.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int contentID, int fromType) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deletePart"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - cm.Parameters.AddWithValue("@FromType", fromType); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Remove", ex); - throw new DbCslaException("Part.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID, int fromType) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID, fromType)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Part.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private int _FromType; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID, int fromType) - { - _ContentID = contentID; - _FromType = fromType; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsPart"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - cm.Parameters.AddWithValue("@FromType", _FromType); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Execute", ex); - throw new DbCslaException("Part.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - PartExtension _PartExtension = new PartExtension(); - [Serializable()] - partial class PartExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class PartConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Part) - { - // Return the ToString value - return ((Part)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _PartExtension.DefaultDTS; + _UserID = _PartExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPart"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.Parameters.AddWithValue("@FromType", criteria.FromType); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItem != null) _MyItem.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addPart"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", ItemID); + 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); + // TODO: 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}] Part.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addPart"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Add", ex); + throw new DbCslaException("Part.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Part.SQLUpdate", GetHashCode()); + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItem != null) _MyItem.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePart"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + cm.Parameters.AddWithValue("@ItemID", ItemID); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Part.Add(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID); + else + _LastChanged = Part.Update(cn, _MyContent, _FromType, _MyItem, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, Content myContent, int fromType, Item myItem, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePart"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@FromType", fromType); + cm.Parameters.AddWithValue("@ItemID", myItem.ItemID); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Update", ex); + throw new DbCslaException("Part.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ContentID, _FromType)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePart"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.Parameters.AddWithValue("@FromType", criteria.FromType); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Part.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int contentID, int fromType) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePart"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + cm.Parameters.AddWithValue("@FromType", fromType); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.Remove", ex); + throw new DbCslaException("Part.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID, int fromType) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID, fromType)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Part.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private int _FromType; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID, int fromType) + { + _ContentID = contentID; + _FromType = fromType; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Part.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsPart"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + cm.Parameters.AddWithValue("@FromType", _FromType); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Part.DataPortal_Execute", ex); + throw new DbCslaException("Part.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + PartExtension _PartExtension = new PartExtension(); + [Serializable()] + partial class PartExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class PartConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Part) + { + // Return the ToString value + return ((Part)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/PartInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/PartInfo.cs index 5dc0ce4c..daeb276a 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/PartInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/PartInfo.cs @@ -19,420 +19,413 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void PartInfoEvent(object sender); - /// - /// PartInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PartInfoConverter))] - public partial class PartInfo : ReadOnlyBase, IDisposable - { - public event PartInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(PartInfo partInfo) - { - if (!_CacheList.Contains(partInfo)) _CacheList.Add(partInfo); // In AddToCache - } - protected static void RemoveFromCache(PartInfo partInfo) - { - while (_CacheList.Contains(partInfo)) _CacheList.Remove(partInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (PartInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (PartInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(PartInfoList lst) - { - foreach (PartInfo item in lst) AddToCache(item); - } - protected static PartInfo GetCachedByPrimaryKey(int contentID, int fromType) - { - ConvertListToDictionary(); - string key = contentID.ToString() + "_" + fromType.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Part _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private int _FromType; - [System.ComponentModel.DataObjectField(true, true)] - public int FromType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromType", true); - return _FromType; - } - } - private int _ItemID; - public int ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ItemID", true); - if (_MyItem != null) _ItemID = _MyItem.ItemID; - return _ItemID; - } - } - private ItemInfo _MyItem; - public ItemInfo MyItem - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItem", true); - if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID); - return _MyItem; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // TODO: Replace base PartInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PartInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check PartInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PartInfo - protected override object GetIdValue() - { - return (_ContentID.ToString() + "." + _FromType.ToString()).GetHashCode(); - } - #endregion - #region Factory Methods - private static int _PartInfoUnique = 0; - private static int PartInfoUnique - { get { return ++_PartInfoUnique; } } - private int _MyPartInfoUnique = PartInfoUnique; - public int MyPartInfoUnique - { get { return _MyPartInfoUnique; } } - protected PartInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; - List listPartInfo = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items - while (listPartInfo.Contains(this)) listPartInfo.Remove(this); // Remove the item from the list - if (listPartInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list - } - public virtual Part Get() - { - return _Editable = Part.Get(_ContentID, _FromType); - } - public static void Refresh(Part tmp) - { - string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Part tmp) - { - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PartInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(Content myContent, ContentPart tmp) - { - string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentPart tmp) - { - if (_ItemID != tmp.ItemID) - { - if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PartInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ItemPart tmp) - { - string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemPart tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _PartInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyItem != null) - { - _MyItem.Dispose();// Dispose related value - _MyItem = null;// Reset related value - } - OnChange();// raise an event - } - public static PartInfo Get(int contentID, int fromType) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Part"); - try - { - PartInfo tmp = GetCachedByPrimaryKey(contentID, fromType); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up PartInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PartInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal PartInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.Constructor", ex); - throw new DbCslaException("PartInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - private int _FromType; - public int FromType - { get { return _FromType; } } - public PKCriteria(int contentID, int fromType) - { - _ContentID = contentID; - _FromType = fromType; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _FromType = dr.GetInt32("FromType"); - _ItemID = dr.GetInt32("ItemID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPart"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.Parameters.AddWithValue("@FromType", criteria.FromType); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PartInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - PartInfoExtension _PartInfoExtension = new PartInfoExtension(); - [Serializable()] - partial class PartInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(PartInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class PartInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PartInfo) - { - // Return the ToString value - return ((PartInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void PartInfoEvent(object sender); + /// + /// PartInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PartInfoConverter))] + public partial class PartInfo : ReadOnlyBase, IDisposable + { + public event PartInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PartInfo partInfo) + { + if (!_CacheList.Contains(partInfo)) _CacheList.Add(partInfo); // In AddToCache + } + protected static void RemoveFromCache(PartInfo partInfo) + { + while (_CacheList.Contains(partInfo)) _CacheList.Remove(partInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (PartInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString() + "_" + tmp.FromType.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString() + "_" + tmp.FromType.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (PartInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(PartInfoList lst) + { + foreach (PartInfo item in lst) AddToCache(item); + } + protected static PartInfo GetCachedByPrimaryKey(int contentID, int fromType) + { + ConvertListToDictionary(); + string key = contentID.ToString() + "_" + fromType.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Part _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private int _FromType; + [System.ComponentModel.DataObjectField(true, true)] + public int FromType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FromType; + } + } + private int _ItemID; + public int ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem != null) _ItemID = _MyItem.ItemID; + return _ItemID; + } + } + private ItemInfo _MyItem; + public ItemInfo MyItem + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItem == null && _ItemID != 0) _MyItem = ItemInfo.Get(_ItemID); + return _MyItem; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // TODO: Replace base PartInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PartInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check PartInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PartInfo + protected override object GetIdValue() + { + return (_ContentID.ToString() + "." + _FromType.ToString()).GetHashCode(); + } + #endregion + #region Factory Methods + private static int _PartInfoUnique = 0; + private static int PartInfoUnique + { get { return ++_PartInfoUnique; } } + private int _MyPartInfoUnique = PartInfoUnique; + public int MyPartInfoUnique + { get { return _MyPartInfoUnique; } } + protected PartInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString() + "_" + FromType.ToString())) return; + List listPartInfo = _CacheByPrimaryKey[ContentID.ToString() + "_" + FromType.ToString()]; // Get the list of items + while (listPartInfo.Contains(this)) listPartInfo.Remove(this); // Remove the item from the list + if (listPartInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString() + "_" + FromType.ToString()); // remove the list + } + public virtual Part Get() + { + return _Editable = Part.Get(_ContentID, _FromType); + } + public static void Refresh(Part tmp) + { + string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Part tmp) + { + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(Content myContent, ContentPart tmp) + { + string key = myContent.ContentID.ToString() + "_" + tmp.FromType.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentPart tmp) + { + if (_ItemID != tmp.ItemID) + { + if (MyItem != null) MyItem.RefreshItemParts(); // 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.RefreshItemParts(); // Update List for new value + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ItemPart tmp) + { + string key = tmp.ContentID.ToString() + "_" + tmp.FromType.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PartInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemPart tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _PartInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyItem != null) + { + _MyItem.Dispose();// Dispose related value + _MyItem = null;// Reset related value + } + OnChange();// raise an event + } + public static PartInfo Get(int contentID, int fromType) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Part"); + try + { + PartInfo tmp = GetCachedByPrimaryKey(contentID, fromType); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID, fromType)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PartInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PartInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal PartInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.Constructor", ex); + throw new DbCslaException("PartInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + private int _FromType; + public int FromType + { get { return _FromType; } } + public PKCriteria(int contentID, int fromType) + { + _ContentID = contentID; + _FromType = fromType; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _FromType = dr.GetInt32("FromType"); + _ItemID = dr.GetInt32("ItemID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PartInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPart"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.Parameters.AddWithValue("@FromType", criteria.FromType); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PartInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PartInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + PartInfoExtension _PartInfoExtension = new PartInfoExtension(); + [Serializable()] + partial class PartInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(PartInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class PartInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PartInfo) + { + // Return the ToString value + return ((PartInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Permission.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Permission.cs index 1764ec4b..6913dca7 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Permission.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Permission.cs @@ -20,1204 +20,1182 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Permission Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PermissionConverter))] - public partial class Permission : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshPermissions = new List(); - private void AddToRefreshList(List refreshPermissions) - { - if (IsDirty) - refreshPermissions.Add(this); - } - private void BuildRefreshList() - { - _RefreshPermissions = new List(); - AddToRefreshList(_RefreshPermissions); - } - private void ProcessRefreshList() - { - foreach (Permission tmp in _RefreshPermissions) - { - PermissionInfo.Refresh(tmp); - if (tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Permission permission) - { - if (!_CacheList.Contains(permission)) _CacheList.Add(permission); // In AddToCache - } - protected static void RemoveFromCache(Permission permission) - { - while (_CacheList.Contains(permission)) _CacheList.Remove(permission); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Permission tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString())) - { - _CacheByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Permission tmp in remove) - RemoveFromCache(tmp); - } - protected static Permission GetCachedByPrimaryKey(int pid) - { - ConvertListToDictionary(); - string key = pid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextPID = -1; - public static int NextPID - { - get { return _nextPID--; } - } - private int _PID; - [System.ComponentModel.DataObjectField(true, true)] - public int PID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PID", true); - return _PID; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private Role _MyRole; - public Role MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); - return _MyRole; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRole", true); - if (_MyRole != value) - { - _MyRole = value; - PropertyHasChanged(); - } - } - } - private int _PermLevel; - /// - /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments - /// - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermLevel", true); - return _PermLevel; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermLevel", true); - if (_PermLevel != value) - { - _PermLevel = value; - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private int _PermValue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermValue", true); - return _PermValue; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermValue", true); - if (_PermValue != value) - { - _PermValue = value; - PropertyHasChanged(); - } - } - } - private int _PermAD; - /// - /// 0 - Allow, 1 - Deny - /// - public int PermAD - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermAD", true); - return _PermAD; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermAD", true); - if (_PermAD != value) - { - _PermAD = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValid); } - } - // TODO: Replace base Permission.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Permission - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Permission.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Permission - protected override object GetIdValue() - { - return _PID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRoleRequired, "MyRole"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _PermissionExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _PermissionExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool StartDateValid(Permission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(Permission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyRoleRequired(Permission target, Csla.Validation.RuleArgs e) - { - if (target._RID == 0 && target._MyRole == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(PID, ""); - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowRead(PermLevel, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowRead(PermValue, ""); - //AuthorizationRules.AllowRead(PermAD, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(RID, ""); - //AuthorizationRules.AllowWrite(PermLevel, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowWrite(PermValue, ""); - //AuthorizationRules.AllowWrite(PermAD, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _PermissionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _PermissionExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _PermissionUnique = 0; - protected static int PermissionUnique - { get { return ++_PermissionUnique; } } - private int _MyPermissionUnique = PermissionUnique; - public int MyPermissionUnique - { get { return _MyPermissionUnique; } } - protected Permission() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(PID.ToString())) - { - List listPermission = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items - while (listPermission.Contains(this)) listPermission.Remove(this); // Remove the item from the list - if (listPermission.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list - } - } - public static Permission New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Permission"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.New", ex); - } - } - public static Permission New(Role myRole, int permLevel, int versionType, int permValue) - { - Permission tmp = Permission.New(); - tmp.MyRole = myRole; - tmp.PermLevel = permLevel; - tmp.VersionType = versionType; - tmp.PermValue = permValue; - return tmp; - } - public static Permission New(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Permission tmp = Permission.New(); - tmp.MyRole = myRole; - tmp.PermLevel = permLevel; - tmp.VersionType = versionType; - tmp.PermValue = permValue; - tmp.PermAD = permAD; - tmp.StartDate = startDate; - tmp.EndDate = endDate; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) - { - Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, permAD, startDate, endDate, config, dts, usrID); - if (tmp.IsSavable) - { - Permission tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Permission New(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) - { - Permission tmp = Permission.New(); - tmp.MyRole = myRole; - tmp.PermLevel = permLevel; - tmp.VersionType = versionType; - tmp.PermValue = permValue; - tmp.EndDate = endDate; - tmp.Config = config; - return tmp; - } - public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) - { - Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, endDate, config); - if (tmp.IsSavable) - { - Permission tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Permission Get(int pid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Permission"); - try - { - Permission tmp = GetCachedByPrimaryKey(pid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(pid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Permission - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.Get", ex); - } - } - public static Permission Get(SafeDataReader dr) - { - if (dr.Read()) return new Permission(dr); - return null; - } - internal Permission(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int pid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Permission"); - try - { - DataPortal.Delete(new PKCriteria(pid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.Delete", ex); - } - } - public override Permission Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Permission"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Permission"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Permission"); - try - { - BuildRefreshList(); - Permission permission = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(permission);//Refresh the item in AllList - ProcessRefreshList(); - return permission; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _PID; - public int PID - { get { return _PID; } } - public PKCriteria(int pid) - { - _PID = pid; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _PID = NextPID; - // Database Defaults - _PermAD = _PermissionExtension.DefaultPermAD; - _StartDate = _PermissionExtension.DefaultStartDate; - _DTS = _PermissionExtension.DefaultDTS; - _UsrID = _PermissionExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.ReadData", GetHashCode()); - try - { - _PID = dr.GetInt32("PID"); - _RID = dr.GetInt32("RID"); - _PermLevel = dr.GetInt32("PermLevel"); - _VersionType = dr.GetInt32("VersionType"); - _PermValue = dr.GetInt32("PermValue"); - _PermAD = dr.GetInt32("PermAD"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPermission"; - cm.Parameters.AddWithValue("@PID", criteria.PID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRole != null) _MyRole.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addPermission"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RID", RID); - cm.Parameters.AddWithValue("@PermLevel", _PermLevel); - cm.Parameters.AddWithValue("@VersionType", _VersionType); - cm.Parameters.AddWithValue("@PermValue", _PermValue); - cm.Parameters.AddWithValue("@PermAD", _PermAD); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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_PID = new SqlParameter("@newPID", SqlDbType.Int); - param_PID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_PID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _PID = (int)cm.Parameters["@newPID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addPermission"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RID", myRole.RID); - cm.Parameters.AddWithValue("@PermLevel", permLevel); - cm.Parameters.AddWithValue("@VersionType", versionType); - cm.Parameters.AddWithValue("@PermValue", permValue); - cm.Parameters.AddWithValue("@PermAD", permAD); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - 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_PID = new SqlParameter("@newPID", SqlDbType.Int); - param_PID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_PID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - pid = (int)cm.Parameters["@newPID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Add", ex); - throw new DbCslaException("Permission.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Permission.SQLUpdate", GetHashCode()); - try - { - if (_MyRole != null) _MyRole.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updatePermission"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@PID", _PID); - cm.Parameters.AddWithValue("@RID", RID); - cm.Parameters.AddWithValue("@PermLevel", _PermLevel); - cm.Parameters.AddWithValue("@VersionType", _VersionType); - cm.Parameters.AddWithValue("@PermValue", _PermValue); - cm.Parameters.AddWithValue("@PermAD", _PermAD); - cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); - cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Permission.Add(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); - else - _LastChanged = Permission.Update(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updatePermission"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@PID", pid); - cm.Parameters.AddWithValue("@RID", myRole.RID); - cm.Parameters.AddWithValue("@PermLevel", permLevel); - cm.Parameters.AddWithValue("@VersionType", versionType); - cm.Parameters.AddWithValue("@PermValue", permValue); - cm.Parameters.AddWithValue("@PermAD", permAD); - cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); - cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Update", ex); - throw new DbCslaException("Permission.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_PID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deletePermission"; - cm.Parameters.AddWithValue("@PID", criteria.PID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Permission.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int pid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deletePermission"; - // Input PK Fields - cm.Parameters.AddWithValue("@PID", pid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Remove", ex); - throw new DbCslaException("Permission.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int pid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(pid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Permission.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _PID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int pid) - { - _PID = pid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsPermission"; - cm.Parameters.AddWithValue("@PID", _PID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Execute", ex); - throw new DbCslaException("Permission.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - PermissionExtension _PermissionExtension = new PermissionExtension(); - [Serializable()] - partial class PermissionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultPermAD - { - get { return 0; } - } - public virtual string DefaultStartDate - { - get { return DateTime.Now.ToShortDateString(); } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class PermissionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Permission) - { - // Return the ToString value - return ((Permission)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Permission Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PermissionConverter))] + public partial class Permission : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshPermissions = new List(); + private void AddToRefreshList(List refreshPermissions) + { + if (IsDirty) + refreshPermissions.Add(this); + } + private void BuildRefreshList() + { + _RefreshPermissions = new List(); + AddToRefreshList(_RefreshPermissions); + } + private void ProcessRefreshList() + { + foreach (Permission tmp in _RefreshPermissions) + { + PermissionInfo.Refresh(tmp); + if (tmp._MyRole != null) RoleInfo.Refresh(tmp._MyRole); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Permission permission) + { + if (!_CacheList.Contains(permission)) _CacheList.Add(permission); // In AddToCache + } + protected static void RemoveFromCache(Permission permission) + { + while (_CacheList.Contains(permission)) _CacheList.Remove(permission); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Permission tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString())) + { + _CacheByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Permission tmp in remove) + RemoveFromCache(tmp); + } + protected static Permission GetCachedByPrimaryKey(int pid) + { + ConvertListToDictionary(); + string key = pid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextPID = -1; + public static int NextPID + { + get { return _nextPID--; } + } + private int _PID; + [System.ComponentModel.DataObjectField(true, true)] + public int PID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PID; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private Role _MyRole; + public Role MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = Role.Get(_RID); + return _MyRole; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRole != value) + { + _MyRole = value; + PropertyHasChanged(); + } + } + } + private int _PermLevel; + /// + /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments + /// + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermLevel; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermLevel != value) + { + _PermLevel = value; + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private int _PermValue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermValue; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermValue != value) + { + _PermValue = value; + PropertyHasChanged(); + } + } + } + private int _PermAD; + /// + /// 0 - Allow, 1 - Deny + /// + public int PermAD + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermAD; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermAD != value) + { + _PermAD = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyRole == null ? false : _MyRole.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyRole == null ? true : _MyRole.IsValid); } + } + // TODO: Replace base Permission.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Permission + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Permission.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Permission + protected override object GetIdValue() + { + return _PID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyRole != null && (hasBrokenRules = _MyRole.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRoleRequired, "MyRole"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _PermissionExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _PermissionExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool StartDateValid(Permission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(Permission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyRoleRequired(Permission target, Csla.Validation.RuleArgs e) + { + if (target._RID == 0 && target._MyRole == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(PID, ""); + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowRead(PermLevel, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowRead(PermValue, ""); + //AuthorizationRules.AllowRead(PermAD, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(RID, ""); + //AuthorizationRules.AllowWrite(PermLevel, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowWrite(PermValue, ""); + //AuthorizationRules.AllowWrite(PermAD, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _PermissionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _PermissionExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _PermissionUnique = 0; + protected static int PermissionUnique + { get { return ++_PermissionUnique; } } + private int _MyPermissionUnique = PermissionUnique; + public int MyPermissionUnique + { get { return _MyPermissionUnique; } } + protected Permission() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(PID.ToString())) + { + List listPermission = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items + while (listPermission.Contains(this)) listPermission.Remove(this); // Remove the item from the list + if (listPermission.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list + } + } + public static Permission New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Permission"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.New", ex); + } + } + public static Permission New(Role myRole, int permLevel, int versionType, int permValue) + { + Permission tmp = Permission.New(); + tmp.MyRole = myRole; + tmp.PermLevel = permLevel; + tmp.VersionType = versionType; + tmp.PermValue = permValue; + return tmp; + } + public static Permission New(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Permission tmp = Permission.New(); + tmp.MyRole = myRole; + tmp.PermLevel = permLevel; + tmp.VersionType = versionType; + tmp.PermValue = permValue; + tmp.PermAD = permAD; + tmp.StartDate = startDate; + tmp.EndDate = endDate; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, int permAD, string startDate, string endDate, string config, DateTime dts, string usrID) + { + Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, permAD, startDate, endDate, config, dts, usrID); + if (tmp.IsSavable) + { + Permission tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Permission New(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) + { + Permission tmp = Permission.New(); + tmp.MyRole = myRole; + tmp.PermLevel = permLevel; + tmp.VersionType = versionType; + tmp.PermValue = permValue; + tmp.EndDate = endDate; + tmp.Config = config; + return tmp; + } + public static Permission MakePermission(Role myRole, int permLevel, int versionType, int permValue, string endDate, string config) + { + Permission tmp = Permission.New(myRole, permLevel, versionType, permValue, endDate, config); + if (tmp.IsSavable) + { + Permission tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Permission Get(int pid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Permission"); + try + { + Permission tmp = GetCachedByPrimaryKey(pid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(pid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Permission + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.Get", ex); + } + } + public static Permission Get(SafeDataReader dr) + { + if (dr.Read()) return new Permission(dr); + return null; + } + internal Permission(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int pid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Permission"); + try + { + DataPortal.Delete(new PKCriteria(pid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.Delete", ex); + } + } + public override Permission Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Permission"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Permission"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Permission"); + try + { + BuildRefreshList(); + Permission permission = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(permission);//Refresh the item in AllList + ProcessRefreshList(); + return permission; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _PID; + public int PID + { get { return _PID; } } + public PKCriteria(int pid) + { + _PID = pid; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _PID = NextPID; + // Database Defaults + _PermAD = _PermissionExtension.DefaultPermAD; + _StartDate = _PermissionExtension.DefaultStartDate; + _DTS = _PermissionExtension.DefaultDTS; + _UsrID = _PermissionExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.ReadData", GetHashCode()); + try + { + _PID = dr.GetInt32("PID"); + _RID = dr.GetInt32("RID"); + _PermLevel = dr.GetInt32("PermLevel"); + _VersionType = dr.GetInt32("VersionType"); + _PermValue = dr.GetInt32("PermValue"); + _PermAD = dr.GetInt32("PermAD"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermission"; + cm.Parameters.AddWithValue("@PID", criteria.PID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRole != null) _MyRole.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addPermission"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RID", RID); + cm.Parameters.AddWithValue("@PermLevel", _PermLevel); + cm.Parameters.AddWithValue("@VersionType", _VersionType); + cm.Parameters.AddWithValue("@PermValue", _PermValue); + cm.Parameters.AddWithValue("@PermAD", _PermAD); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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_PID = new SqlParameter("@newPID", SqlDbType.Int); + param_PID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_PID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _PID = (int)cm.Parameters["@newPID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addPermission"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RID", myRole.RID); + cm.Parameters.AddWithValue("@PermLevel", permLevel); + cm.Parameters.AddWithValue("@VersionType", versionType); + cm.Parameters.AddWithValue("@PermValue", permValue); + cm.Parameters.AddWithValue("@PermAD", permAD); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + 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_PID = new SqlParameter("@newPID", SqlDbType.Int); + param_PID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_PID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + pid = (int)cm.Parameters["@newPID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Add", ex); + throw new DbCslaException("Permission.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Permission.SQLUpdate", GetHashCode()); + try + { + if (_MyRole != null) _MyRole.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePermission"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@PID", _PID); + cm.Parameters.AddWithValue("@RID", RID); + cm.Parameters.AddWithValue("@PermLevel", _PermLevel); + cm.Parameters.AddWithValue("@VersionType", _VersionType); + cm.Parameters.AddWithValue("@PermValue", _PermValue); + cm.Parameters.AddWithValue("@PermAD", _PermAD); + cm.Parameters.AddWithValue("@StartDate", new SmartDate(_StartDate).DBValue); + cm.Parameters.AddWithValue("@EndDate", new SmartDate(_EndDate).DBValue); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Permission.Add(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); + else + _LastChanged = Permission.Update(cn, ref _PID, _MyRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int pid, Role myRole, int permLevel, int versionType, int permValue, int permAD, SmartDate startDate, SmartDate endDate, string config, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePermission"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@PID", pid); + cm.Parameters.AddWithValue("@RID", myRole.RID); + cm.Parameters.AddWithValue("@PermLevel", permLevel); + cm.Parameters.AddWithValue("@VersionType", versionType); + cm.Parameters.AddWithValue("@PermValue", permValue); + cm.Parameters.AddWithValue("@PermAD", permAD); + cm.Parameters.AddWithValue("@StartDate", startDate.DBValue); + cm.Parameters.AddWithValue("@EndDate", endDate.DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Update", ex); + throw new DbCslaException("Permission.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_PID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePermission"; + cm.Parameters.AddWithValue("@PID", criteria.PID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Permission.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int pid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePermission"; + // Input PK Fields + cm.Parameters.AddWithValue("@PID", pid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.Remove", ex); + throw new DbCslaException("Permission.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int pid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(pid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Permission.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _PID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int pid) + { + _PID = pid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Permission.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsPermission"; + cm.Parameters.AddWithValue("@PID", _PID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Permission.DataPortal_Execute", ex); + throw new DbCslaException("Permission.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + PermissionExtension _PermissionExtension = new PermissionExtension(); + [Serializable()] + partial class PermissionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultPermAD + { + get { return 0; } + } + public virtual string DefaultStartDate + { + get { return DateTime.Now.ToShortDateString(); } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class PermissionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Permission) + { + // Return the ToString value + return ((Permission)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/PermissionInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/PermissionInfo.cs index bed79b29..09e8d172 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/PermissionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/PermissionInfo.cs @@ -19,451 +19,439 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void PermissionInfoEvent(object sender); - /// - /// PermissionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(PermissionInfoConverter))] - public partial class PermissionInfo : ReadOnlyBase, IDisposable - { - public event PermissionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(PermissionInfo permissionInfo) - { - if (!_CacheList.Contains(permissionInfo)) _CacheList.Add(permissionInfo); // In AddToCache - } - protected static void RemoveFromCache(PermissionInfo permissionInfo) - { - while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (PermissionInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString())) - { - _CacheByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (PermissionInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(PermissionInfoList lst) - { - foreach (PermissionInfo item in lst) AddToCache(item); - } - protected static PermissionInfo GetCachedByPrimaryKey(int pid) - { - ConvertListToDictionary(); - string key = pid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Permission _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _PID; - [System.ComponentModel.DataObjectField(true, true)] - public int PID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PID", true); - return _PID; - } - } - private int _RID; - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - if (_MyRole != null) _RID = _MyRole.RID; - return _RID; - } - } - private RoleInfo _MyRole; - public RoleInfo MyRole - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRole", true); - if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); - return _MyRole; - } - } - private int _PermLevel; - /// - /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments - /// - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermLevel", true); - return _PermLevel; - } - } - private int _VersionType; - /// - /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - } - private int _PermValue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermValue", true); - return _PermValue; - } - } - private int _PermAD; - /// - /// 0 - Allow, 1 - Deny - /// - public int PermAD - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermAD", true); - return _PermAD; - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - // TODO: Replace base PermissionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PermissionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check PermissionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PermissionInfo - protected override object GetIdValue() - { - return _PID; - } - #endregion - #region Factory Methods - private static int _PermissionInfoUnique = 0; - private static int PermissionInfoUnique - { get { return ++_PermissionInfoUnique; } } - private int _MyPermissionInfoUnique = PermissionInfoUnique; - public int MyPermissionInfoUnique - { get { return _MyPermissionInfoUnique; } } - protected PermissionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(PID.ToString())) return; - List listPermissionInfo = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items - while (listPermissionInfo.Contains(this)) listPermissionInfo.Remove(this); // Remove the item from the list - if (listPermissionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list - } - public virtual Permission Get() - { - return _Editable = Permission.Get(_PID); - } - public static void Refresh(Permission tmp) - { - string key = tmp.PID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Permission tmp) - { - if (_RID != tmp.RID) - { - if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value - _RID = tmp.RID; // Update the value - } - _MyRole = null; // Reset list so that the next line gets a new list - if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for new value - _PermLevel = tmp.PermLevel; - _VersionType = tmp.VersionType; - _PermValue = tmp.PermValue; - _PermAD = tmp.PermAD; - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _PermissionInfoExtension.Refresh(this); - if(_MyRole != null) - { - _MyRole.Dispose();// Dispose related value - _MyRole = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(RolePermission tmp) - { - string key = tmp.PID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RolePermission tmp) - { - _PermLevel = tmp.PermLevel; - _VersionType = tmp.VersionType; - _PermValue = tmp.PermValue; - _PermAD = tmp.PermAD; - _StartDate = tmp.StartDate; - _EndDate = tmp.EndDate; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _PermissionInfoExtension.Refresh(this); - if(_MyRole != null) - { - _MyRole.Dispose();// Dispose related value - _MyRole = null;// Reset related value - } - OnChange();// raise an event - } - public static PermissionInfo Get(int pid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Permission"); - try - { - PermissionInfo tmp = GetCachedByPrimaryKey(pid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(pid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up PermissionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on PermissionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal PermissionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.Constructor", ex); - throw new DbCslaException("PermissionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _PID; - public int PID - { get { return _PID; } } - public PKCriteria(int pid) - { - _PID = pid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.ReadData", GetHashCode()); - try - { - _PID = dr.GetInt32("PID"); - _RID = dr.GetInt32("RID"); - _PermLevel = dr.GetInt32("PermLevel"); - _VersionType = dr.GetInt32("VersionType"); - _PermValue = dr.GetInt32("PermValue"); - _PermAD = dr.GetInt32("PermAD"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PermissionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPermission"; - cm.Parameters.AddWithValue("@PID", criteria.PID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("PermissionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - PermissionInfoExtension _PermissionInfoExtension = new PermissionInfoExtension(); - [Serializable()] - partial class PermissionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(PermissionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class PermissionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is PermissionInfo) - { - // Return the ToString value - return ((PermissionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void PermissionInfoEvent(object sender); + /// + /// PermissionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(PermissionInfoConverter))] + public partial class PermissionInfo : ReadOnlyBase, IDisposable + { + public event PermissionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(PermissionInfo permissionInfo) + { + if (!_CacheList.Contains(permissionInfo)) _CacheList.Add(permissionInfo); // In AddToCache + } + protected static void RemoveFromCache(PermissionInfo permissionInfo) + { + while (_CacheList.Contains(permissionInfo)) _CacheList.Remove(permissionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (PermissionInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.PID.ToString())) + { + _CacheByPrimaryKey[tmp.PID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.PID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (PermissionInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(PermissionInfoList lst) + { + foreach (PermissionInfo item in lst) AddToCache(item); + } + protected static PermissionInfo GetCachedByPrimaryKey(int pid) + { + ConvertListToDictionary(); + string key = pid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Permission _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _PID; + [System.ComponentModel.DataObjectField(true, true)] + public int PID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PID; + } + } + private int _RID; + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole != null) _RID = _MyRole.RID; + return _RID; + } + } + private RoleInfo _MyRole; + public RoleInfo MyRole + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRole == null && _RID != 0) _MyRole = RoleInfo.Get(_RID); + return _MyRole; + } + } + private int _PermLevel; + /// + /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments + /// + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermLevel; + } + } + private int _VersionType; + /// + /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + } + private int _PermValue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermValue; + } + } + private int _PermAD; + /// + /// 0 - Allow, 1 - Deny + /// + public int PermAD + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermAD; + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + // TODO: Replace base PermissionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PermissionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check PermissionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PermissionInfo + protected override object GetIdValue() + { + return _PID; + } + #endregion + #region Factory Methods + private static int _PermissionInfoUnique = 0; + private static int PermissionInfoUnique + { get { return ++_PermissionInfoUnique; } } + private int _MyPermissionInfoUnique = PermissionInfoUnique; + public int MyPermissionInfoUnique + { get { return _MyPermissionInfoUnique; } } + protected PermissionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(PID.ToString())) return; + List listPermissionInfo = _CacheByPrimaryKey[PID.ToString()]; // Get the list of items + while (listPermissionInfo.Contains(this)) listPermissionInfo.Remove(this); // Remove the item from the list + if (listPermissionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(PID.ToString()); // remove the list + } + public virtual Permission Get() + { + return _Editable = Permission.Get(_PID); + } + public static void Refresh(Permission tmp) + { + string key = tmp.PID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Permission tmp) + { + if (_RID != tmp.RID) + { + if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for old value + _RID = tmp.RID; // Update the value + } + _MyRole = null; // Reset list so that the next line gets a new list + if (MyRole != null) MyRole.RefreshRolePermissions(); // Update List for new value + _PermLevel = tmp.PermLevel; + _VersionType = tmp.VersionType; + _PermValue = tmp.PermValue; + _PermAD = tmp.PermAD; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _PermissionInfoExtension.Refresh(this); + if (_MyRole != null) + { + _MyRole.Dispose();// Dispose related value + _MyRole = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(RolePermission tmp) + { + string key = tmp.PID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (PermissionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RolePermission tmp) + { + _PermLevel = tmp.PermLevel; + _VersionType = tmp.VersionType; + _PermValue = tmp.PermValue; + _PermAD = tmp.PermAD; + _StartDate = tmp.StartDate; + _EndDate = tmp.EndDate; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _PermissionInfoExtension.Refresh(this); + if (_MyRole != null) + { + _MyRole.Dispose();// Dispose related value + _MyRole = null;// Reset related value + } + OnChange();// raise an event + } + public static PermissionInfo Get(int pid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Permission"); + try + { + PermissionInfo tmp = GetCachedByPrimaryKey(pid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(pid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up PermissionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on PermissionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal PermissionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.Constructor", ex); + throw new DbCslaException("PermissionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _PID; + public int PID + { get { return _PID; } } + public PKCriteria(int pid) + { + _PID = pid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.ReadData", GetHashCode()); + try + { + _PID = dr.GetInt32("PID"); + _RID = dr.GetInt32("RID"); + _PermLevel = dr.GetInt32("PermLevel"); + _VersionType = dr.GetInt32("VersionType"); + _PermValue = dr.GetInt32("PermValue"); + _PermAD = dr.GetInt32("PermAD"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PermissionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] PermissionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermission"; + cm.Parameters.AddWithValue("@PID", criteria.PID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("PermissionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("PermissionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + PermissionInfoExtension _PermissionInfoExtension = new PermissionInfoExtension(); + [Serializable()] + partial class PermissionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(PermissionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class PermissionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is PermissionInfo) + { + // Return the ToString value + return ((PermissionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODb.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODb.cs index 68c65f38..febd474c 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODb.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODb.cs @@ -20,1148 +20,1131 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODb Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbConverter))] - public partial class RODb : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshRODbs = new List(); - private List _RefreshRODbROFsts = new List(); - private List _RefreshRODbROImages = new List(); - private List _RefreshRODbRoUsages = new List(); - private void AddToRefreshList(List refreshRODbs, List refreshRODbROFsts, List refreshRODbROImages, List refreshRODbRoUsages) - { - if (IsDirty) - refreshRODbs.Add(this); - if (_RODbROFsts != null && _RODbROFsts.IsDirty) - { - foreach (RODbROFst tmp in _RODbROFsts) - { - if (tmp.IsDirty) refreshRODbROFsts.Add(tmp); - } - } - if (_RODbROImages != null && _RODbROImages.IsDirty) - { - foreach (RODbROImage tmp in _RODbROImages) - { - if (tmp.IsDirty) refreshRODbROImages.Add(tmp); - } - } - if (_RODbRoUsages != null && _RODbRoUsages.IsDirty) - { - foreach (RODbRoUsage tmp in _RODbRoUsages) - { - if (tmp.IsDirty) refreshRODbRoUsages.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshRODbs = new List(); - _RefreshRODbROFsts = new List(); - _RefreshRODbROImages = new List(); - _RefreshRODbRoUsages = new List(); - AddToRefreshList(_RefreshRODbs, _RefreshRODbROFsts, _RefreshRODbROImages, _RefreshRODbRoUsages); - } - private void ProcessRefreshList() - { - foreach (RODb tmp in _RefreshRODbs) - { - RODbInfo.Refresh(tmp); - } - foreach (RODbROFst tmp in _RefreshRODbROFsts) - { - ROFstInfo.Refresh(tmp); - } - foreach (RODbROImage tmp in _RefreshRODbROImages) - { - ROImageInfo.Refresh(tmp); - } - foreach (RODbRoUsage tmp in _RefreshRODbRoUsages) - { - RoUsageInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RODb rODb) - { - if (!_CacheList.Contains(rODb)) _CacheList.Add(rODb); // In AddToCache - } - protected static void RemoveFromCache(RODb rODb) - { - while (_CacheList.Contains(rODb)) _CacheList.Remove(rODb); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (RODb tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.RODbID.ToString())) - { - _CacheByPrimaryKey[tmp.RODbID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.RODbID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (RODb tmp in remove) - RemoveFromCache(tmp); - } - protected static RODb GetCachedByPrimaryKey(int rODbID) - { - ConvertListToDictionary(); - string key = rODbID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextRODbID = -1; - public static int NextRODbID - { - get { return _nextRODbID--; } - } - private int _RODbID; - [System.ComponentModel.DataObjectField(true, true)] - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - return _RODbID; - } - } - private string _ROName = string.Empty; - /// - /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion - /// - public string ROName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROName", true); - return _ROName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROName", true); - if (value == null) value = string.Empty; - if (_ROName != value) - { - _ROName = value; - PropertyHasChanged(); - } - } - } - private string _FolderPath = string.Empty; - /// - /// Path to the RO database - /// - public string FolderPath - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderPath", true); - return _FolderPath; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FolderPath", true); - if (value == null) value = string.Empty; - if (_FolderPath != value) - { - _FolderPath = value; - PropertyHasChanged(); - } - } - } - private string _DBConnectionString = string.Empty; - /// - /// Connection String - Default could just be the full path and name of the database - /// - public string DBConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBConnectionString", true); - return _DBConnectionString; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DBConnectionString", true); - if (value == null) value = string.Empty; - if (_DBConnectionString != value) - { - _DBConnectionString = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbROFstCount = 0; - /// - /// Count of RODbROFsts for this RODb - /// - public int RODbROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFstCount", true); - return _RODbROFstCount; - } - } - private RODbROFsts _RODbROFsts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RODbROFstsConverter))] - public RODbROFsts RODbROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFsts", true); - if (_RODbROFstCount > 0 && _RODbROFsts == null) - _RODbROFsts = RODbROFsts.GetByRODbID(RODbID); - else if (_RODbROFsts == null) - _RODbROFsts = RODbROFsts.New(); - return _RODbROFsts; - } - } - private int _RODbROImageCount = 0; - /// - /// Count of RODbROImages for this RODb - /// - public int RODbROImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImageCount", true); - return _RODbROImageCount; - } - } - private RODbROImages _RODbROImages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RODbROImagesConverter))] - public RODbROImages RODbROImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImages", true); - if (_RODbROImageCount > 0 && _RODbROImages == null) - _RODbROImages = RODbROImages.GetByRODbID(RODbID); - else if (_RODbROImages == null) - _RODbROImages = RODbROImages.New(); - return _RODbROImages; - } - } - private int _RODbRoUsageCount = 0; - /// - /// Count of RODbRoUsages for this RODb - /// - public int RODbRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsageCount", true); - return _RODbRoUsageCount; - } - } - private RODbRoUsages _RODbRoUsages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RODbRoUsagesConverter))] - public RODbRoUsages RODbRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsages", true); - if (_RODbRoUsageCount > 0 && _RODbRoUsages == null) - _RODbRoUsages = RODbRoUsages.GetByRODbID(RODbID); - else if (_RODbRoUsages == null) - _RODbRoUsages = RODbRoUsages.New(); - return _RODbRoUsages; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_RODbROFsts == null ? false : _RODbROFsts.IsDirty) || (_RODbROImages == null ? false : _RODbROImages.IsDirty) || (_RODbRoUsages == null ? false : _RODbRoUsages.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_RODbROFsts == null ? true : _RODbROFsts.IsValid) && (_RODbROImages == null ? true : _RODbROImages.IsValid) && (_RODbRoUsages == null ? true : _RODbRoUsages.IsValid); } - } - // TODO: Replace base RODb.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODb - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check RODb.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODb - protected override object GetIdValue() - { - return _RODbID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_RODbRoUsages != null && (hasBrokenRules = _RODbRoUsages.HasBrokenRules) != null) return hasBrokenRules; - if (_RODbROFsts != null && (hasBrokenRules = _RODbROFsts.HasBrokenRules) != null) return hasBrokenRules; - if (_RODbROImages != null && (hasBrokenRules = _RODbROImages.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROName", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FolderPath"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FolderPath", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "DBConnectionString"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("DBConnectionString", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _RODbExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _RODbExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowRead(ROName, ""); - //AuthorizationRules.AllowRead(FolderPath, ""); - //AuthorizationRules.AllowRead(DBConnectionString, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(ROName, ""); - //AuthorizationRules.AllowWrite(FolderPath, ""); - //AuthorizationRules.AllowWrite(DBConnectionString, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _RODbExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _RODbExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _RODbROFstCount; - usedByCount += _RODbROImageCount; - usedByCount += _RODbRoUsageCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _RODbUnique = 0; - protected static int RODbUnique - { get { return ++_RODbUnique; } } - private int _MyRODbUnique = RODbUnique; - public int MyRODbUnique - { get { return _MyRODbUnique; } } - protected RODb() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) - { - List listRODb = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items - while (listRODb.Contains(this)) listRODb.Remove(this); // Remove the item from the list - if (listRODb.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list - } - } - public static RODb New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RODb"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.New", ex); - } - } - public static RODb New(string rOName, string folderPath, string dBConnectionString) - { - RODb tmp = RODb.New(); - tmp.ROName = rOName; - tmp.FolderPath = folderPath; - tmp.DBConnectionString = dBConnectionString; - return tmp; - } - public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString) - { - RODb tmp = RODb.New(rOName, folderPath, dBConnectionString); - if (tmp.IsSavable) - { - RODb tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RODb New(string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID) - { - RODb tmp = RODb.New(); - tmp.ROName = rOName; - tmp.FolderPath = folderPath; - tmp.DBConnectionString = dBConnectionString; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID) - { - RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, dts, userID); - if (tmp.IsSavable) - { - RODb tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RODb Get(int rODbID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a RODb"); - try - { - RODb tmp = GetCachedByPrimaryKey(rODbID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rODbID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RODb - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.Get", ex); - } - } - public static RODb Get(SafeDataReader dr) - { - if (dr.Read()) return new RODb(dr); - return null; - } - internal RODb(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rODbID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RODb"); - try - { - DataPortal.Delete(new PKCriteria(rODbID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.Delete", ex); - } - } - public override RODb Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RODb"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RODb"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a RODb"); - try - { - BuildRefreshList(); - RODb rODb = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(rODb);//Refresh the item in AllList - ProcessRefreshList(); - return rODb; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - public PKCriteria(int rODbID) - { - _RODbID = rODbID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _RODbID = NextRODbID; - // Database Defaults - _DTS = _RODbExtension.DefaultDTS; - _UserID = _RODbExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.ReadData", GetHashCode()); - try - { - _RODbID = dr.GetInt32("RODbID"); - _ROName = dr.GetString("ROName"); - _FolderPath = dr.GetString("FolderPath"); - _DBConnectionString = dr.GetString("DBConnectionString"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbROFstCount = dr.GetInt32("ROFstCount"); - _RODbROImageCount = dr.GetInt32("ROImageCount"); - _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRODb"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _RODbROFsts = RODbROFsts.Get(dr); - // load child objects - dr.NextResult(); - _RODbROImages = RODbROImages.Get(dr); - // load child objects - dr.NextResult(); - _RODbRoUsages = RODbRoUsages.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRODb"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROName", _ROName); - cm.Parameters.AddWithValue("@FolderPath", _FolderPath); - cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - // Output Calculated Columns - SqlParameter param_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); - param_RODbID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RODbID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _RODbID = (int)cm.Parameters["@newRODbID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRODb"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROName", rOName); - cm.Parameters.AddWithValue("@FolderPath", folderPath); - cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UserID", userID); - // Output Calculated Columns - SqlParameter param_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); - param_RODbID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RODbID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - rODbID = (int)cm.Parameters["@newRODbID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Add", ex); - throw new DbCslaException("RODb.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] RODb.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRODb"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RODbID", _RODbID); - cm.Parameters.AddWithValue("@ROName", _ROName); - cm.Parameters.AddWithValue("@FolderPath", _FolderPath); - cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); - 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); - // TODO: 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 (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = RODb.Add(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _DTS, _UserID); - else - _LastChanged = RODb.Update(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_RODbRoUsages != null) _RODbRoUsages.Update(this); - if (_RODbROFsts != null) _RODbROFsts.Update(this); - if (_RODbROImages != null) _RODbROImages.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRODb"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", rODbID); - cm.Parameters.AddWithValue("@ROName", rOName); - cm.Parameters.AddWithValue("@FolderPath", folderPath); - cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Update", ex); - throw new DbCslaException("RODb.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_RODbID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRODb"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODb.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rODbID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRODb"; - // Input PK Fields - cm.Parameters.AddWithValue("@RODbID", rODbID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Remove", ex); - throw new DbCslaException("RODb.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rODbID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rODbID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODb.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _RODbID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rODbID) - { - _RODbID = rODbID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsRODb"; - cm.Parameters.AddWithValue("@RODbID", _RODbID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Execute", ex); - throw new DbCslaException("RODb.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - RODbExtension _RODbExtension = new RODbExtension(); - [Serializable()] - partial class RODbExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODb) - { - // Return the ToString value - return ((RODb)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODb Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbConverter))] + public partial class RODb : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRODbs = new List(); + private List _RefreshRODbROFsts = new List(); + private List _RefreshRODbROImages = new List(); + private List _RefreshRODbRoUsages = new List(); + private void AddToRefreshList(List refreshRODbs, List refreshRODbROFsts, List refreshRODbROImages, List refreshRODbRoUsages) + { + if (IsDirty) + refreshRODbs.Add(this); + if (_RODbROFsts != null && _RODbROFsts.IsDirty) + { + foreach (RODbROFst tmp in _RODbROFsts) + { + if (tmp.IsDirty) refreshRODbROFsts.Add(tmp); + } + } + if (_RODbROImages != null && _RODbROImages.IsDirty) + { + foreach (RODbROImage tmp in _RODbROImages) + { + if (tmp.IsDirty) refreshRODbROImages.Add(tmp); + } + } + if (_RODbRoUsages != null && _RODbRoUsages.IsDirty) + { + foreach (RODbRoUsage tmp in _RODbRoUsages) + { + if (tmp.IsDirty) refreshRODbRoUsages.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshRODbs = new List(); + _RefreshRODbROFsts = new List(); + _RefreshRODbROImages = new List(); + _RefreshRODbRoUsages = new List(); + AddToRefreshList(_RefreshRODbs, _RefreshRODbROFsts, _RefreshRODbROImages, _RefreshRODbRoUsages); + } + private void ProcessRefreshList() + { + foreach (RODb tmp in _RefreshRODbs) + { + RODbInfo.Refresh(tmp); + } + foreach (RODbROFst tmp in _RefreshRODbROFsts) + { + ROFstInfo.Refresh(tmp); + } + foreach (RODbROImage tmp in _RefreshRODbROImages) + { + ROImageInfo.Refresh(tmp); + } + foreach (RODbRoUsage tmp in _RefreshRODbRoUsages) + { + RoUsageInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RODb rODb) + { + if (!_CacheList.Contains(rODb)) _CacheList.Add(rODb); // In AddToCache + } + protected static void RemoveFromCache(RODb rODb) + { + while (_CacheList.Contains(rODb)) _CacheList.Remove(rODb); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RODb tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.RODbID.ToString())) + { + _CacheByPrimaryKey[tmp.RODbID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.RODbID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (RODb tmp in remove) + RemoveFromCache(tmp); + } + protected static RODb GetCachedByPrimaryKey(int rODbID) + { + ConvertListToDictionary(); + string key = rODbID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextRODbID = -1; + public static int NextRODbID + { + get { return _nextRODbID--; } + } + private int _RODbID; + [System.ComponentModel.DataObjectField(true, true)] + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbID; + } + } + private string _ROName = string.Empty; + /// + /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion + /// + public string ROName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROName != value) + { + _ROName = value; + PropertyHasChanged(); + } + } + } + private string _FolderPath = string.Empty; + /// + /// Path to the RO database + /// + public string FolderPath + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderPath; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FolderPath != value) + { + _FolderPath = value; + PropertyHasChanged(); + } + } + } + private string _DBConnectionString = string.Empty; + /// + /// Connection String - Default could just be the full path and name of the database + /// + public string DBConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBConnectionString; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_DBConnectionString != value) + { + _DBConnectionString = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbROFstCount = 0; + /// + /// Count of RODbROFsts for this RODb + /// + public int RODbROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbROFstCount; + } + } + private RODbROFsts _RODbROFsts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RODbROFstsConverter))] + public RODbROFsts RODbROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROFstCount > 0 && _RODbROFsts == null) + _RODbROFsts = RODbROFsts.GetByRODbID(RODbID); + else if (_RODbROFsts == null) + _RODbROFsts = RODbROFsts.New(); + return _RODbROFsts; + } + } + private int _RODbROImageCount = 0; + /// + /// Count of RODbROImages for this RODb + /// + public int RODbROImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbROImageCount; + } + } + private RODbROImages _RODbROImages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RODbROImagesConverter))] + public RODbROImages RODbROImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROImageCount > 0 && _RODbROImages == null) + _RODbROImages = RODbROImages.GetByRODbID(RODbID); + else if (_RODbROImages == null) + _RODbROImages = RODbROImages.New(); + return _RODbROImages; + } + } + private int _RODbRoUsageCount = 0; + /// + /// Count of RODbRoUsages for this RODb + /// + public int RODbRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbRoUsageCount; + } + } + private RODbRoUsages _RODbRoUsages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RODbRoUsagesConverter))] + public RODbRoUsages RODbRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbRoUsageCount > 0 && _RODbRoUsages == null) + _RODbRoUsages = RODbRoUsages.GetByRODbID(RODbID); + else if (_RODbRoUsages == null) + _RODbRoUsages = RODbRoUsages.New(); + return _RODbRoUsages; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_RODbROFsts == null ? false : _RODbROFsts.IsDirty) || (_RODbROImages == null ? false : _RODbROImages.IsDirty) || (_RODbRoUsages == null ? false : _RODbRoUsages.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_RODbROFsts == null ? true : _RODbROFsts.IsValid) && (_RODbROImages == null ? true : _RODbROImages.IsValid) && (_RODbRoUsages == null ? true : _RODbRoUsages.IsValid); } + } + // TODO: Replace base RODb.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODb + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check RODb.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODb + protected override object GetIdValue() + { + return _RODbID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_RODbRoUsages != null && (hasBrokenRules = _RODbRoUsages.HasBrokenRules) != null) return hasBrokenRules; + if (_RODbROFsts != null && (hasBrokenRules = _RODbROFsts.HasBrokenRules) != null) return hasBrokenRules; + if (_RODbROImages != null && (hasBrokenRules = _RODbROImages.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROName", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FolderPath"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FolderPath", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "DBConnectionString"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("DBConnectionString", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _RODbExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _RODbExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowRead(ROName, ""); + //AuthorizationRules.AllowRead(FolderPath, ""); + //AuthorizationRules.AllowRead(DBConnectionString, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(ROName, ""); + //AuthorizationRules.AllowWrite(FolderPath, ""); + //AuthorizationRules.AllowWrite(DBConnectionString, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _RODbExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _RODbExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _RODbROFstCount; + usedByCount += _RODbROImageCount; + usedByCount += _RODbRoUsageCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _RODbUnique = 0; + protected static int RODbUnique + { get { return ++_RODbUnique; } } + private int _MyRODbUnique = RODbUnique; + public int MyRODbUnique + { get { return _MyRODbUnique; } } + protected RODb() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) + { + List listRODb = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items + while (listRODb.Contains(this)) listRODb.Remove(this); // Remove the item from the list + if (listRODb.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list + } + } + public static RODb New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RODb"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.New", ex); + } + } + public static RODb New(string rOName, string folderPath, string dBConnectionString) + { + RODb tmp = RODb.New(); + tmp.ROName = rOName; + tmp.FolderPath = folderPath; + tmp.DBConnectionString = dBConnectionString; + return tmp; + } + public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString) + { + RODb tmp = RODb.New(rOName, folderPath, dBConnectionString); + if (tmp.IsSavable) + { + RODb tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RODb New(string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID) + { + RODb tmp = RODb.New(); + tmp.ROName = rOName; + tmp.FolderPath = folderPath; + tmp.DBConnectionString = dBConnectionString; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static RODb MakeRODb(string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID) + { + RODb tmp = RODb.New(rOName, folderPath, dBConnectionString, dts, userID); + if (tmp.IsSavable) + { + RODb tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RODb Get(int rODbID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a RODb"); + try + { + RODb tmp = GetCachedByPrimaryKey(rODbID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rODbID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RODb + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.Get", ex); + } + } + public static RODb Get(SafeDataReader dr) + { + if (dr.Read()) return new RODb(dr); + return null; + } + internal RODb(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rODbID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RODb"); + try + { + DataPortal.Delete(new PKCriteria(rODbID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.Delete", ex); + } + } + public override RODb Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RODb"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RODb"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a RODb"); + try + { + BuildRefreshList(); + RODb rODb = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(rODb);//Refresh the item in AllList + ProcessRefreshList(); + return rODb; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _RODbID; + public int RODbID + { get { return _RODbID; } } + public PKCriteria(int rODbID) + { + _RODbID = rODbID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _RODbID = NextRODbID; + // Database Defaults + _DTS = _RODbExtension.DefaultDTS; + _UserID = _RODbExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.ReadData", GetHashCode()); + try + { + _RODbID = dr.GetInt32("RODbID"); + _ROName = dr.GetString("ROName"); + _FolderPath = dr.GetString("FolderPath"); + _DBConnectionString = dr.GetString("DBConnectionString"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbROFstCount = dr.GetInt32("ROFstCount"); + _RODbROImageCount = dr.GetInt32("ROImageCount"); + _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRODb"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _RODbROFsts = RODbROFsts.Get(dr); + // load child objects + dr.NextResult(); + _RODbROImages = RODbROImages.Get(dr); + // load child objects + dr.NextResult(); + _RODbRoUsages = RODbRoUsages.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRODb"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROName", _ROName); + cm.Parameters.AddWithValue("@FolderPath", _FolderPath); + cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); + param_RODbID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RODbID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _RODbID = (int)cm.Parameters["@newRODbID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_RODbRoUsages != null) _RODbRoUsages.Update(this); + if (_RODbROFsts != null) _RODbROFsts.Update(this); + if (_RODbROImages != null) _RODbROImages.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRODb"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROName", rOName); + cm.Parameters.AddWithValue("@FolderPath", folderPath); + cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_RODbID = new SqlParameter("@newRODbID", SqlDbType.Int); + param_RODbID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RODbID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + rODbID = (int)cm.Parameters["@newRODbID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Add", ex); + throw new DbCslaException("RODb.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] RODb.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRODb"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RODbID", _RODbID); + cm.Parameters.AddWithValue("@ROName", _ROName); + cm.Parameters.AddWithValue("@FolderPath", _FolderPath); + cm.Parameters.AddWithValue("@DBConnectionString", _DBConnectionString); + 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); + // TODO: 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 (_RODbRoUsages != null) _RODbRoUsages.Update(this); + if (_RODbROFsts != null) _RODbROFsts.Update(this); + if (_RODbROImages != null) _RODbROImages.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = RODb.Add(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _DTS, _UserID); + else + _LastChanged = RODb.Update(cn, ref _RODbID, _ROName, _FolderPath, _DBConnectionString, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_RODbRoUsages != null) _RODbRoUsages.Update(this); + if (_RODbROFsts != null) _RODbROFsts.Update(this); + if (_RODbROImages != null) _RODbROImages.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rODbID, string rOName, string folderPath, string dBConnectionString, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRODb"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", rODbID); + cm.Parameters.AddWithValue("@ROName", rOName); + cm.Parameters.AddWithValue("@FolderPath", folderPath); + cm.Parameters.AddWithValue("@DBConnectionString", dBConnectionString); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Update", ex); + throw new DbCslaException("RODb.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_RODbID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRODb"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODb.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rODbID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRODb"; + // Input PK Fields + cm.Parameters.AddWithValue("@RODbID", rODbID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.Remove", ex); + throw new DbCslaException("RODb.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rODbID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rODbID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODb.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _RODbID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rODbID) + { + _RODbID = rODbID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODb.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsRODb"; + cm.Parameters.AddWithValue("@RODbID", _RODbID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODb.DataPortal_Execute", ex); + throw new DbCslaException("RODb.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + RODbExtension _RODbExtension = new RODbExtension(); + [Serializable()] + partial class RODbExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODb) + { + // Return the ToString value + return ((RODb)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbInfo.cs index d9887a02..ad776452 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbInfo.cs @@ -19,446 +19,434 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void RODbInfoEvent(object sender); - /// - /// RODbInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbInfoConverter))] - public partial class RODbInfo : ReadOnlyBase, IDisposable - { - public event RODbInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RODbInfo rODbInfo) - { - if (!_CacheList.Contains(rODbInfo)) _CacheList.Add(rODbInfo); // In AddToCache - } - protected static void RemoveFromCache(RODbInfo rODbInfo) - { - while (_CacheList.Contains(rODbInfo)) _CacheList.Remove(rODbInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (RODbInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.RODbID.ToString())) - { - _CacheByPrimaryKey[tmp.RODbID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.RODbID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (RODbInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(RODbInfoList lst) - { - foreach (RODbInfo item in lst) AddToCache(item); - } - protected static RODbInfo GetCachedByPrimaryKey(int rODbID) - { - ConvertListToDictionary(); - string key = rODbID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected RODb _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _RODbID; - [System.ComponentModel.DataObjectField(true, true)] - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - return _RODbID; - } - } - private string _ROName = string.Empty; - /// - /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion - /// - public string ROName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROName", true); - return _ROName; - } - } - private string _FolderPath = string.Empty; - /// - /// Path to the RO database - /// - public string FolderPath - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderPath", true); - return _FolderPath; - } - } - private string _DBConnectionString = string.Empty; - /// - /// Connection String - Default could just be the full path and name of the database - /// - public string DBConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DBConnectionString", true); - return _DBConnectionString; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _RODbROFstCount = 0; - /// - /// Count of RODbROFsts for this RODb - /// - public int RODbROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFstCount", true); - return _RODbROFstCount; - } - } - private ROFstInfoList _RODbROFsts = null; - [TypeConverter(typeof(ROFstInfoListConverter))] - public ROFstInfoList RODbROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROFsts", true); - if (_RODbROFstCount < 0 || (_RODbROFstCount > 0 && _RODbROFsts == null)) - _RODbROFsts = ROFstInfoList.GetByRODbID(_RODbID); - if (_RODbROFstCount < 0) - _RODbROFstCount = _RODbROFsts.Count; - return _RODbROFsts; - } - } - public void RefreshRODbROFsts() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) - foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) - tmp._RODbROFstCount = -1; // This will cause the data to be requeried - } - private int _RODbROImageCount = 0; - /// - /// Count of RODbROImages for this RODb - /// - public int RODbROImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImageCount", true); - return _RODbROImageCount; - } - } - private ROImageInfoList _RODbROImages = null; - [TypeConverter(typeof(ROImageInfoListConverter))] - public ROImageInfoList RODbROImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbROImages", true); - if (_RODbROImageCount < 0 || (_RODbROImageCount > 0 && _RODbROImages == null)) - _RODbROImages = ROImageInfoList.GetByRODbID(_RODbID); - if (_RODbROImageCount < 0) - _RODbROImageCount = _RODbROImages.Count; - return _RODbROImages; - } - } - public void RefreshRODbROImages() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) - foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) - tmp._RODbROImageCount = -1; // This will cause the data to be requeried - } - private int _RODbRoUsageCount = 0; - /// - /// Count of RODbRoUsages for this RODb - /// - public int RODbRoUsageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsageCount", true); - return _RODbRoUsageCount; - } - } - private RoUsageInfoList _RODbRoUsages = null; - [TypeConverter(typeof(RoUsageInfoListConverter))] - public RoUsageInfoList RODbRoUsages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbRoUsages", true); - if (_RODbRoUsageCount < 0 || (_RODbRoUsageCount > 0 && _RODbRoUsages == null)) - _RODbRoUsages = RoUsageInfoList.GetByRODbID(_RODbID); - if (_RODbRoUsageCount < 0) - _RODbRoUsageCount = _RODbRoUsages.Count; - return _RODbRoUsages; - } - } - public void RefreshRODbRoUsages() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) - foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) - tmp._RODbRoUsageCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base RODbInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check RODbInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbInfo - protected override object GetIdValue() - { - return _RODbID; - } - #endregion - #region Factory Methods - private static int _RODbInfoUnique = 0; - private static int RODbInfoUnique - { get { return ++_RODbInfoUnique; } } - private int _MyRODbInfoUnique = RODbInfoUnique; - public int MyRODbInfoUnique - { get { return _MyRODbInfoUnique; } } - protected RODbInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) return; - List listRODbInfo = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items - while (listRODbInfo.Contains(this)) listRODbInfo.Remove(this); // Remove the item from the list - if (listRODbInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list - } - public virtual RODb Get() - { - return _Editable = RODb.Get(_RODbID); - } - public static void Refresh(RODb tmp) - { - string key = tmp.RODbID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RODbInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODb tmp) - { - _ROName = tmp.ROName; - _FolderPath = tmp.FolderPath; - _DBConnectionString = tmp.DBConnectionString; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _RODbInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static RODbInfo Get(int rODbID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a RODb"); - try - { - RODbInfo tmp = GetCachedByPrimaryKey(rODbID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rODbID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RODbInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RODbInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal RODbInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.Constructor", ex); - throw new DbCslaException("RODbInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _RODbID; - public int RODbID - { get { return _RODbID; } } - public PKCriteria(int rODbID) - { - _RODbID = rODbID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.ReadData", GetHashCode()); - try - { - _RODbID = dr.GetInt32("RODbID"); - _ROName = dr.GetString("ROName"); - _FolderPath = dr.GetString("FolderPath"); - _DBConnectionString = dr.GetString("DBConnectionString"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _RODbROFstCount = dr.GetInt32("ROFstCount"); - _RODbROImageCount = dr.GetInt32("ROImageCount"); - _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODbInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRODb"; - cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RODbInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - RODbInfoExtension _RODbInfoExtension = new RODbInfoExtension(); - [Serializable()] - partial class RODbInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(RODbInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class RODbInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbInfo) - { - // Return the ToString value - return ((RODbInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void RODbInfoEvent(object sender); + /// + /// RODbInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbInfoConverter))] + public partial class RODbInfo : ReadOnlyBase, IDisposable + { + public event RODbInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RODbInfo rODbInfo) + { + if (!_CacheList.Contains(rODbInfo)) _CacheList.Add(rODbInfo); // In AddToCache + } + protected static void RemoveFromCache(RODbInfo rODbInfo) + { + while (_CacheList.Contains(rODbInfo)) _CacheList.Remove(rODbInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RODbInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.RODbID.ToString())) + { + _CacheByPrimaryKey[tmp.RODbID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.RODbID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (RODbInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(RODbInfoList lst) + { + foreach (RODbInfo item in lst) AddToCache(item); + } + protected static RODbInfo GetCachedByPrimaryKey(int rODbID) + { + ConvertListToDictionary(); + string key = rODbID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected RODb _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _RODbID; + [System.ComponentModel.DataObjectField(true, true)] + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbID; + } + } + private string _ROName = string.Empty; + /// + /// Hook for future - to allow the user to select multiple RO Databases assocaiated with on DocVersion + /// + public string ROName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROName; + } + } + private string _FolderPath = string.Empty; + /// + /// Path to the RO database + /// + public string FolderPath + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FolderPath; + } + } + private string _DBConnectionString = string.Empty; + /// + /// Connection String - Default could just be the full path and name of the database + /// + public string DBConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DBConnectionString; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _RODbROFstCount = 0; + /// + /// Count of RODbROFsts for this RODb + /// + public int RODbROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbROFstCount; + } + } + private ROFstInfoList _RODbROFsts = null; + [TypeConverter(typeof(ROFstInfoListConverter))] + public ROFstInfoList RODbROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROFstCount < 0 || (_RODbROFstCount > 0 && _RODbROFsts == null)) + _RODbROFsts = ROFstInfoList.GetByRODbID(_RODbID); + if (_RODbROFstCount < 0) + _RODbROFstCount = _RODbROFsts.Count; + return _RODbROFsts; + } + } + public void RefreshRODbROFsts() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) + foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) + tmp._RODbROFstCount = -1; // This will cause the data to be requeried + } + private int _RODbROImageCount = 0; + /// + /// Count of RODbROImages for this RODb + /// + public int RODbROImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbROImageCount; + } + } + private ROImageInfoList _RODbROImages = null; + [TypeConverter(typeof(ROImageInfoListConverter))] + public ROImageInfoList RODbROImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbROImageCount < 0 || (_RODbROImageCount > 0 && _RODbROImages == null)) + _RODbROImages = ROImageInfoList.GetByRODbID(_RODbID); + if (_RODbROImageCount < 0) + _RODbROImageCount = _RODbROImages.Count; + return _RODbROImages; + } + } + public void RefreshRODbROImages() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) + foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) + tmp._RODbROImageCount = -1; // This will cause the data to be requeried + } + private int _RODbRoUsageCount = 0; + /// + /// Count of RODbRoUsages for this RODb + /// + public int RODbRoUsageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RODbRoUsageCount; + } + } + private RoUsageInfoList _RODbRoUsages = null; + [TypeConverter(typeof(RoUsageInfoListConverter))] + public RoUsageInfoList RODbRoUsages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RODbRoUsageCount < 0 || (_RODbRoUsageCount > 0 && _RODbRoUsages == null)) + _RODbRoUsages = RoUsageInfoList.GetByRODbID(_RODbID); + if (_RODbRoUsageCount < 0) + _RODbRoUsageCount = _RODbRoUsages.Count; + return _RODbRoUsages; + } + } + public void RefreshRODbRoUsages() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RODbID.ToString())) + foreach (RODbInfo tmp in _CacheByPrimaryKey[_RODbID.ToString()]) + tmp._RODbRoUsageCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base RODbInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check RODbInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbInfo + protected override object GetIdValue() + { + return _RODbID; + } + #endregion + #region Factory Methods + private static int _RODbInfoUnique = 0; + private static int RODbInfoUnique + { get { return ++_RODbInfoUnique; } } + private int _MyRODbInfoUnique = RODbInfoUnique; + public int MyRODbInfoUnique + { get { return _MyRODbInfoUnique; } } + protected RODbInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(RODbID.ToString())) return; + List listRODbInfo = _CacheByPrimaryKey[RODbID.ToString()]; // Get the list of items + while (listRODbInfo.Contains(this)) listRODbInfo.Remove(this); // Remove the item from the list + if (listRODbInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(RODbID.ToString()); // remove the list + } + public virtual RODb Get() + { + return _Editable = RODb.Get(_RODbID); + } + public static void Refresh(RODb tmp) + { + string key = tmp.RODbID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RODbInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODb tmp) + { + _ROName = tmp.ROName; + _FolderPath = tmp.FolderPath; + _DBConnectionString = tmp.DBConnectionString; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RODbInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static RODbInfo Get(int rODbID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a RODb"); + try + { + RODbInfo tmp = GetCachedByPrimaryKey(rODbID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rODbID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RODbInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RODbInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RODbInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.Constructor", ex); + throw new DbCslaException("RODbInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _RODbID; + public int RODbID + { get { return _RODbID; } } + public PKCriteria(int rODbID) + { + _RODbID = rODbID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.ReadData", GetHashCode()); + try + { + _RODbID = dr.GetInt32("RODbID"); + _ROName = dr.GetString("ROName"); + _FolderPath = dr.GetString("FolderPath"); + _DBConnectionString = dr.GetString("DBConnectionString"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _RODbROFstCount = dr.GetInt32("ROFstCount"); + _RODbROImageCount = dr.GetInt32("ROImageCount"); + _RODbRoUsageCount = dr.GetInt32("RoUsageCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODbInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRODb"; + cm.Parameters.AddWithValue("@RODbID", criteria.RODbID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RODbInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RODbInfoExtension _RODbInfoExtension = new RODbInfoExtension(); + [Serializable()] + partial class RODbInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RODbInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RODbInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbInfo) + { + // Return the ToString value + return ((RODbInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROFst.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROFst.cs index ce6e5e66..ac88ec3d 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROFst.cs @@ -19,353 +19,345 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODbROFst Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbROFstConverter))] - public partial class RODbROFst : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - } - private byte[] _ROFST; - public byte[] ROFST - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFST", true); - return _ROFST; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROFST", true); - if (_ROFST != value) - { - _ROFST = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check RODbROFst.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbROFst - protected override object GetIdValue() - { - return _ROFstID; - } - // TODO: Replace base RODbROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbROFst - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(ROFST, ""); - //AuthorizationRules.AllowWrite(ROFST, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static RODbROFst New(byte[] rofst) - { - return new RODbROFst(rofst); - } - internal static RODbROFst Get(SafeDataReader dr) - { - return new RODbROFst(dr); - } - public RODbROFst() - { - MarkAsChild(); - _ROFstID = ROFst.NextROFstID; - _DTS = _RODbROFstExtension.DefaultDTS; - _UserID = _RODbROFstExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RODbROFst(byte[] rofst) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _RODbROFstExtension.DefaultDTS; - _UserID = _RODbROFstExtension.DefaultUserID; - _ROFST = rofst; - ValidationRules.CheckRules(); - } - internal RODbROFst(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROFst.FetchDR", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _ROFST = (byte[])dr.GetValue("ROFST"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROFst.FetchDR", ex); - throw new DbCslaException("RODbROFst.Fetch", ex); - } - MarkOld(); - } - internal void Insert(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFst.Add(cn, ref _ROFstID, myRODb, _ROFST, _DTS, _UserID); - MarkOld(); - } - internal void Update(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFst.Update(cn, ref _ROFstID, myRODb, _ROFST, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(RODb myRODb) - { - // 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"]; - ROFst.Remove(cn, _ROFstID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RODbROFstExtension _RODbROFstExtension = new RODbROFstExtension(); - [Serializable()] - partial class RODbROFstExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbROFstConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbROFst) - { - // Return the ToString value - return ((RODbROFst)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODbROFst Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbROFstConverter))] + public partial class RODbROFst : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + } + private byte[] _ROFST; + public byte[] ROFST + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFST; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ROFST != value) + { + _ROFST = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check RODbROFst.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbROFst + protected override object GetIdValue() + { + return _ROFstID; + } + // TODO: Replace base RODbROFst.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbROFst + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(ROFST, ""); + //AuthorizationRules.AllowWrite(ROFST, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static RODbROFst New(byte[] rofst) + { + return new RODbROFst(rofst); + } + internal static RODbROFst Get(SafeDataReader dr) + { + return new RODbROFst(dr); + } + public RODbROFst() + { + MarkAsChild(); + _ROFstID = ROFst.NextROFstID; + _DTS = _RODbROFstExtension.DefaultDTS; + _UserID = _RODbROFstExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RODbROFst(byte[] rofst) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _RODbROFstExtension.DefaultDTS; + _UserID = _RODbROFstExtension.DefaultUserID; + _ROFST = rofst; + ValidationRules.CheckRules(); + } + internal RODbROFst(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROFst.FetchDR", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _ROFST = (byte[])dr.GetValue("ROFST"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROFst.FetchDR", ex); + throw new DbCslaException("RODbROFst.Fetch", ex); + } + MarkOld(); + } + internal void Insert(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFst.Add(cn, ref _ROFstID, myRODb, _ROFST, _DTS, _UserID); + MarkOld(); + } + internal void Update(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFst.Update(cn, ref _ROFstID, myRODb, _ROFST, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(RODb myRODb) + { + // 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"]; + ROFst.Remove(cn, _ROFstID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RODbROFstExtension _RODbROFstExtension = new RODbROFstExtension(); + [Serializable()] + partial class RODbROFstExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbROFstConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbROFst) + { + // Return the ToString value + return ((RODbROFst)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROImage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROImage.cs index eacd9a3c..dd0f9a67 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbROImage.cs @@ -19,383 +19,373 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODbROImage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbROImageConverter))] - public partial class RODbROImage : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImage _MyROImage; - [System.ComponentModel.DataObjectField(true, true)] - public ROImage MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.Get(_ImageID); - return _MyROImage; - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileName", true); - if (value == null) value = string.Empty; - if (_FileName != value) - { - _FileName = value; - PropertyHasChanged(); - } - } - } - private byte[] _Content; - public byte[] Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content", true); - return _Content; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Content", true); - if (_Content != value) - { - _Content = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check RODbROImage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbROImage - protected override object GetIdValue() - { - return _ImageID; - } - // TODO: Replace base RODbROImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbROImage - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ImageID, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowRead(Content, ""); - //AuthorizationRules.AllowWrite(Content, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static RODbROImage New(string fileName, byte[] content) - { - return new RODbROImage(fileName, content); - } - internal static RODbROImage Get(SafeDataReader dr) - { - return new RODbROImage(dr); - } - public RODbROImage() - { - MarkAsChild(); - _ImageID = ROImage.NextImageID; - _DTS = _RODbROImageExtension.DefaultDTS; - _UserID = _RODbROImageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RODbROImage(string fileName, byte[] content) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _RODbROImageExtension.DefaultDTS; - _UserID = _RODbROImageExtension.DefaultUserID; - _FileName = fileName; - _Content = content; - ValidationRules.CheckRules(); - } - internal RODbROImage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROImage.FetchDR", GetHashCode()); - try - { - _ImageID = dr.GetInt32("ImageID"); - _FileName = dr.GetString("FileName"); - _Content = (byte[])dr.GetValue("Content"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROImage.FetchDR", ex); - throw new DbCslaException("RODbROImage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROImage.Add(cn, ref _ImageID, myRODb, _FileName, _Content, _DTS, _UserID); - MarkOld(); - } - internal void Update(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROImage.Update(cn, ref _ImageID, myRODb, _FileName, _Content, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(RODb myRODb) - { - // 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"]; - ROImage.Remove(cn, _ImageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RODbROImageExtension _RODbROImageExtension = new RODbROImageExtension(); - [Serializable()] - partial class RODbROImageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbROImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbROImage) - { - // Return the ToString value - return ((RODbROImage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODbROImage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbROImageConverter))] + public partial class RODbROImage : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImage _MyROImage; + [System.ComponentModel.DataObjectField(true, true)] + public ROImage MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.Get(_ImageID); + return _MyROImage; + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileName != value) + { + _FileName = value; + PropertyHasChanged(); + } + } + } + private byte[] _Content; + public byte[] Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Content != value) + { + _Content = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check RODbROImage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbROImage + protected override object GetIdValue() + { + return _ImageID; + } + // TODO: Replace base RODbROImage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbROImage + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ImageID, ""); + //AuthorizationRules.AllowRead(FileName, ""); + //AuthorizationRules.AllowWrite(FileName, ""); + //AuthorizationRules.AllowRead(Content, ""); + //AuthorizationRules.AllowWrite(Content, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static RODbROImage New(string fileName, byte[] content) + { + return new RODbROImage(fileName, content); + } + internal static RODbROImage Get(SafeDataReader dr) + { + return new RODbROImage(dr); + } + public RODbROImage() + { + MarkAsChild(); + _ImageID = ROImage.NextImageID; + _DTS = _RODbROImageExtension.DefaultDTS; + _UserID = _RODbROImageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RODbROImage(string fileName, byte[] content) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _RODbROImageExtension.DefaultDTS; + _UserID = _RODbROImageExtension.DefaultUserID; + _FileName = fileName; + _Content = content; + ValidationRules.CheckRules(); + } + internal RODbROImage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbROImage.FetchDR", GetHashCode()); + try + { + _ImageID = dr.GetInt32("ImageID"); + _FileName = dr.GetString("FileName"); + _Content = (byte[])dr.GetValue("Content"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbROImage.FetchDR", ex); + throw new DbCslaException("RODbROImage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROImage.Add(cn, ref _ImageID, myRODb, _FileName, _Content, _DTS, _UserID); + MarkOld(); + } + internal void Update(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROImage.Update(cn, ref _ImageID, myRODb, _FileName, _Content, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(RODb myRODb) + { + // 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"]; + ROImage.Remove(cn, _ImageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RODbROImageExtension _RODbROImageExtension = new RODbROImageExtension(); + [Serializable()] + partial class RODbROImageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbROImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbROImage) + { + // Return the ToString value + return ((RODbROImage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbRoUsage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbRoUsage.cs index fb2627fe..6db52d37 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbRoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RODbRoUsage.cs @@ -19,526 +19,506 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RODbRoUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RODbRoUsageConverter))] - public partial class RODbRoUsage : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; - return _ROUsageID; - } - } - private RoUsage _MyRoUsage; - [System.ComponentModel.DataObjectField(true, true)] - public RoUsage MyRoUsage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRoUsage", true); - if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); - return _MyRoUsage; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - PropertyHasChanged(); - } - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Content_Number = string.Empty; - public string Content_Number - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Number", true); - return _Content_Number; - } - } - private string _Content_Text = string.Empty; - public string Content_Text - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Text", true); - return _Content_Text; - } - } - private int? _Content_Type; - /// - /// 0 - Procedure, 10000 - Section, 20000 Step - /// - public int? Content_Type - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Type", true); - return _Content_Type; - } - } - private int? _Content_FormatID; - public int? Content_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_FormatID", true); - return _Content_FormatID; - } - } - private string _Content_Config = string.Empty; - public string Content_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_Config", true); - return _Content_Config; - } - } - private DateTime _Content_DTS = new DateTime(); - public DateTime Content_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_DTS", true); - return _Content_DTS; - } - } - private string _Content_UserID = string.Empty; - public string Content_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content_UserID", true); - return _Content_UserID; - } - } - // TODO: Check RODbRoUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RODbRoUsage - protected override object GetIdValue() - { - return _ROUsageID; - } - // TODO: Replace base RODbRoUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RODbRoUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: Add other validation rules - } - private static bool MyContentRequired(RODbRoUsage target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROUsageID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static RODbRoUsage New(string roid) - { - return new RODbRoUsage(roid); - } - internal static RODbRoUsage Get(SafeDataReader dr) - { - return new RODbRoUsage(dr); - } - public RODbRoUsage() - { - MarkAsChild(); - _ROUsageID = RoUsage.NextROUsageID; - _ContentID = _RODbRoUsageExtension.DefaultContentID; - _DTS = _RODbRoUsageExtension.DefaultDTS; - _UserID = _RODbRoUsageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private RODbRoUsage(string roid) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _ContentID = _RODbRoUsageExtension.DefaultContentID; - _DTS = _RODbRoUsageExtension.DefaultDTS; - _UserID = _RODbRoUsageExtension.DefaultUserID; - _ROID = roid; - ValidationRules.CheckRules(); - } - internal RODbRoUsage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbRoUsage.FetchDR", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ContentID = dr.GetInt32("ContentID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Content_Number = dr.GetString("Content_Number"); - _Content_Text = dr.GetString("Content_Text"); - _Content_Type = (int?)dr.GetValue("Content_Type"); - _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); - _Content_Config = dr.GetString("Content_Config"); - _Content_DTS = dr.GetDateTime("Content_DTS"); - _Content_UserID = dr.GetString("Content_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbRoUsage.FetchDR", ex); - throw new DbCslaException("RODbRoUsage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, myRODb); - MarkOld(); - } - internal void Update(RODb myRODb) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb); - MarkOld(); - } - internal void DeleteSelf(RODb myRODb) - { - // 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"]; - RoUsage.Remove(cn, _ROUsageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RODbRoUsageExtension _RODbRoUsageExtension = new RODbRoUsageExtension(); - [Serializable()] - partial class RODbRoUsageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultContentID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RODbRoUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RODbRoUsage) - { - // Return the ToString value - return ((RODbRoUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RODbRoUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RODbRoUsageConverter))] + public partial class RODbRoUsage : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage != null) _ROUsageID = _MyRoUsage.ROUsageID; + return _ROUsageID; + } + } + private RoUsage _MyRoUsage; + [System.ComponentModel.DataObjectField(true, true)] + public RoUsage MyRoUsage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRoUsage == null && _ROUsageID != 0) _MyRoUsage = RoUsage.Get(_ROUsageID); + return _MyRoUsage; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + PropertyHasChanged(); + } + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Content_Number = string.Empty; + public string Content_Number + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Number; + } + } + private string _Content_Text = string.Empty; + public string Content_Text + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Text; + } + } + private int? _Content_Type; + /// + /// 0 - Procedure, 10000 - Section, 20000 Step + /// + public int? Content_Type + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Type; + } + } + private int? _Content_FormatID; + public int? Content_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_FormatID; + } + } + private string _Content_Config = string.Empty; + public string Content_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_Config; + } + } + private DateTime _Content_DTS = new DateTime(); + public DateTime Content_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_DTS; + } + } + private string _Content_UserID = string.Empty; + public string Content_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content_UserID; + } + } + // TODO: Check RODbRoUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RODbRoUsage + protected override object GetIdValue() + { + return _ROUsageID; + } + // TODO: Replace base RODbRoUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RODbRoUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: Add other validation rules + } + private static bool MyContentRequired(RODbRoUsage target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROUsageID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static RODbRoUsage New(string roid) + { + return new RODbRoUsage(roid); + } + internal static RODbRoUsage Get(SafeDataReader dr) + { + return new RODbRoUsage(dr); + } + public RODbRoUsage() + { + MarkAsChild(); + _ROUsageID = RoUsage.NextROUsageID; + _ContentID = _RODbRoUsageExtension.DefaultContentID; + _DTS = _RODbRoUsageExtension.DefaultDTS; + _UserID = _RODbRoUsageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private RODbRoUsage(string roid) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _ContentID = _RODbRoUsageExtension.DefaultContentID; + _DTS = _RODbRoUsageExtension.DefaultDTS; + _UserID = _RODbRoUsageExtension.DefaultUserID; + _ROID = roid; + ValidationRules.CheckRules(); + } + internal RODbRoUsage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RODbRoUsage.FetchDR", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ContentID = dr.GetInt32("ContentID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Content_Number = dr.GetString("Content_Number"); + _Content_Text = dr.GetString("Content_Text"); + _Content_Type = (int?)dr.GetValue("Content_Type"); + _Content_FormatID = (int?)dr.GetValue("Content_FormatID"); + _Content_Config = dr.GetString("Content_Config"); + _Content_DTS = dr.GetDateTime("Content_DTS"); + _Content_UserID = dr.GetString("Content_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RODbRoUsage.FetchDR", ex); + throw new DbCslaException("RODbRoUsage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, myRODb); + MarkOld(); + } + internal void Update(RODb myRODb) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged, myRODb); + MarkOld(); + } + internal void DeleteSelf(RODb myRODb) + { + // 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"]; + RoUsage.Remove(cn, _ROUsageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RODbRoUsageExtension _RODbRoUsageExtension = new RODbRoUsageExtension(); + [Serializable()] + partial class RODbRoUsageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultContentID + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RODbRoUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RODbRoUsage) + { + // Return the ToString value + return ((RODbRoUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFst.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFst.cs index f4d91041..f3e4d7c5 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFst.cs @@ -20,1067 +20,1053 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROFst Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstConverter))] - public partial class ROFst : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshROFsts = new List(); - private List _RefreshROFstDocVersionROFsts = new List(); - private List _RefreshROFstROFstImages = new List(); - private void AddToRefreshList(List refreshROFsts, List refreshROFstDocVersionROFsts, List refreshROFstROFstImages) - { - if (IsDirty) - refreshROFsts.Add(this); - if (_ROFstDocVersionROFsts != null && _ROFstDocVersionROFsts.IsDirty) - { - foreach (ROFstDocVersionROFst tmp in _ROFstDocVersionROFsts) - { - if (tmp.IsDirty) refreshROFstDocVersionROFsts.Add(tmp); - } - } - if (_ROFstROFstImages != null && _ROFstROFstImages.IsDirty) - { - foreach (ROFstROFstImage tmp in _ROFstROFstImages) - { - if (tmp.IsDirty) refreshROFstROFstImages.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshROFsts = new List(); - _RefreshROFstDocVersionROFsts = new List(); - _RefreshROFstROFstImages = new List(); - AddToRefreshList(_RefreshROFsts, _RefreshROFstDocVersionROFsts, _RefreshROFstROFstImages); - } - private void ProcessRefreshList() - { - foreach (ROFst tmp in _RefreshROFsts) - { - ROFstInfo.Refresh(tmp); - if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); - } - foreach (ROFstDocVersionROFst tmp in _RefreshROFstDocVersionROFsts) - { - DocVersionROFstInfo.Refresh(this, tmp); - } - foreach (ROFstROFstImage tmp in _RefreshROFstROFstImages) - { - ROFstImageInfo.Refresh(this, tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROFst rOFst) - { - if (!_CacheList.Contains(rOFst)) _CacheList.Add(rOFst); // In AddToCache - } - protected static void RemoveFromCache(ROFst rOFst) - { - while (_CacheList.Contains(rOFst)) _CacheList.Remove(rOFst); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ROFst tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString())) - { - _CacheByPrimaryKey[tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ROFst tmp in remove) - RemoveFromCache(tmp); - } - protected static ROFst GetCachedByPrimaryKey(int rOFstID) - { - ConvertListToDictionary(); - string key = rOFstID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextROFstID = -1; - public static int NextROFstID - { - get { return _nextROFstID--; } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - return _ROFstID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - PropertyHasChanged(); - } - } - } - private byte[] _ROFST; - public byte[] ROFST - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFST", true); - return _ROFST; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROFST", true); - if (_ROFST != value) - { - _ROFST = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ROFstDocVersionROFstCount = 0; - /// - /// Count of ROFstDocVersionROFsts for this ROFst - /// - public int ROFstDocVersionROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstDocVersionROFstCount", true); - return _ROFstDocVersionROFstCount; - } - } - private ROFstDocVersionROFsts _ROFstDocVersionROFsts = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ROFstDocVersionROFstsConverter))] - public ROFstDocVersionROFsts ROFstDocVersionROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstDocVersionROFsts", true); - // TODO: See if this fixed after docversion changes. -// if (_ROFstDocVersionROFstCount > 0 && _ROFstDocVersionROFsts == null) - _ROFstDocVersionROFsts = ROFstDocVersionROFsts.GetByROFstID(ROFstID); - // TODO: This should be uncommented after docversion changes: - //else if (_ROFstDocVersionROFsts == null) - // _ROFstDocVersionROFsts = ROFstDocVersionROFsts.New(); - return _ROFstDocVersionROFsts; - } - } - private int _ROFstROFstImageCount = 0; - /// - /// Count of ROFstROFstImages for this ROFst - /// - public int ROFstROFstImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstROFstImageCount", true); - return _ROFstROFstImageCount; - } - } - private ROFstROFstImages _ROFstROFstImages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ROFstROFstImagesConverter))] - public ROFstROFstImages ROFstROFstImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstROFstImages", true); - if (_ROFstROFstImageCount > 0 && _ROFstROFstImages == null) - _ROFstROFstImages = ROFstROFstImages.GetByROFstID(ROFstID); - else if (_ROFstROFstImages == null) - _ROFstROFstImages = ROFstROFstImages.New(); - return _ROFstROFstImages; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_ROFstDocVersionROFsts == null ? false : _ROFstDocVersionROFsts.IsDirty) || (_ROFstROFstImages == null ? false : _ROFstROFstImages.IsDirty) || (_MyRODb == null ? false : _MyRODb.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ROFstDocVersionROFsts == null ? true : _ROFstDocVersionROFsts.IsValid) && (_ROFstROFstImages == null ? true : _ROFstROFstImages.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } - } - // TODO: Replace base ROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFst - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ROFst.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFst - protected override object GetIdValue() - { - return _ROFstID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ROFstDocVersionROFsts != null && (hasBrokenRules = _ROFstDocVersionROFsts.HasBrokenRules) != null) return hasBrokenRules; - if (_ROFstROFstImages != null && (hasBrokenRules = _ROFstROFstImages.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ROFstExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ROFstExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyRODbRequired(ROFst target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowRead(ROFST, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - //AuthorizationRules.AllowWrite(ROFST, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ROFstExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ROFstExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ROFstDocVersionROFstCount; - usedByCount += _ROFstROFstImageCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ROFstUnique = 0; - protected static int ROFstUnique - { get { return ++_ROFstUnique; } } - private int _MyROFstUnique = ROFstUnique; - public int MyROFstUnique - { get { return _MyROFstUnique; } } - protected ROFst() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) - { - List listROFst = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items - while (listROFst.Contains(this)) listROFst.Remove(this); // Remove the item from the list - if (listROFst.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list - } - } - public static ROFst New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFst"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.New", ex); - } - } - public static ROFst New(RODb myRODb, byte[] rofst) - { - ROFst tmp = ROFst.New(); - tmp.MyRODb = myRODb; - tmp.ROFST = rofst; - return tmp; - } - public static ROFst MakeROFst(RODb myRODb, byte[] rofst) - { - ROFst tmp = ROFst.New(myRODb, rofst); - if (tmp.IsSavable) - { - ROFst tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROFst New(RODb myRODb, byte[] rofst, DateTime dts, string userID) - { - ROFst tmp = ROFst.New(); - tmp.MyRODb = myRODb; - tmp.ROFST = rofst; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static ROFst MakeROFst(RODb myRODb, byte[] rofst, DateTime dts, string userID) - { - ROFst tmp = ROFst.New(myRODb, rofst, dts, userID); - if (tmp.IsSavable) - { - ROFst tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROFst Get(int rOFstID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROFst"); - try - { - ROFst tmp = GetCachedByPrimaryKey(rOFstID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROFst - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.Get", ex); - } - } - public static ROFst Get(SafeDataReader dr) - { - if (dr.Read()) return new ROFst(dr); - return null; - } - internal ROFst(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rOFstID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFst"); - try - { - DataPortal.Delete(new PKCriteria(rOFstID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.Delete", ex); - } - } - public override ROFst Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFst"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFst"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ROFst"); - try - { - BuildRefreshList(); - ROFst rOFst = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(rOFst);//Refresh the item in AllList - ProcessRefreshList(); - return rOFst; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ROFstID = NextROFstID; - // Database Defaults - _DTS = _ROFstExtension.DefaultDTS; - _UserID = _ROFstExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.ReadData", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _RODbID = dr.GetInt32("RODbID"); - _ROFST = (byte[])dr.GetValue("ROFST"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROFstDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); - _ROFstROFstImageCount = dr.GetInt32("ROFstImageCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROFst"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ROFstDocVersionROFsts = ROFstDocVersionROFsts.Get(dr); - // load child objects - dr.NextResult(); - _ROFstROFstImages = ROFstROFstImages.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addROFst"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@ROFST", _ROFST); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - // Output Calculated Columns - SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); - param_ROFstID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROFstID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _ROFstID = (int)cm.Parameters["@newROFstID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_ROFstDocVersionROFsts != null) _ROFstDocVersionROFsts.Update(this); - if (_ROFstROFstImages != null) _ROFstROFstImages.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rOFstID, RODb myRODb, byte[] rofst, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addROFst"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); - cm.Parameters.AddWithValue("@ROFST", rofst); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UserID", userID); - // Output Calculated Columns - SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); - param_ROFstID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROFstID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - rOFstID = (int)cm.Parameters["@newROFstID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Add", ex); - throw new DbCslaException("ROFst.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ROFst.SQLUpdate", GetHashCode()); - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateROFst"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ROFstID", _ROFstID); - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@ROFST", _ROFST); - 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); - // TODO: 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 (_ROFstDocVersionROFsts != null) _ROFstDocVersionROFsts.Update(this); - if (_ROFstROFstImages != null) _ROFstROFstImages.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ROFst.Add(cn, ref _ROFstID, _MyRODb, _ROFST, _DTS, _UserID); - else - _LastChanged = ROFst.Update(cn, ref _ROFstID, _MyRODb, _ROFST, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_ROFstDocVersionROFsts != null) _ROFstDocVersionROFsts.Update(this); - if (_ROFstROFstImages != null) _ROFstROFstImages.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rOFstID, RODb myRODb, byte[] rofst, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateROFst"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROFstID", rOFstID); - cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); - cm.Parameters.AddWithValue("@ROFST", rofst); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Update", ex); - throw new DbCslaException("ROFst.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ROFstID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteROFst"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFst.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rOFstID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteROFst"; - // Input PK Fields - cm.Parameters.AddWithValue("@ROFstID", rOFstID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Remove", ex); - throw new DbCslaException("ROFst.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rOFstID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rOFstID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFst.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ROFstID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rOFstID) - { - _ROFstID = rOFstID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsROFst"; - cm.Parameters.AddWithValue("@ROFstID", _ROFstID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Execute", ex); - throw new DbCslaException("ROFst.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ROFstExtension _ROFstExtension = new ROFstExtension(); - [Serializable()] - partial class ROFstExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROFstConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFst) - { - // Return the ToString value - return ((ROFst)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ROFst Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstConverter))] + public partial class ROFst : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshROFsts = new List(); + private List _RefreshROFstDocVersionROFsts = new List(); + private List _RefreshROFstROFstImages = new List(); + private void AddToRefreshList(List refreshROFsts, List refreshROFstDocVersionROFsts, List refreshROFstROFstImages) + { + if (IsDirty) + refreshROFsts.Add(this); + if (_ROFstDocVersionROFsts != null && _ROFstDocVersionROFsts.IsDirty) + { + foreach (ROFstDocVersionROFst tmp in _ROFstDocVersionROFsts) + { + if (tmp.IsDirty) refreshROFstDocVersionROFsts.Add(tmp); + } + } + if (_ROFstROFstImages != null && _ROFstROFstImages.IsDirty) + { + foreach (ROFstROFstImage tmp in _ROFstROFstImages) + { + if (tmp.IsDirty) refreshROFstROFstImages.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshROFsts = new List(); + _RefreshROFstDocVersionROFsts = new List(); + _RefreshROFstROFstImages = new List(); + AddToRefreshList(_RefreshROFsts, _RefreshROFstDocVersionROFsts, _RefreshROFstROFstImages); + } + private void ProcessRefreshList() + { + foreach (ROFst tmp in _RefreshROFsts) + { + ROFstInfo.Refresh(tmp); + if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); + } + foreach (ROFstDocVersionROFst tmp in _RefreshROFstDocVersionROFsts) + { + DocVersionROFstInfo.Refresh(this, tmp); + } + foreach (ROFstROFstImage tmp in _RefreshROFstROFstImages) + { + ROFstImageInfo.Refresh(this, tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROFst rOFst) + { + if (!_CacheList.Contains(rOFst)) _CacheList.Add(rOFst); // In AddToCache + } + protected static void RemoveFromCache(ROFst rOFst) + { + while (_CacheList.Contains(rOFst)) _CacheList.Remove(rOFst); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ROFst tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString())) + { + _CacheByPrimaryKey[tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ROFst tmp in remove) + RemoveFromCache(tmp); + } + protected static ROFst GetCachedByPrimaryKey(int rOFstID) + { + ConvertListToDictionary(); + string key = rOFstID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextROFstID = -1; + public static int NextROFstID + { + get { return _nextROFstID--; } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + PropertyHasChanged(); + } + } + } + private byte[] _ROFST; + public byte[] ROFST + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFST; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_ROFST != value) + { + _ROFST = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ROFstDocVersionROFstCount = 0; + /// + /// Count of ROFstDocVersionROFsts for this ROFst + /// + public int ROFstDocVersionROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstDocVersionROFstCount; + } + } + private ROFstDocVersionROFsts _ROFstDocVersionROFsts = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ROFstDocVersionROFstsConverter))] + public ROFstDocVersionROFsts ROFstDocVersionROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + // TODO: See if this fixed after docversion changes. + // if (_ROFstDocVersionROFstCount > 0 && _ROFstDocVersionROFsts == null) + _ROFstDocVersionROFsts = ROFstDocVersionROFsts.GetByROFstID(ROFstID); + // TODO: This should be uncommented after docversion changes: + //else if (_ROFstDocVersionROFsts == null) + // _ROFstDocVersionROFsts = ROFstDocVersionROFsts.New(); + return _ROFstDocVersionROFsts; + } + } + private int _ROFstROFstImageCount = 0; + /// + /// Count of ROFstROFstImages for this ROFst + /// + public int ROFstROFstImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstROFstImageCount; + } + } + private ROFstROFstImages _ROFstROFstImages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ROFstROFstImagesConverter))] + public ROFstROFstImages ROFstROFstImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstROFstImageCount > 0 && _ROFstROFstImages == null) + _ROFstROFstImages = ROFstROFstImages.GetByROFstID(ROFstID); + else if (_ROFstROFstImages == null) + _ROFstROFstImages = ROFstROFstImages.New(); + return _ROFstROFstImages; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_ROFstDocVersionROFsts == null ? false : _ROFstDocVersionROFsts.IsDirty) || (_ROFstROFstImages == null ? false : _ROFstROFstImages.IsDirty) || (_MyRODb == null ? false : _MyRODb.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ROFstDocVersionROFsts == null ? true : _ROFstDocVersionROFsts.IsValid) && (_ROFstROFstImages == null ? true : _ROFstROFstImages.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } + } + // TODO: Replace base ROFst.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFst + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ROFst.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFst + protected override object GetIdValue() + { + return _ROFstID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ROFstDocVersionROFsts != null && (hasBrokenRules = _ROFstDocVersionROFsts.HasBrokenRules) != null) return hasBrokenRules; + if (_ROFstROFstImages != null && (hasBrokenRules = _ROFstROFstImages.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ROFstExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ROFstExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyRODbRequired(ROFst target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowRead(ROFST, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + //AuthorizationRules.AllowWrite(ROFST, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ROFstExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ROFstExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ROFstDocVersionROFstCount; + usedByCount += _ROFstROFstImageCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ROFstUnique = 0; + protected static int ROFstUnique + { get { return ++_ROFstUnique; } } + private int _MyROFstUnique = ROFstUnique; + public int MyROFstUnique + { get { return _MyROFstUnique; } } + protected ROFst() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) + { + List listROFst = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items + while (listROFst.Contains(this)) listROFst.Remove(this); // Remove the item from the list + if (listROFst.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list + } + } + public static ROFst New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROFst"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.New", ex); + } + } + public static ROFst New(RODb myRODb, byte[] rofst) + { + ROFst tmp = ROFst.New(); + tmp.MyRODb = myRODb; + tmp.ROFST = rofst; + return tmp; + } + public static ROFst MakeROFst(RODb myRODb, byte[] rofst) + { + ROFst tmp = ROFst.New(myRODb, rofst); + if (tmp.IsSavable) + { + ROFst tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROFst New(RODb myRODb, byte[] rofst, DateTime dts, string userID) + { + ROFst tmp = ROFst.New(); + tmp.MyRODb = myRODb; + tmp.ROFST = rofst; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static ROFst MakeROFst(RODb myRODb, byte[] rofst, DateTime dts, string userID) + { + ROFst tmp = ROFst.New(myRODb, rofst, dts, userID); + if (tmp.IsSavable) + { + ROFst tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROFst Get(int rOFstID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROFst"); + try + { + ROFst tmp = GetCachedByPrimaryKey(rOFstID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROFst + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.Get", ex); + } + } + public static ROFst Get(SafeDataReader dr) + { + if (dr.Read()) return new ROFst(dr); + return null; + } + internal ROFst(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rOFstID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROFst"); + try + { + DataPortal.Delete(new PKCriteria(rOFstID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.Delete", ex); + } + } + public override ROFst Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROFst"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROFst"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ROFst"); + try + { + BuildRefreshList(); + ROFst rOFst = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(rOFst);//Refresh the item in AllList + ProcessRefreshList(); + return rOFst; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + public PKCriteria(int rOFstID) + { + _ROFstID = rOFstID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ROFstID = NextROFstID; + // Database Defaults + _DTS = _ROFstExtension.DefaultDTS; + _UserID = _ROFstExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.ReadData", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _RODbID = dr.GetInt32("RODbID"); + _ROFST = (byte[])dr.GetValue("ROFST"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROFstDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); + _ROFstROFstImageCount = dr.GetInt32("ROFstImageCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROFst"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ROFstDocVersionROFsts = ROFstDocVersionROFsts.Get(dr); + // load child objects + dr.NextResult(); + _ROFstROFstImages = ROFstROFstImages.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addROFst"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@ROFST", _ROFST); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); + param_ROFstID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROFstID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _ROFstID = (int)cm.Parameters["@newROFstID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_ROFstDocVersionROFsts != null) _ROFstDocVersionROFsts.Update(this); + if (_ROFstROFstImages != null) _ROFstROFstImages.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rOFstID, RODb myRODb, byte[] rofst, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addROFst"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); + cm.Parameters.AddWithValue("@ROFST", rofst); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int); + param_ROFstID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROFstID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + rOFstID = (int)cm.Parameters["@newROFstID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Add", ex); + throw new DbCslaException("ROFst.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ROFst.SQLUpdate", GetHashCode()); + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateROFst"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ROFstID", _ROFstID); + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@ROFST", _ROFST); + 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); + // TODO: 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 (_ROFstDocVersionROFsts != null) _ROFstDocVersionROFsts.Update(this); + if (_ROFstROFstImages != null) _ROFstROFstImages.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ROFst.Add(cn, ref _ROFstID, _MyRODb, _ROFST, _DTS, _UserID); + else + _LastChanged = ROFst.Update(cn, ref _ROFstID, _MyRODb, _ROFST, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_ROFstDocVersionROFsts != null) _ROFstDocVersionROFsts.Update(this); + if (_ROFstROFstImages != null) _ROFstROFstImages.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rOFstID, RODb myRODb, byte[] rofst, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateROFst"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROFstID", rOFstID); + cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); + cm.Parameters.AddWithValue("@ROFST", rofst); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Update", ex); + throw new DbCslaException("ROFst.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ROFstID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteROFst"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFst.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rOFstID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteROFst"; + // Input PK Fields + cm.Parameters.AddWithValue("@ROFstID", rOFstID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.Remove", ex); + throw new DbCslaException("ROFst.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rOFstID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rOFstID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFst.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ROFstID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rOFstID) + { + _ROFstID = rOFstID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsROFst"; + cm.Parameters.AddWithValue("@ROFstID", _ROFstID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFst.DataPortal_Execute", ex); + throw new DbCslaException("ROFst.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ROFstExtension _ROFstExtension = new ROFstExtension(); + [Serializable()] + partial class ROFstExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROFstConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFst) + { + // Return the ToString value + return ((ROFst)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstDocVersionROFst.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstDocVersionROFst.cs index e73ec831..c1623abe 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstDocVersionROFst.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstDocVersionROFst.cs @@ -19,432 +19,417 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROFstDocVersionROFst Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstDocVersionROFstConverter))] - public partial class ROFstDocVersionROFst : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _VersionID; - [System.ComponentModel.DataObjectField(true, true)] - public int VersionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionID", true); - if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; - return _VersionID; - } - } - private DocVersion _MyDocVersion; - [System.ComponentModel.DataObjectField(true, true)] - public DocVersion MyDocVersion - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyDocVersion", true); - if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); - return _MyDocVersion; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _DocVersion_FolderID; - public int DocVersion_FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_FolderID", true); - return _DocVersion_FolderID; - } - } - private int _DocVersion_VersionType; - /// - /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) - /// - public int DocVersion_VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_VersionType", true); - return _DocVersion_VersionType; - } - } - private string _DocVersion_Name = string.Empty; - public string DocVersion_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_Name", true); - return _DocVersion_Name; - } - } - private string _DocVersion_Title = string.Empty; - public string DocVersion_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_Title", true); - return _DocVersion_Title; - } - } - private int? _DocVersion_ItemID; - public int? DocVersion_ItemID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_ItemID", true); - return _DocVersion_ItemID; - } - } - private int? _DocVersion_FormatID; - public int? DocVersion_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_FormatID", true); - return _DocVersion_FormatID; - } - } - private string _DocVersion_Config = string.Empty; - public string DocVersion_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_Config", true); - return _DocVersion_Config; - } - } - private DateTime _DocVersion_DTS = new DateTime(); - public DateTime DocVersion_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_DTS", true); - return _DocVersion_DTS; - } - } - private string _DocVersion_UserID = string.Empty; - public string DocVersion_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DocVersion_UserID", true); - return _DocVersion_UserID; - } - } - // TODO: Check ROFstDocVersionROFst.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstDocVersionROFst - protected override object GetIdValue() - { - return _VersionID; - } - // TODO: Replace base ROFstDocVersionROFst.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstDocVersionROFst - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(VersionID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ROFstDocVersionROFst New(DocVersion myDocVersion) - { - return new ROFstDocVersionROFst(myDocVersion); - } - internal static ROFstDocVersionROFst Get(SafeDataReader dr) - { - return new ROFstDocVersionROFst(dr); - } - public ROFstDocVersionROFst() - { - MarkAsChild(); + /// + /// ROFstDocVersionROFst Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstDocVersionROFstConverter))] + public partial class ROFstDocVersionROFst : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _VersionID; + [System.ComponentModel.DataObjectField(true, true)] + public int VersionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion != null) _VersionID = _MyDocVersion.VersionID; + return _VersionID; + } + } + private DocVersion _MyDocVersion; + [System.ComponentModel.DataObjectField(true, true)] + public DocVersion MyDocVersion + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyDocVersion == null && _VersionID != 0) _MyDocVersion = DocVersion.Get(_VersionID); + return _MyDocVersion; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _DocVersion_FolderID; + public int DocVersion_FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_FolderID; + } + } + private int _DocVersion_VersionType; + /// + /// 0 Working Draft, 1 Temporary, 128 Revision, 129 Approved (Greater than 127 - non editable) + /// + public int DocVersion_VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_VersionType; + } + } + private string _DocVersion_Name = string.Empty; + public string DocVersion_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_Name; + } + } + private string _DocVersion_Title = string.Empty; + public string DocVersion_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_Title; + } + } + private int? _DocVersion_ItemID; + public int? DocVersion_ItemID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_ItemID; + } + } + private int? _DocVersion_FormatID; + public int? DocVersion_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_FormatID; + } + } + private string _DocVersion_Config = string.Empty; + public string DocVersion_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_Config; + } + } + private DateTime _DocVersion_DTS = new DateTime(); + public DateTime DocVersion_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_DTS; + } + } + private string _DocVersion_UserID = string.Empty; + public string DocVersion_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DocVersion_UserID; + } + } + // TODO: Check ROFstDocVersionROFst.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstDocVersionROFst + protected override object GetIdValue() + { + return _VersionID; + } + // TODO: Replace base ROFstDocVersionROFst.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFstDocVersionROFst + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(VersionID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ROFstDocVersionROFst New(DocVersion myDocVersion) + { + return new ROFstDocVersionROFst(myDocVersion); + } + internal static ROFstDocVersionROFst Get(SafeDataReader dr) + { + return new ROFstDocVersionROFst(dr); + } + public ROFstDocVersionROFst() + { + MarkAsChild(); - _DTS = _ROFstDocVersionROFstExtension.DefaultDTS; - _UserID = _ROFstDocVersionROFstExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ROFstDocVersionROFst(DocVersion myDocVersion) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ROFstDocVersionROFstExtension.DefaultDTS; - _UserID = _ROFstDocVersionROFstExtension.DefaultUserID; - _MyDocVersion = myDocVersion; - ValidationRules.CheckRules(); - } - internal ROFstDocVersionROFst(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstDocVersionROFst.FetchDR", GetHashCode()); - try - { - _VersionID = dr.GetInt32("VersionID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _DocVersion_FolderID = dr.GetInt32("DocVersion_FolderID"); - _DocVersion_VersionType = dr.GetInt32("DocVersion_VersionType"); - _DocVersion_Name = dr.GetString("DocVersion_Name"); - _DocVersion_Title = dr.GetString("DocVersion_Title"); - _DocVersion_ItemID = (int?)dr.GetValue("DocVersion_ItemID"); - _DocVersion_FormatID = (int?)dr.GetValue("DocVersion_FormatID"); - _DocVersion_Config = dr.GetString("DocVersion_Config"); - _DocVersion_DTS = dr.GetDateTime("DocVersion_DTS"); - _DocVersion_UserID = dr.GetString("DocVersion_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstDocVersionROFst.FetchDR", ex); - throw new DbCslaException("ROFstDocVersionROFst.Fetch", ex); - } - MarkOld(); - } - internal void Insert(ROFst myROFst) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = DocVersionROFst.Add(cn, _MyDocVersion, myROFst, _DTS, _UserID); - MarkOld(); - } - internal void Update(ROFst myROFst) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = DocVersionROFst.Update(cn, _MyDocVersion, myROFst, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(ROFst myROFst) - { - // 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"]; - DocVersionROFst.Remove(cn, _VersionID, myROFst.ROFstID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ROFstDocVersionROFstExtension _ROFstDocVersionROFstExtension = new ROFstDocVersionROFstExtension(); - [Serializable()] - partial class ROFstDocVersionROFstExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROFstDocVersionROFstConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstDocVersionROFst) - { - // Return the ToString value - return ((ROFstDocVersionROFst)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _ROFstDocVersionROFstExtension.DefaultDTS; + _UserID = _ROFstDocVersionROFstExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ROFstDocVersionROFst(DocVersion myDocVersion) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ROFstDocVersionROFstExtension.DefaultDTS; + _UserID = _ROFstDocVersionROFstExtension.DefaultUserID; + _MyDocVersion = myDocVersion; + ValidationRules.CheckRules(); + } + internal ROFstDocVersionROFst(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstDocVersionROFst.FetchDR", GetHashCode()); + try + { + _VersionID = dr.GetInt32("VersionID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _DocVersion_FolderID = dr.GetInt32("DocVersion_FolderID"); + _DocVersion_VersionType = dr.GetInt32("DocVersion_VersionType"); + _DocVersion_Name = dr.GetString("DocVersion_Name"); + _DocVersion_Title = dr.GetString("DocVersion_Title"); + _DocVersion_ItemID = (int?)dr.GetValue("DocVersion_ItemID"); + _DocVersion_FormatID = (int?)dr.GetValue("DocVersion_FormatID"); + _DocVersion_Config = dr.GetString("DocVersion_Config"); + _DocVersion_DTS = dr.GetDateTime("DocVersion_DTS"); + _DocVersion_UserID = dr.GetString("DocVersion_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstDocVersionROFst.FetchDR", ex); + throw new DbCslaException("ROFstDocVersionROFst.Fetch", ex); + } + MarkOld(); + } + internal void Insert(ROFst myROFst) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = DocVersionROFst.Add(cn, _MyDocVersion, myROFst, _DTS, _UserID); + MarkOld(); + } + internal void Update(ROFst myROFst) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = DocVersionROFst.Update(cn, _MyDocVersion, myROFst, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(ROFst myROFst) + { + // 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"]; + DocVersionROFst.Remove(cn, _VersionID, myROFst.ROFstID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ROFstDocVersionROFstExtension _ROFstDocVersionROFstExtension = new ROFstDocVersionROFstExtension(); + [Serializable()] + partial class ROFstDocVersionROFstExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROFstDocVersionROFstConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstDocVersionROFst) + { + // Return the ToString value + return ((ROFstDocVersionROFst)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImage.cs index 036ce13e..e112ed68 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImage.cs @@ -20,915 +20,907 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROFstImage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstImageConverter))] - public partial class ROFstImage : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshROFstImages = new List(); - private void AddToRefreshList(List refreshROFstImages) - { - if (IsDirty) - refreshROFstImages.Add(this); - } - private void BuildRefreshList() - { - _RefreshROFstImages = new List(); - AddToRefreshList(_RefreshROFstImages); - } - private void ProcessRefreshList() - { - foreach (ROFstImage tmp in _RefreshROFstImages) - { - ROFstImageInfo.Refresh(tmp); - if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); - if (tmp._MyROImage != null) ROImageInfo.Refresh(tmp._MyROImage); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROFstImage rOFstImage) - { - if (!_CacheList.Contains(rOFstImage)) _CacheList.Add(rOFstImage); // In AddToCache - } - protected static void RemoveFromCache(ROFstImage rOFstImage) - { - while (_CacheList.Contains(rOFstImage)) _CacheList.Remove(rOFstImage); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ROFstImage tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString())) - { - _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ROFstImage tmp in remove) - RemoveFromCache(tmp); - } - protected static ROFstImage GetCachedByPrimaryKey(int rOFstID, int imageID) - { - ConvertListToDictionary(); - string key = rOFstID.ToString() + "_" + imageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - } - private int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImage _MyROImage; - [System.ComponentModel.DataObjectField(true, true)] - public ROImage MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.Get(_ImageID); - return _MyROImage; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsDirty - { - get { return base.IsDirty || (_MyROFst == null ? false : _MyROFst.IsDirty) || (_MyROImage == null ? false : _MyROImage.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValid) && (_MyROImage == null ? true : _MyROImage.IsValid); } - } - // TODO: Replace base ROFstImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstImage - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ROFstImage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstImage - protected override object GetIdValue() - { - return (_ROFstID.ToString() + "." + _ImageID.ToString()).GetHashCode(); - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ROFstImageExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ROFstImageExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(ImageID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ROFstImageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ROFstImageExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ROFstImageUnique = 0; - protected static int ROFstImageUnique - { get { return ++_ROFstImageUnique; } } - private int _MyROFstImageUnique = ROFstImageUnique; - public int MyROFstImageUnique - { get { return _MyROFstImageUnique; } } - protected ROFstImage() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ROFstID.ToString() + "_" + ImageID.ToString())) - { - List listROFstImage = _CacheByPrimaryKey[ROFstID.ToString() + "_" + ImageID.ToString()]; // Get the list of items - while (listROFstImage.Contains(this)) listROFstImage.Remove(this); // Remove the item from the list - if (listROFstImage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ROFstID.ToString() + "_" + ImageID.ToString()); // remove the list - } - } - public static ROFstImage New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFstImage"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFstImage.New", ex); - } - } - public static ROFstImage New(ROFst myROFst, ROImage myROImage) - { - ROFstImage tmp = ROFstImage.New(); - tmp._MyROFst = myROFst; - tmp._MyROImage = myROImage; - return tmp; - } - public static ROFstImage MakeROFstImage(ROFst myROFst, ROImage myROImage) - { - ROFstImage tmp = ROFstImage.New(myROFst, myROImage); - if (tmp.IsSavable) - { - ROFstImage tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROFstImage New(ROFst myROFst, ROImage myROImage, DateTime dts, string userID) - { - ROFstImage tmp = ROFstImage.New(); - tmp._MyROFst = myROFst; - tmp._MyROImage = myROImage; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static ROFstImage MakeROFstImage(ROFst myROFst, ROImage myROImage, DateTime dts, string userID) - { - ROFstImage tmp = ROFstImage.New(myROFst, myROImage, dts, userID); - if (tmp.IsSavable) - { - ROFstImage tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROFstImage Get(int rOFstID, int imageID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROFstImage"); - try - { - ROFstImage tmp = GetCachedByPrimaryKey(rOFstID, imageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOFstID, imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROFstImage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFstImage.Get", ex); - } - } - public static ROFstImage Get(SafeDataReader dr) - { - if (dr.Read()) return new ROFstImage(dr); - return null; - } - internal ROFstImage(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rOFstID, int imageID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFstImage"); - try - { - DataPortal.Delete(new PKCriteria(rOFstID, imageID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFstImage.Delete", ex); - } - } - public override ROFstImage Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROFstImage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROFstImage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ROFstImage"); - try - { - BuildRefreshList(); - ROFstImage rOFstImage = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(rOFstImage);//Refresh the item in AllList - ProcessRefreshList(); - return rOFstImage; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int rOFstID, int imageID) - { - _ROFstID = rOFstID; - _ImageID = imageID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// ROFstImage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstImageConverter))] + public partial class ROFstImage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshROFstImages = new List(); + private void AddToRefreshList(List refreshROFstImages) + { + if (IsDirty) + refreshROFstImages.Add(this); + } + private void BuildRefreshList() + { + _RefreshROFstImages = new List(); + AddToRefreshList(_RefreshROFstImages); + } + private void ProcessRefreshList() + { + foreach (ROFstImage tmp in _RefreshROFstImages) + { + ROFstImageInfo.Refresh(tmp); + if (tmp._MyROFst != null) ROFstInfo.Refresh(tmp._MyROFst); + if (tmp._MyROImage != null) ROImageInfo.Refresh(tmp._MyROImage); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROFstImage rOFstImage) + { + if (!_CacheList.Contains(rOFstImage)) _CacheList.Add(rOFstImage); // In AddToCache + } + protected static void RemoveFromCache(ROFstImage rOFstImage) + { + while (_CacheList.Contains(rOFstImage)) _CacheList.Remove(rOFstImage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ROFstImage tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString())) + { + _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ROFstImage tmp in remove) + RemoveFromCache(tmp); + } + protected static ROFstImage GetCachedByPrimaryKey(int rOFstID, int imageID) + { + ConvertListToDictionary(); + string key = rOFstID.ToString() + "_" + imageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + } + private int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImage _MyROImage; + [System.ComponentModel.DataObjectField(true, true)] + public ROImage MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.Get(_ImageID); + return _MyROImage; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsDirty + { + get { return base.IsDirty || (_MyROFst == null ? false : _MyROFst.IsDirty) || (_MyROImage == null ? false : _MyROImage.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyROFst == null ? true : _MyROFst.IsValid) && (_MyROImage == null ? true : _MyROImage.IsValid); } + } + // TODO: Replace base ROFstImage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFstImage + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ROFstImage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstImage + protected override object GetIdValue() + { + return (_ROFstID.ToString() + "." + _ImageID.ToString()).GetHashCode(); + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ROFstImageExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ROFstImageExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(ImageID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ROFstImageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ROFstImageExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ROFstImageUnique = 0; + protected static int ROFstImageUnique + { get { return ++_ROFstImageUnique; } } + private int _MyROFstImageUnique = ROFstImageUnique; + public int MyROFstImageUnique + { get { return _MyROFstImageUnique; } } + protected ROFstImage() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ROFstID.ToString() + "_" + ImageID.ToString())) + { + List listROFstImage = _CacheByPrimaryKey[ROFstID.ToString() + "_" + ImageID.ToString()]; // Get the list of items + while (listROFstImage.Contains(this)) listROFstImage.Remove(this); // Remove the item from the list + if (listROFstImage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ROFstID.ToString() + "_" + ImageID.ToString()); // remove the list + } + } + public static ROFstImage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROFstImage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFstImage.New", ex); + } + } + public static ROFstImage New(ROFst myROFst, ROImage myROImage) + { + ROFstImage tmp = ROFstImage.New(); + tmp._MyROFst = myROFst; + tmp._MyROImage = myROImage; + return tmp; + } + public static ROFstImage MakeROFstImage(ROFst myROFst, ROImage myROImage) + { + ROFstImage tmp = ROFstImage.New(myROFst, myROImage); + if (tmp.IsSavable) + { + ROFstImage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROFstImage New(ROFst myROFst, ROImage myROImage, DateTime dts, string userID) + { + ROFstImage tmp = ROFstImage.New(); + tmp._MyROFst = myROFst; + tmp._MyROImage = myROImage; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static ROFstImage MakeROFstImage(ROFst myROFst, ROImage myROImage, DateTime dts, string userID) + { + ROFstImage tmp = ROFstImage.New(myROFst, myROImage, dts, userID); + if (tmp.IsSavable) + { + ROFstImage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROFstImage Get(int rOFstID, int imageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROFstImage"); + try + { + ROFstImage tmp = GetCachedByPrimaryKey(rOFstID, imageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOFstID, imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROFstImage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFstImage.Get", ex); + } + } + public static ROFstImage Get(SafeDataReader dr) + { + if (dr.Read()) return new ROFstImage(dr); + return null; + } + internal ROFstImage(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rOFstID, int imageID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROFstImage"); + try + { + DataPortal.Delete(new PKCriteria(rOFstID, imageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFstImage.Delete", ex); + } + } + public override ROFstImage Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROFstImage"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROFstImage"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ROFstImage"); + try + { + BuildRefreshList(); + ROFstImage rOFstImage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(rOFstImage);//Refresh the item in AllList + ProcessRefreshList(); + return rOFstImage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + private int _ImageID; + public int ImageID + { get { return _ImageID; } } + public PKCriteria(int rOFstID, int imageID) + { + _ROFstID = rOFstID; + _ImageID = imageID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults - _DTS = _ROFstImageExtension.DefaultDTS; - _UserID = _ROFstImageExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.ReadData", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _ImageID = dr.GetInt32("ImageID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstImage.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROFstImage"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstImage.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstImage.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyROFst != null) _MyROFst.Update(); - if (_MyROImage != null) _MyROImage.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addROFstImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROFstID", ROFstID); - cm.Parameters.AddWithValue("@ImageID", ImageID); - 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); - // TODO: 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}] ROFstImage.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstImage.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ROFst myROFst, ROImage myROImage, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addROFstImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); - cm.Parameters.AddWithValue("@ImageID", myROImage.ImageID); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.Add", ex); - throw new DbCslaException("ROFstImage.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ROFstImage.SQLUpdate", GetHashCode()); - try - { - if (_MyROFst != null) _MyROFst.Update(); - if (_MyROImage != null) _MyROImage.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateROFstImage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ROFstID", ROFstID); - cm.Parameters.AddWithValue("@ImageID", ImageID); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ROFstImage.Add(cn, _MyROFst, _MyROImage, _DTS, _UserID); - else - _LastChanged = ROFstImage.Update(cn, _MyROFst, _MyROImage, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ROFst myROFst, ROImage myROImage, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateROFstImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); - cm.Parameters.AddWithValue("@ImageID", myROImage.ImageID); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.Update", ex); - throw new DbCslaException("ROFstImage.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ROFstID, _ImageID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteROFstImage"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstImage.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rOFstID, int imageID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteROFstImage"; - // Input PK Fields - cm.Parameters.AddWithValue("@ROFstID", rOFstID); - cm.Parameters.AddWithValue("@ImageID", imageID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.Remove", ex); - throw new DbCslaException("ROFstImage.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rOFstID, int imageID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rOFstID, imageID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFstImage.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ROFstID; - private int _ImageID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rOFstID, int imageID) - { - _ROFstID = rOFstID; - _ImageID = imageID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsROFstImage"; - cm.Parameters.AddWithValue("@ROFstID", _ROFstID); - cm.Parameters.AddWithValue("@ImageID", _ImageID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Execute", ex); - throw new DbCslaException("ROFstImage.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ROFstImageExtension _ROFstImageExtension = new ROFstImageExtension(); - [Serializable()] - partial class ROFstImageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROFstImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstImage) - { - // Return the ToString value - return ((ROFstImage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // Database Defaults + _DTS = _ROFstImageExtension.DefaultDTS; + _UserID = _ROFstImageExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.ReadData", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _ImageID = dr.GetInt32("ImageID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstImage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROFstImage"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstImage.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstImage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyROFst != null) _MyROFst.Update(); + if (_MyROImage != null) _MyROImage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addROFstImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROFstID", ROFstID); + cm.Parameters.AddWithValue("@ImageID", ImageID); + 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); + // TODO: 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}] ROFstImage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstImage.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ROFst myROFst, ROImage myROImage, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addROFstImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); + cm.Parameters.AddWithValue("@ImageID", myROImage.ImageID); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.Add", ex); + throw new DbCslaException("ROFstImage.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ROFstImage.SQLUpdate", GetHashCode()); + try + { + if (_MyROFst != null) _MyROFst.Update(); + if (_MyROImage != null) _MyROImage.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateROFstImage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ROFstID", ROFstID); + cm.Parameters.AddWithValue("@ImageID", ImageID); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ROFstImage.Add(cn, _MyROFst, _MyROImage, _DTS, _UserID); + else + _LastChanged = ROFstImage.Update(cn, _MyROFst, _MyROImage, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ROFst myROFst, ROImage myROImage, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateROFstImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROFstID", myROFst.ROFstID); + cm.Parameters.AddWithValue("@ImageID", myROImage.ImageID); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.Update", ex); + throw new DbCslaException("ROFstImage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ROFstID, _ImageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteROFstImage"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstImage.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rOFstID, int imageID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteROFstImage"; + // Input PK Fields + cm.Parameters.AddWithValue("@ROFstID", rOFstID); + cm.Parameters.AddWithValue("@ImageID", imageID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.Remove", ex); + throw new DbCslaException("ROFstImage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rOFstID, int imageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rOFstID, imageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFstImage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ROFstID; + private int _ImageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rOFstID, int imageID) + { + _ROFstID = rOFstID; + _ImageID = imageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsROFstImage"; + cm.Parameters.AddWithValue("@ROFstID", _ROFstID); + cm.Parameters.AddWithValue("@ImageID", _ImageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImage.DataPortal_Execute", ex); + throw new DbCslaException("ROFstImage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ROFstImageExtension _ROFstImageExtension = new ROFstImageExtension(); + [Serializable()] + partial class ROFstImageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROFstImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstImage) + { + // Return the ToString value + return ((ROFstImage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImageInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImageInfo.cs index b1905b67..da5d8fd1 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstImageInfo.cs @@ -19,396 +19,390 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ROFstImageInfoEvent(object sender); - /// - /// ROFstImageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstImageInfoConverter))] - public partial class ROFstImageInfo : ReadOnlyBase, IDisposable - { - public event ROFstImageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROFstImageInfo rOFstImageInfo) - { - if (!_CacheList.Contains(rOFstImageInfo)) _CacheList.Add(rOFstImageInfo); // In AddToCache - } - protected static void RemoveFromCache(ROFstImageInfo rOFstImageInfo) - { - while (_CacheList.Contains(rOFstImageInfo)) _CacheList.Remove(rOFstImageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ROFstImageInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString())) - { - _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ROFstImageInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(ROFstImageInfoList lst) - { - foreach (ROFstImageInfo item in lst) AddToCache(item); - } - protected static ROFstImageInfo GetCachedByPrimaryKey(int rOFstID, int imageID) - { - ConvertListToDictionary(); - string key = rOFstID.ToString() + "_" + imageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ROFstImage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFstInfo _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFstInfo MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); - return _MyROFst; - } - } - private int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImageInfo _MyROImage; - [System.ComponentModel.DataObjectField(true, true)] - public ROImageInfo MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImageInfo.Get(_ImageID); - return _MyROImage; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - // TODO: Replace base ROFstImageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstImageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ROFstImageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstImageInfo - protected override object GetIdValue() - { - return (_ROFstID.ToString() + "." + _ImageID.ToString()).GetHashCode(); - } - #endregion - #region Factory Methods - private static int _ROFstImageInfoUnique = 0; - private static int ROFstImageInfoUnique - { get { return ++_ROFstImageInfoUnique; } } - private int _MyROFstImageInfoUnique = ROFstImageInfoUnique; - public int MyROFstImageInfoUnique - { get { return _MyROFstImageInfoUnique; } } - protected ROFstImageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ROFstID.ToString() + "_" + ImageID.ToString())) return; - List listROFstImageInfo = _CacheByPrimaryKey[ROFstID.ToString() + "_" + ImageID.ToString()]; // Get the list of items - while (listROFstImageInfo.Contains(this)) listROFstImageInfo.Remove(this); // Remove the item from the list - if (listROFstImageInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ROFstID.ToString() + "_" + ImageID.ToString()); // remove the list - } - public virtual ROFstImage Get() - { - return _Editable = ROFstImage.Get(_ROFstID, _ImageID); - } - public static void Refresh(ROFstImage tmp) - { - string key = tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROFstImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROFstImage tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROFstImageInfoExtension.Refresh(this); - if(_MyROFst != null) - { - _MyROFst.Dispose();// Dispose related value - _MyROFst = null;// Reset related value - } - if(_MyROImage != null) - { - _MyROImage.Dispose();// Dispose related value - _MyROImage = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ROFst myROFst, ROFstROFstImage tmp) - { - string key = myROFst.ROFstID.ToString() + "_" + tmp.ImageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROFstImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROFstROFstImage tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROFstImageInfoExtension.Refresh(this); - if(_MyROFst != null) - { - _MyROFst.Dispose();// Dispose related value - _MyROFst = null;// Reset related value - } - if(_MyROImage != null) - { - _MyROImage.Dispose();// Dispose related value - _MyROImage = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ROImage myROImage, ROImageROFstImage tmp) - { - string key = tmp.ROFstID.ToString() + "_" + myROImage.ImageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROFstImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROImageROFstImage tmp) - { - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROFstImageInfoExtension.Refresh(this); - if(_MyROFst != null) - { - _MyROFst.Dispose();// Dispose related value - _MyROFst = null;// Reset related value - } - if(_MyROImage != null) - { - _MyROImage.Dispose();// Dispose related value - _MyROImage = null;// Reset related value - } - OnChange();// raise an event - } - public static ROFstImageInfo Get(int rOFstID, int imageID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ROFstImage"); - try - { - ROFstImageInfo tmp = GetCachedByPrimaryKey(rOFstID, imageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOFstID, imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROFstImageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFstImageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ROFstImageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImageInfo.Constructor", ex); - throw new DbCslaException("ROFstImageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int rOFstID, int imageID) - { - _ROFstID = rOFstID; - _ImageID = imageID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImageInfo.ReadData", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _ImageID = dr.GetInt32("ImageID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstImageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROFstImage"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstImageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ROFstImageInfoExtension _ROFstImageInfoExtension = new ROFstImageInfoExtension(); - [Serializable()] - partial class ROFstImageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ROFstImageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ROFstImageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstImageInfo) - { - // Return the ToString value - return ((ROFstImageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ROFstImageInfoEvent(object sender); + /// + /// ROFstImageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstImageInfoConverter))] + public partial class ROFstImageInfo : ReadOnlyBase, IDisposable + { + public event ROFstImageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROFstImageInfo rOFstImageInfo) + { + if (!_CacheList.Contains(rOFstImageInfo)) _CacheList.Add(rOFstImageInfo); // In AddToCache + } + protected static void RemoveFromCache(ROFstImageInfo rOFstImageInfo) + { + while (_CacheList.Contains(rOFstImageInfo)) _CacheList.Remove(rOFstImageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ROFstImageInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString())) + { + _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ROFstImageInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(ROFstImageInfoList lst) + { + foreach (ROFstImageInfo item in lst) AddToCache(item); + } + protected static ROFstImageInfo GetCachedByPrimaryKey(int rOFstID, int imageID) + { + ConvertListToDictionary(); + string key = rOFstID.ToString() + "_" + imageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ROFstImage _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFstInfo _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFstInfo MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFstInfo.Get(_ROFstID); + return _MyROFst; + } + } + private int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImageInfo _MyROImage; + [System.ComponentModel.DataObjectField(true, true)] + public ROImageInfo MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImageInfo.Get(_ImageID); + return _MyROImage; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + // TODO: Replace base ROFstImageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFstImageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ROFstImageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstImageInfo + protected override object GetIdValue() + { + return (_ROFstID.ToString() + "." + _ImageID.ToString()).GetHashCode(); + } + #endregion + #region Factory Methods + private static int _ROFstImageInfoUnique = 0; + private static int ROFstImageInfoUnique + { get { return ++_ROFstImageInfoUnique; } } + private int _MyROFstImageInfoUnique = ROFstImageInfoUnique; + public int MyROFstImageInfoUnique + { get { return _MyROFstImageInfoUnique; } } + protected ROFstImageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ROFstID.ToString() + "_" + ImageID.ToString())) return; + List listROFstImageInfo = _CacheByPrimaryKey[ROFstID.ToString() + "_" + ImageID.ToString()]; // Get the list of items + while (listROFstImageInfo.Contains(this)) listROFstImageInfo.Remove(this); // Remove the item from the list + if (listROFstImageInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ROFstID.ToString() + "_" + ImageID.ToString()); // remove the list + } + public virtual ROFstImage Get() + { + return _Editable = ROFstImage.Get(_ROFstID, _ImageID); + } + public static void Refresh(ROFstImage tmp) + { + string key = tmp.ROFstID.ToString() + "_" + tmp.ImageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROFstImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROFstImage tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROFstImageInfoExtension.Refresh(this); + if (_MyROFst != null) + { + _MyROFst.Dispose();// Dispose related value + _MyROFst = null;// Reset related value + } + if (_MyROImage != null) + { + _MyROImage.Dispose();// Dispose related value + _MyROImage = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ROFst myROFst, ROFstROFstImage tmp) + { + string key = myROFst.ROFstID.ToString() + "_" + tmp.ImageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROFstImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROFstROFstImage tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROFstImageInfoExtension.Refresh(this); + if (_MyROFst != null) + { + _MyROFst.Dispose();// Dispose related value + _MyROFst = null;// Reset related value + } + if (_MyROImage != null) + { + _MyROImage.Dispose();// Dispose related value + _MyROImage = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ROImage myROImage, ROImageROFstImage tmp) + { + string key = tmp.ROFstID.ToString() + "_" + myROImage.ImageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROFstImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROImageROFstImage tmp) + { + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROFstImageInfoExtension.Refresh(this); + if (_MyROFst != null) + { + _MyROFst.Dispose();// Dispose related value + _MyROFst = null;// Reset related value + } + if (_MyROImage != null) + { + _MyROImage.Dispose();// Dispose related value + _MyROImage = null;// Reset related value + } + OnChange();// raise an event + } + public static ROFstImageInfo Get(int rOFstID, int imageID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ROFstImage"); + try + { + ROFstImageInfo tmp = GetCachedByPrimaryKey(rOFstID, imageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOFstID, imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROFstImageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFstImageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ROFstImageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImageInfo.Constructor", ex); + throw new DbCslaException("ROFstImageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + private int _ImageID; + public int ImageID + { get { return _ImageID; } } + public PKCriteria(int rOFstID, int imageID) + { + _ROFstID = rOFstID; + _ImageID = imageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImageInfo.ReadData", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _ImageID = dr.GetInt32("ImageID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstImageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstImageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROFstImage"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstImageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstImageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ROFstImageInfoExtension _ROFstImageInfoExtension = new ROFstImageInfoExtension(); + [Serializable()] + partial class ROFstImageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ROFstImageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ROFstImageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstImageInfo) + { + // Return the ToString value + return ((ROFstImageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstInfo.cs index ec8af2cb..c730a80a 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstInfo.cs @@ -19,433 +19,423 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ROFstInfoEvent(object sender); - /// - /// ROFstInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstInfoConverter))] - public partial class ROFstInfo : ReadOnlyBase, IDisposable - { - public event ROFstInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROFstInfo rOFstInfo) - { - if (!_CacheList.Contains(rOFstInfo)) _CacheList.Add(rOFstInfo); // In AddToCache - } - protected static void RemoveFromCache(ROFstInfo rOFstInfo) - { - while (_CacheList.Contains(rOFstInfo)) _CacheList.Remove(rOFstInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ROFstInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString())) - { - _CacheByPrimaryKey[tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ROFstInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(ROFstInfoList lst) - { - foreach (ROFstInfo item in lst) AddToCache(item); - } - protected static ROFstInfo GetCachedByPrimaryKey(int rOFstID) - { - ConvertListToDictionary(); - string key = rOFstID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ROFst _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - return _ROFstID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODbInfo _MyRODb; - public RODbInfo MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); - return _MyRODb; - } - } - private byte[] _ROFST; - public byte[] ROFST - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFST", true); - return _ROFST; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ROFstDocVersionROFstCount = 0; - /// - /// Count of ROFstDocVersionROFsts for this ROFst - /// - public int ROFstDocVersionROFstCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstDocVersionROFstCount", true); - return _ROFstDocVersionROFstCount; - } - } - private DocVersionROFstInfoList _ROFstDocVersionROFsts = null; - [TypeConverter(typeof(DocVersionROFstInfoListConverter))] - public DocVersionROFstInfoList ROFstDocVersionROFsts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstDocVersionROFsts", true); - if (_ROFstDocVersionROFstCount < 0 || (_ROFstDocVersionROFstCount > 0 && _ROFstDocVersionROFsts == null)) - _ROFstDocVersionROFsts = DocVersionROFstInfoList.GetByROFstID(_ROFstID); - if (_ROFstDocVersionROFstCount < 0) - _ROFstDocVersionROFstCount = _ROFstDocVersionROFsts.Count; - return _ROFstDocVersionROFsts; - } - } - public void RefreshROFstDocVersionROFsts() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) - foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) - tmp._ROFstDocVersionROFstCount = -1; // This will cause the data to be requeried - } - private int _ROFstROFstImageCount = 0; - /// - /// Count of ROFstROFstImages for this ROFst - /// - public int ROFstROFstImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstROFstImageCount", true); - return _ROFstROFstImageCount; - } - } - private ROFstImageInfoList _ROFstROFstImages = null; - [TypeConverter(typeof(ROFstImageInfoListConverter))] - public ROFstImageInfoList ROFstROFstImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstROFstImages", true); - if (_ROFstROFstImageCount < 0 || (_ROFstROFstImageCount > 0 && _ROFstROFstImages == null)) - _ROFstROFstImages = ROFstImageInfoList.GetByROFstID(_ROFstID); - if (_ROFstROFstImageCount < 0) - _ROFstROFstImageCount = _ROFstROFstImages.Count; - return _ROFstROFstImages; - } - } - public void RefreshROFstROFstImages() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) - foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) - tmp._ROFstROFstImageCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base ROFstInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ROFstInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstInfo - protected override object GetIdValue() - { - return _ROFstID; - } - #endregion - #region Factory Methods - private static int _ROFstInfoUnique = 0; - private static int ROFstInfoUnique - { get { return ++_ROFstInfoUnique; } } - private int _MyROFstInfoUnique = ROFstInfoUnique; - public int MyROFstInfoUnique - { get { return _MyROFstInfoUnique; } } - protected ROFstInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) return; - List listROFstInfo = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items - while (listROFstInfo.Contains(this)) listROFstInfo.Remove(this); // Remove the item from the list - if (listROFstInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list - } - public virtual ROFst Get() - { - return _Editable = ROFst.Get(_ROFstID); - } - public static void Refresh(ROFst tmp) - { - string key = tmp.ROFstID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROFst tmp) - { - if (_RODbID != tmp.RODbID) - { - if (MyRODb != null) MyRODb.RefreshRODbROFsts(); // 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.RefreshRODbROFsts(); // Update List for new value - _ROFST = tmp.ROFST; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROFstInfoExtension.Refresh(this); - if(_MyRODb != null) - { - _MyRODb.Dispose();// Dispose related value - _MyRODb = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(RODbROFst tmp) - { - string key = tmp.ROFstID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODbROFst tmp) - { - _ROFST = tmp.ROFST; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROFstInfoExtension.Refresh(this); - if(_MyRODb != null) - { - _MyRODb.Dispose();// Dispose related value - _MyRODb = null;// Reset related value - } - OnChange();// raise an event - } - public static ROFstInfo Get(int rOFstID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ROFst"); - try - { - ROFstInfo tmp = GetCachedByPrimaryKey(rOFstID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROFstInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROFstInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ROFstInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.Constructor", ex); - throw new DbCslaException("ROFstInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ROFstID; - public int ROFstID - { get { return _ROFstID; } } - public PKCriteria(int rOFstID) - { - _ROFstID = rOFstID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.ReadData", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _RODbID = dr.GetInt32("RODbID"); - _ROFST = (byte[])dr.GetValue("ROFST"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _ROFstDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); - _ROFstROFstImageCount = dr.GetInt32("ROFstImageCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROFst"; - cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROFstInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ROFstInfoExtension _ROFstInfoExtension = new ROFstInfoExtension(); - [Serializable()] - partial class ROFstInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ROFstInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ROFstInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstInfo) - { - // Return the ToString value - return ((ROFstInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ROFstInfoEvent(object sender); + /// + /// ROFstInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstInfoConverter))] + public partial class ROFstInfo : ReadOnlyBase, IDisposable + { + public event ROFstInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROFstInfo rOFstInfo) + { + if (!_CacheList.Contains(rOFstInfo)) _CacheList.Add(rOFstInfo); // In AddToCache + } + protected static void RemoveFromCache(ROFstInfo rOFstInfo) + { + while (_CacheList.Contains(rOFstInfo)) _CacheList.Remove(rOFstInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ROFstInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROFstID.ToString())) + { + _CacheByPrimaryKey[tmp.ROFstID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ROFstID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ROFstInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(ROFstInfoList lst) + { + foreach (ROFstInfo item in lst) AddToCache(item); + } + protected static ROFstInfo GetCachedByPrimaryKey(int rOFstID) + { + ConvertListToDictionary(); + string key = rOFstID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ROFst _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODbInfo _MyRODb; + public RODbInfo MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); + return _MyRODb; + } + } + private byte[] _ROFST; + public byte[] ROFST + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFST; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ROFstDocVersionROFstCount = 0; + /// + /// Count of ROFstDocVersionROFsts for this ROFst + /// + public int ROFstDocVersionROFstCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstDocVersionROFstCount; + } + } + private DocVersionROFstInfoList _ROFstDocVersionROFsts = null; + [TypeConverter(typeof(DocVersionROFstInfoListConverter))] + public DocVersionROFstInfoList ROFstDocVersionROFsts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstDocVersionROFstCount < 0 || (_ROFstDocVersionROFstCount > 0 && _ROFstDocVersionROFsts == null)) + _ROFstDocVersionROFsts = DocVersionROFstInfoList.GetByROFstID(_ROFstID); + if (_ROFstDocVersionROFstCount < 0) + _ROFstDocVersionROFstCount = _ROFstDocVersionROFsts.Count; + return _ROFstDocVersionROFsts; + } + } + public void RefreshROFstDocVersionROFsts() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) + foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) + tmp._ROFstDocVersionROFstCount = -1; // This will cause the data to be requeried + } + private int _ROFstROFstImageCount = 0; + /// + /// Count of ROFstROFstImages for this ROFst + /// + public int ROFstROFstImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFstROFstImageCount; + } + } + private ROFstImageInfoList _ROFstROFstImages = null; + [TypeConverter(typeof(ROFstImageInfoListConverter))] + public ROFstImageInfoList ROFstROFstImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROFstROFstImageCount < 0 || (_ROFstROFstImageCount > 0 && _ROFstROFstImages == null)) + _ROFstROFstImages = ROFstImageInfoList.GetByROFstID(_ROFstID); + if (_ROFstROFstImageCount < 0) + _ROFstROFstImageCount = _ROFstROFstImages.Count; + return _ROFstROFstImages; + } + } + public void RefreshROFstROFstImages() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ROFstID.ToString())) + foreach (ROFstInfo tmp in _CacheByPrimaryKey[_ROFstID.ToString()]) + tmp._ROFstROFstImageCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base ROFstInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFstInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ROFstInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstInfo + protected override object GetIdValue() + { + return _ROFstID; + } + #endregion + #region Factory Methods + private static int _ROFstInfoUnique = 0; + private static int ROFstInfoUnique + { get { return ++_ROFstInfoUnique; } } + private int _MyROFstInfoUnique = ROFstInfoUnique; + public int MyROFstInfoUnique + { get { return _MyROFstInfoUnique; } } + protected ROFstInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ROFstID.ToString())) return; + List listROFstInfo = _CacheByPrimaryKey[ROFstID.ToString()]; // Get the list of items + while (listROFstInfo.Contains(this)) listROFstInfo.Remove(this); // Remove the item from the list + if (listROFstInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ROFstID.ToString()); // remove the list + } + public virtual ROFst Get() + { + return _Editable = ROFst.Get(_ROFstID); + } + public static void Refresh(ROFst tmp) + { + string key = tmp.ROFstID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROFst tmp) + { + if (_RODbID != tmp.RODbID) + { + if (MyRODb != null) MyRODb.RefreshRODbROFsts(); // 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.RefreshRODbROFsts(); // Update List for new value + _ROFST = tmp.ROFST; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROFstInfoExtension.Refresh(this); + if (_MyRODb != null) + { + _MyRODb.Dispose();// Dispose related value + _MyRODb = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(RODbROFst tmp) + { + string key = tmp.ROFstID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROFstInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODbROFst tmp) + { + _ROFST = tmp.ROFST; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROFstInfoExtension.Refresh(this); + if (_MyRODb != null) + { + _MyRODb.Dispose();// Dispose related value + _MyRODb = null;// Reset related value + } + OnChange();// raise an event + } + public static ROFstInfo Get(int rOFstID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ROFst"); + try + { + ROFstInfo tmp = GetCachedByPrimaryKey(rOFstID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOFstID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROFstInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROFstInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ROFstInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.Constructor", ex); + throw new DbCslaException("ROFstInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ROFstID; + public int ROFstID + { get { return _ROFstID; } } + public PKCriteria(int rOFstID) + { + _ROFstID = rOFstID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.ReadData", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _RODbID = dr.GetInt32("RODbID"); + _ROFST = (byte[])dr.GetValue("ROFST"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _ROFstDocVersionROFstCount = dr.GetInt32("DocVersionROFstCount"); + _ROFstROFstImageCount = dr.GetInt32("ROFstImageCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROFst"; + cm.Parameters.AddWithValue("@ROFstID", criteria.ROFstID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROFstInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ROFstInfoExtension _ROFstInfoExtension = new ROFstInfoExtension(); + [Serializable()] + partial class ROFstInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ROFstInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ROFstInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstInfo) + { + // Return the ToString value + return ((ROFstInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstROFstImage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstROFstImage.cs index 869cc572..0ccf4dc8 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstROFstImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROFstROFstImage.cs @@ -19,385 +19,374 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROFstROFstImage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROFstROFstImageConverter))] - public partial class ROFstROFstImage : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - if (_MyROImage != null) _ImageID = _MyROImage.ImageID; - return _ImageID; - } - } - private ROImage _MyROImage; - [System.ComponentModel.DataObjectField(true, true)] - public ROImage MyROImage - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROImage", true); - if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.Get(_ImageID); - return _MyROImage; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ROImage_RODbID; - public int ROImage_RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_RODbID", true); - return _ROImage_RODbID; - } - } - private string _ROImage_FileName = string.Empty; - public string ROImage_FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_FileName", true); - return _ROImage_FileName; - } - } - private byte[] _ROImage_Content; - public byte[] ROImage_Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_Content", true); - return _ROImage_Content; - } - } - private DateTime _ROImage_DTS = new DateTime(); - public DateTime ROImage_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_DTS", true); - return _ROImage_DTS; - } - } - private string _ROImage_UserID = string.Empty; - public string ROImage_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImage_UserID", true); - return _ROImage_UserID; - } - } - // TODO: Check ROFstROFstImage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROFstROFstImage - protected override object GetIdValue() - { - return _ImageID; - } - // TODO: Replace base ROFstROFstImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROFstROFstImage - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ImageID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ROFstROFstImage New(ROImage myROImage) - { - return new ROFstROFstImage(myROImage); - } - internal static ROFstROFstImage Get(SafeDataReader dr) - { - return new ROFstROFstImage(dr); - } - public ROFstROFstImage() - { - MarkAsChild(); + /// + /// ROFstROFstImage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROFstROFstImageConverter))] + public partial class ROFstROFstImage : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage != null) _ImageID = _MyROImage.ImageID; + return _ImageID; + } + } + private ROImage _MyROImage; + [System.ComponentModel.DataObjectField(true, true)] + public ROImage MyROImage + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROImage == null && _ImageID != 0) _MyROImage = ROImage.Get(_ImageID); + return _MyROImage; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ROImage_RODbID; + public int ROImage_RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_RODbID; + } + } + private string _ROImage_FileName = string.Empty; + public string ROImage_FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_FileName; + } + } + private byte[] _ROImage_Content; + public byte[] ROImage_Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_Content; + } + } + private DateTime _ROImage_DTS = new DateTime(); + public DateTime ROImage_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_DTS; + } + } + private string _ROImage_UserID = string.Empty; + public string ROImage_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImage_UserID; + } + } + // TODO: Check ROFstROFstImage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROFstROFstImage + protected override object GetIdValue() + { + return _ImageID; + } + // TODO: Replace base ROFstROFstImage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROFstROFstImage + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ImageID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ROFstROFstImage New(ROImage myROImage) + { + return new ROFstROFstImage(myROImage); + } + internal static ROFstROFstImage Get(SafeDataReader dr) + { + return new ROFstROFstImage(dr); + } + public ROFstROFstImage() + { + MarkAsChild(); - _DTS = _ROFstROFstImageExtension.DefaultDTS; - _UserID = _ROFstROFstImageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ROFstROFstImage(ROImage myROImage) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ROFstROFstImageExtension.DefaultDTS; - _UserID = _ROFstROFstImageExtension.DefaultUserID; - _MyROImage = myROImage; - ValidationRules.CheckRules(); - } - internal ROFstROFstImage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstROFstImage.FetchDR", GetHashCode()); - try - { - _ImageID = dr.GetInt32("ImageID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROImage_RODbID = dr.GetInt32("ROImage_RODbID"); - _ROImage_FileName = dr.GetString("ROImage_FileName"); - _ROImage_Content = (byte[])dr.GetValue("ROImage_Content"); - _ROImage_DTS = dr.GetDateTime("ROImage_DTS"); - _ROImage_UserID = dr.GetString("ROImage_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstROFstImage.FetchDR", ex); - throw new DbCslaException("ROFstROFstImage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(ROFst myROFst) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFstImage.Add(cn, myROFst, _MyROImage, _DTS, _UserID); - MarkOld(); - } - internal void Update(ROFst myROFst) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFstImage.Update(cn, myROFst, _MyROImage, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(ROFst myROFst) - { - // 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"]; - ROFstImage.Remove(cn, myROFst.ROFstID, _ImageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ROFstROFstImageExtension _ROFstROFstImageExtension = new ROFstROFstImageExtension(); - [Serializable()] - partial class ROFstROFstImageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROFstROFstImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROFstROFstImage) - { - // Return the ToString value - return ((ROFstROFstImage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _ROFstROFstImageExtension.DefaultDTS; + _UserID = _ROFstROFstImageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ROFstROFstImage(ROImage myROImage) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ROFstROFstImageExtension.DefaultDTS; + _UserID = _ROFstROFstImageExtension.DefaultUserID; + _MyROImage = myROImage; + ValidationRules.CheckRules(); + } + internal ROFstROFstImage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFstROFstImage.FetchDR", GetHashCode()); + try + { + _ImageID = dr.GetInt32("ImageID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROImage_RODbID = dr.GetInt32("ROImage_RODbID"); + _ROImage_FileName = dr.GetString("ROImage_FileName"); + _ROImage_Content = (byte[])dr.GetValue("ROImage_Content"); + _ROImage_DTS = dr.GetDateTime("ROImage_DTS"); + _ROImage_UserID = dr.GetString("ROImage_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROFstROFstImage.FetchDR", ex); + throw new DbCslaException("ROFstROFstImage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(ROFst myROFst) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFstImage.Add(cn, myROFst, _MyROImage, _DTS, _UserID); + MarkOld(); + } + internal void Update(ROFst myROFst) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFstImage.Update(cn, myROFst, _MyROImage, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(ROFst myROFst) + { + // 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"]; + ROFstImage.Remove(cn, myROFst.ROFstID, _ImageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ROFstROFstImageExtension _ROFstROFstImageExtension = new ROFstROFstImageExtension(); + [Serializable()] + partial class ROFstROFstImageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROFstROFstImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROFstROFstImage) + { + // Return the ToString value + return ((ROFstROFstImage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImage.cs index 392f4454..8be16bc0 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImage.cs @@ -20,1047 +20,1033 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROImage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROImageConverter))] - public partial class ROImage : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshROImages = new List(); - private List _RefreshROImageROFstImages = new List(); - private void AddToRefreshList(List refreshROImages, List refreshROImageROFstImages) - { - if (IsDirty) - refreshROImages.Add(this); - if (_ROImageROFstImages != null && _ROImageROFstImages.IsDirty) - { - foreach (ROImageROFstImage tmp in _ROImageROFstImages) - { - if (tmp.IsDirty) refreshROImageROFstImages.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshROImages = new List(); - _RefreshROImageROFstImages = new List(); - AddToRefreshList(_RefreshROImages, _RefreshROImageROFstImages); - } - private void ProcessRefreshList() - { - foreach (ROImage tmp in _RefreshROImages) - { - ROImageInfo.Refresh(tmp); - if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); - } - foreach (ROImageROFstImage tmp in _RefreshROImageROFstImages) - { - ROFstImageInfo.Refresh(this, tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROImage rOImage) - { - if (!_CacheList.Contains(rOImage)) _CacheList.Add(rOImage); // In AddToCache - } - protected static void RemoveFromCache(ROImage rOImage) - { - while (_CacheList.Contains(rOImage)) _CacheList.Remove(rOImage); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ROImage tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ImageID.ToString())) - { - _CacheByPrimaryKey[tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ROImage tmp in remove) - RemoveFromCache(tmp); - } - protected static ROImage GetCachedByPrimaryKey(int imageID) - { - ConvertListToDictionary(); - string key = imageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextImageID = -1; - public static int NextImageID - { - get { return _nextImageID--; } - } - private int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - return _ImageID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - PropertyHasChanged(); - } - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FileName", true); - if (value == null) value = string.Empty; - if (_FileName != value) - { - _FileName = value; - PropertyHasChanged(); - } - } - } - private byte[] _Content; - public byte[] Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content", true); - return _Content; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Content", true); - if (_Content != value) - { - _Content = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _ROImageROFstImageCount = 0; - /// - /// Count of ROImageROFstImages for this ROImage - /// - public int ROImageROFstImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageROFstImageCount", true); - return _ROImageROFstImageCount; - } - } - private ROImageROFstImages _ROImageROFstImages = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ROImageROFstImagesConverter))] - public ROImageROFstImages ROImageROFstImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageROFstImages", true); - if (_ROImageROFstImageCount > 0 && _ROImageROFstImages == null) - _ROImageROFstImages = ROImageROFstImages.GetByImageID(ImageID); - else if (_ROImageROFstImages == null) - _ROImageROFstImages = ROImageROFstImages.New(); - return _ROImageROFstImages; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_ROImageROFstImages == null ? false : _ROImageROFstImages.IsDirty) || (_MyRODb == null ? false : _MyRODb.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ROImageROFstImages == null ? true : _ROImageROFstImages.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } - } - // TODO: Replace base ROImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImage - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ROImage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROImage - protected override object GetIdValue() - { - return _ImageID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_ROImageROFstImages != null && (hasBrokenRules = _ROImageROFstImages.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "FileName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _ROImageExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ROImageExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyRODbRequired(ROImage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ImageID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowRead(FileName, ""); - //AuthorizationRules.AllowRead(Content, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - //AuthorizationRules.AllowWrite(FileName, ""); - //AuthorizationRules.AllowWrite(Content, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _ROImageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ROImageExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _ROImageROFstImageCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ROImageUnique = 0; - protected static int ROImageUnique - { get { return ++_ROImageUnique; } } - private int _MyROImageUnique = ROImageUnique; - public int MyROImageUnique - { get { return _MyROImageUnique; } } - protected ROImage() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) - { - List listROImage = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items - while (listROImage.Contains(this)) listROImage.Remove(this); // Remove the item from the list - if (listROImage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list - } - } - public static ROImage New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROImage"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.New", ex); - } - } - public static ROImage New(RODb myRODb, string fileName, byte[] content) - { - ROImage tmp = ROImage.New(); - tmp.MyRODb = myRODb; - tmp.FileName = fileName; - tmp.Content = content; - return tmp; - } - public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content) - { - ROImage tmp = ROImage.New(myRODb, fileName, content); - if (tmp.IsSavable) - { - ROImage tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROImage New(RODb myRODb, string fileName, byte[] content, DateTime dts, string userID) - { - ROImage tmp = ROImage.New(); - tmp.MyRODb = myRODb; - tmp.FileName = fileName; - tmp.Content = content; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content, DateTime dts, string userID) - { - ROImage tmp = ROImage.New(myRODb, fileName, content, dts, userID); - if (tmp.IsSavable) - { - ROImage tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ROImage Get(int imageID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ROImage"); - try - { - ROImage tmp = GetCachedByPrimaryKey(imageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROImage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.Get", ex); - } - } - public static ROImage Get(SafeDataReader dr) - { - if (dr.Read()) return new ROImage(dr); - return null; - } - internal ROImage(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int imageID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROImage"); - try - { - DataPortal.Delete(new PKCriteria(imageID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.Delete", ex); - } - } - public override ROImage Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ROImage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ROImage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ROImage"); - try - { - BuildRefreshList(); - ROImage rOImage = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(rOImage);//Refresh the item in AllList - ProcessRefreshList(); - return rOImage; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int imageID) - { - _ImageID = imageID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ImageID = NextImageID; - // Database Defaults - _DTS = _ROImageExtension.DefaultDTS; - _UserID = _ROImageExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.ReadData", GetHashCode()); - try - { - _ImageID = dr.GetInt32("ImageID"); - _RODbID = dr.GetInt32("RODbID"); - _FileName = dr.GetString("FileName"); - _Content = (byte[])dr.GetValue("Content"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROImageROFstImageCount = dr.GetInt32("ROFstImageCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROImage"; - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _ROImageROFstImages = ROImageROFstImages.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addROImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@FileName", _FileName); - cm.Parameters.AddWithValue("@Content", _Content); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UserID", _UserID); - // Output Calculated Columns - SqlParameter param_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); - param_ImageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ImageID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _ImageID = (int)cm.Parameters["@newImageID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_ROImageROFstImages != null) _ROImageROFstImages.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int imageID, RODb myRODb, string fileName, byte[] content, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addROImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); - cm.Parameters.AddWithValue("@FileName", fileName); - cm.Parameters.AddWithValue("@Content", content); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UserID", userID); - // Output Calculated Columns - SqlParameter param_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); - param_ImageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ImageID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - imageID = (int)cm.Parameters["@newImageID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Add", ex); - throw new DbCslaException("ROImage.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ROImage.SQLUpdate", GetHashCode()); - try - { - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateROImage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ImageID", _ImageID); - cm.Parameters.AddWithValue("@RODbID", RODbID); - cm.Parameters.AddWithValue("@FileName", _FileName); - cm.Parameters.AddWithValue("@Content", _Content); - 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); - // TODO: 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 (_ROImageROFstImages != null) _ROImageROFstImages.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ROImage.Add(cn, ref _ImageID, _MyRODb, _FileName, _Content, _DTS, _UserID); - else - _LastChanged = ROImage.Update(cn, ref _ImageID, _MyRODb, _FileName, _Content, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_ROImageROFstImages != null) _ROImageROFstImages.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int imageID, RODb myRODb, string fileName, byte[] content, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateROImage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ImageID", imageID); - cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); - cm.Parameters.AddWithValue("@FileName", fileName); - cm.Parameters.AddWithValue("@Content", content); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Update", ex); - throw new DbCslaException("ROImage.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ImageID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteROImage"; - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImage.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int imageID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteROImage"; - // Input PK Fields - cm.Parameters.AddWithValue("@ImageID", imageID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Remove", ex); - throw new DbCslaException("ROImage.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int imageID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(imageID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImage.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ImageID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int imageID) - { - _ImageID = imageID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsROImage"; - cm.Parameters.AddWithValue("@ImageID", _ImageID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Execute", ex); - throw new DbCslaException("ROImage.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ROImageExtension _ROImageExtension = new ROImageExtension(); - [Serializable()] - partial class ROImageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROImage) - { - // Return the ToString value - return ((ROImage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// ROImage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROImageConverter))] + public partial class ROImage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshROImages = new List(); + private List _RefreshROImageROFstImages = new List(); + private void AddToRefreshList(List refreshROImages, List refreshROImageROFstImages) + { + if (IsDirty) + refreshROImages.Add(this); + if (_ROImageROFstImages != null && _ROImageROFstImages.IsDirty) + { + foreach (ROImageROFstImage tmp in _ROImageROFstImages) + { + if (tmp.IsDirty) refreshROImageROFstImages.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshROImages = new List(); + _RefreshROImageROFstImages = new List(); + AddToRefreshList(_RefreshROImages, _RefreshROImageROFstImages); + } + private void ProcessRefreshList() + { + foreach (ROImage tmp in _RefreshROImages) + { + ROImageInfo.Refresh(tmp); + if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); + } + foreach (ROImageROFstImage tmp in _RefreshROImageROFstImages) + { + ROFstImageInfo.Refresh(this, tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROImage rOImage) + { + if (!_CacheList.Contains(rOImage)) _CacheList.Add(rOImage); // In AddToCache + } + protected static void RemoveFromCache(ROImage rOImage) + { + while (_CacheList.Contains(rOImage)) _CacheList.Remove(rOImage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ROImage tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ImageID.ToString())) + { + _CacheByPrimaryKey[tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ROImage tmp in remove) + RemoveFromCache(tmp); + } + protected static ROImage GetCachedByPrimaryKey(int imageID) + { + ConvertListToDictionary(); + string key = imageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextImageID = -1; + public static int NextImageID + { + get { return _nextImageID--; } + } + private int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + PropertyHasChanged(); + } + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FileName != value) + { + _FileName = value; + PropertyHasChanged(); + } + } + } + private byte[] _Content; + public byte[] Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_Content != value) + { + _Content = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _ROImageROFstImageCount = 0; + /// + /// Count of ROImageROFstImages for this ROImage + /// + public int ROImageROFstImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImageROFstImageCount; + } + } + private ROImageROFstImages _ROImageROFstImages = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ROImageROFstImagesConverter))] + public ROImageROFstImages ROImageROFstImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROImageROFstImageCount > 0 && _ROImageROFstImages == null) + _ROImageROFstImages = ROImageROFstImages.GetByImageID(ImageID); + else if (_ROImageROFstImages == null) + _ROImageROFstImages = ROImageROFstImages.New(); + return _ROImageROFstImages; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_ROImageROFstImages == null ? false : _ROImageROFstImages.IsDirty) || (_MyRODb == null ? false : _MyRODb.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ROImageROFstImages == null ? true : _ROImageROFstImages.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } + } + // TODO: Replace base ROImage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROImage + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ROImage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROImage + protected override object GetIdValue() + { + return _ImageID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_ROImageROFstImages != null && (hasBrokenRules = _ROImageROFstImages.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "FileName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FileName", 255)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _ROImageExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ROImageExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyRODbRequired(ROImage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ImageID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowRead(FileName, ""); + //AuthorizationRules.AllowRead(Content, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + //AuthorizationRules.AllowWrite(FileName, ""); + //AuthorizationRules.AllowWrite(Content, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _ROImageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ROImageExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _ROImageROFstImageCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ROImageUnique = 0; + protected static int ROImageUnique + { get { return ++_ROImageUnique; } } + private int _MyROImageUnique = ROImageUnique; + public int MyROImageUnique + { get { return _MyROImageUnique; } } + protected ROImage() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) + { + List listROImage = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items + while (listROImage.Contains(this)) listROImage.Remove(this); // Remove the item from the list + if (listROImage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list + } + } + public static ROImage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROImage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.New", ex); + } + } + public static ROImage New(RODb myRODb, string fileName, byte[] content) + { + ROImage tmp = ROImage.New(); + tmp.MyRODb = myRODb; + tmp.FileName = fileName; + tmp.Content = content; + return tmp; + } + public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content) + { + ROImage tmp = ROImage.New(myRODb, fileName, content); + if (tmp.IsSavable) + { + ROImage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROImage New(RODb myRODb, string fileName, byte[] content, DateTime dts, string userID) + { + ROImage tmp = ROImage.New(); + tmp.MyRODb = myRODb; + tmp.FileName = fileName; + tmp.Content = content; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static ROImage MakeROImage(RODb myRODb, string fileName, byte[] content, DateTime dts, string userID) + { + ROImage tmp = ROImage.New(myRODb, fileName, content, dts, userID); + if (tmp.IsSavable) + { + ROImage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ROImage Get(int imageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ROImage"); + try + { + ROImage tmp = GetCachedByPrimaryKey(imageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROImage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.Get", ex); + } + } + public static ROImage Get(SafeDataReader dr) + { + if (dr.Read()) return new ROImage(dr); + return null; + } + internal ROImage(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int imageID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROImage"); + try + { + DataPortal.Delete(new PKCriteria(imageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.Delete", ex); + } + } + public override ROImage Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ROImage"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ROImage"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ROImage"); + try + { + BuildRefreshList(); + ROImage rOImage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(rOImage);//Refresh the item in AllList + ProcessRefreshList(); + return rOImage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ImageID; + public int ImageID + { get { return _ImageID; } } + public PKCriteria(int imageID) + { + _ImageID = imageID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ImageID = NextImageID; + // Database Defaults + _DTS = _ROImageExtension.DefaultDTS; + _UserID = _ROImageExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.ReadData", GetHashCode()); + try + { + _ImageID = dr.GetInt32("ImageID"); + _RODbID = dr.GetInt32("RODbID"); + _FileName = dr.GetString("FileName"); + _Content = (byte[])dr.GetValue("Content"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROImageROFstImageCount = dr.GetInt32("ROFstImageCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROImage"; + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _ROImageROFstImages = ROImageROFstImages.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addROImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Content", _Content); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UserID", _UserID); + // Output Calculated Columns + SqlParameter param_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); + param_ImageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ImageID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _ImageID = (int)cm.Parameters["@newImageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_ROImageROFstImages != null) _ROImageROFstImages.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int imageID, RODb myRODb, string fileName, byte[] content, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addROImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); + cm.Parameters.AddWithValue("@FileName", fileName); + cm.Parameters.AddWithValue("@Content", content); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UserID", userID); + // Output Calculated Columns + SqlParameter param_ImageID = new SqlParameter("@newImageID", SqlDbType.Int); + param_ImageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ImageID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + imageID = (int)cm.Parameters["@newImageID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Add", ex); + throw new DbCslaException("ROImage.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ROImage.SQLUpdate", GetHashCode()); + try + { + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateROImage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ImageID", _ImageID); + cm.Parameters.AddWithValue("@RODbID", RODbID); + cm.Parameters.AddWithValue("@FileName", _FileName); + cm.Parameters.AddWithValue("@Content", _Content); + 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); + // TODO: 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 (_ROImageROFstImages != null) _ROImageROFstImages.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ROImage.Add(cn, ref _ImageID, _MyRODb, _FileName, _Content, _DTS, _UserID); + else + _LastChanged = ROImage.Update(cn, ref _ImageID, _MyRODb, _FileName, _Content, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_ROImageROFstImages != null) _ROImageROFstImages.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int imageID, RODb myRODb, string fileName, byte[] content, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateROImage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ImageID", imageID); + cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID); + cm.Parameters.AddWithValue("@FileName", fileName); + cm.Parameters.AddWithValue("@Content", content); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Update", ex); + throw new DbCslaException("ROImage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ImageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteROImage"; + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImage.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int imageID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteROImage"; + // Input PK Fields + cm.Parameters.AddWithValue("@ImageID", imageID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.Remove", ex); + throw new DbCslaException("ROImage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int imageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(imageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ImageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int imageID) + { + _ImageID = imageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsROImage"; + cm.Parameters.AddWithValue("@ImageID", _ImageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImage.DataPortal_Execute", ex); + throw new DbCslaException("ROImage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ROImageExtension _ROImageExtension = new ROImageExtension(); + [Serializable()] + partial class ROImageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROImage) + { + // Return the ToString value + return ((ROImage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageInfo.cs index d9b9519b..dcee318b 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageInfo.cs @@ -19,410 +19,401 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ROImageInfoEvent(object sender); - /// - /// ROImageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROImageInfoConverter))] - public partial class ROImageInfo : ReadOnlyBase, IDisposable - { - public event ROImageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ROImageInfo rOImageInfo) - { - if (!_CacheList.Contains(rOImageInfo)) _CacheList.Add(rOImageInfo); // In AddToCache - } - protected static void RemoveFromCache(ROImageInfo rOImageInfo) - { - while (_CacheList.Contains(rOImageInfo)) _CacheList.Remove(rOImageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ROImageInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ImageID.ToString())) - { - _CacheByPrimaryKey[tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ROImageInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(ROImageInfoList lst) - { - foreach (ROImageInfo item in lst) AddToCache(item); - } - protected static ROImageInfo GetCachedByPrimaryKey(int imageID) - { - ConvertListToDictionary(); - string key = imageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ROImage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ImageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ImageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ImageID", true); - return _ImageID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODbInfo _MyRODb; - public RODbInfo MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); - return _MyRODb; - } - } - private string _FileName = string.Empty; - public string FileName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FileName", true); - return _FileName; - } - } - private byte[] _Content; - public byte[] Content - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Content", true); - return _Content; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _ROImageROFstImageCount = 0; - /// - /// Count of ROImageROFstImages for this ROImage - /// - public int ROImageROFstImageCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageROFstImageCount", true); - return _ROImageROFstImageCount; - } - } - private ROFstImageInfoList _ROImageROFstImages = null; - [TypeConverter(typeof(ROFstImageInfoListConverter))] - public ROFstImageInfoList ROImageROFstImages - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROImageROFstImages", true); - if (_ROImageROFstImageCount < 0 || (_ROImageROFstImageCount > 0 && _ROImageROFstImages == null)) - _ROImageROFstImages = ROFstImageInfoList.GetByImageID(_ImageID); - if (_ROImageROFstImageCount < 0) - _ROImageROFstImageCount = _ROImageROFstImages.Count; - return _ROImageROFstImages; - } - } - public void RefreshROImageROFstImages() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_ImageID.ToString())) - foreach (ROImageInfo tmp in _CacheByPrimaryKey[_ImageID.ToString()]) - tmp._ROImageROFstImageCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base ROImageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ROImageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROImageInfo - protected override object GetIdValue() - { - return _ImageID; - } - #endregion - #region Factory Methods - private static int _ROImageInfoUnique = 0; - private static int ROImageInfoUnique - { get { return ++_ROImageInfoUnique; } } - private int _MyROImageInfoUnique = ROImageInfoUnique; - public int MyROImageInfoUnique - { get { return _MyROImageInfoUnique; } } - protected ROImageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) return; - List listROImageInfo = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items - while (listROImageInfo.Contains(this)) listROImageInfo.Remove(this); // Remove the item from the list - if (listROImageInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list - } - public virtual ROImage Get() - { - return _Editable = ROImage.Get(_ImageID); - } - public static void Refresh(ROImage tmp) - { - string key = tmp.ImageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ROImage tmp) - { - if (_RODbID != tmp.RODbID) - { - if (MyRODb != null) MyRODb.RefreshRODbROImages(); // 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.RefreshRODbROImages(); // Update List for new value - _FileName = tmp.FileName; - _Content = tmp.Content; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROImageInfoExtension.Refresh(this); - if(_MyRODb != null) - { - _MyRODb.Dispose();// Dispose related value - _MyRODb = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(RODbROImage tmp) - { - string key = tmp.ImageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODbROImage tmp) - { - _FileName = tmp.FileName; - _Content = tmp.Content; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _ROImageInfoExtension.Refresh(this); - if(_MyRODb != null) - { - _MyRODb.Dispose();// Dispose related value - _MyRODb = null;// Reset related value - } - OnChange();// raise an event - } - public static ROImageInfo Get(int imageID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ROImage"); - try - { - ROImageInfo tmp = GetCachedByPrimaryKey(imageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(imageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ROImageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ROImageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ROImageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.Constructor", ex); - throw new DbCslaException("ROImageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ImageID; - public int ImageID - { get { return _ImageID; } } - public PKCriteria(int imageID) - { - _ImageID = imageID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.ReadData", GetHashCode()); - try - { - _ImageID = dr.GetInt32("ImageID"); - _RODbID = dr.GetInt32("RODbID"); - _FileName = dr.GetString("FileName"); - _Content = (byte[])dr.GetValue("Content"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _ROImageROFstImageCount = dr.GetInt32("ROFstImageCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getROImage"; - cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ROImageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ROImageInfoExtension _ROImageInfoExtension = new ROImageInfoExtension(); - [Serializable()] - partial class ROImageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ROImageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ROImageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROImageInfo) - { - // Return the ToString value - return ((ROImageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ROImageInfoEvent(object sender); + /// + /// ROImageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROImageInfoConverter))] + public partial class ROImageInfo : ReadOnlyBase, IDisposable + { + public event ROImageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ROImageInfo rOImageInfo) + { + if (!_CacheList.Contains(rOImageInfo)) _CacheList.Add(rOImageInfo); // In AddToCache + } + protected static void RemoveFromCache(ROImageInfo rOImageInfo) + { + while (_CacheList.Contains(rOImageInfo)) _CacheList.Remove(rOImageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ROImageInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ImageID.ToString())) + { + _CacheByPrimaryKey[tmp.ImageID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ImageID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ROImageInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(ROImageInfoList lst) + { + foreach (ROImageInfo item in lst) AddToCache(item); + } + protected static ROImageInfo GetCachedByPrimaryKey(int imageID) + { + ConvertListToDictionary(); + string key = imageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ROImage _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ImageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ImageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ImageID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODbInfo _MyRODb; + public RODbInfo MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); + return _MyRODb; + } + } + private string _FileName = string.Empty; + public string FileName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FileName; + } + } + private byte[] _Content; + public byte[] Content + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Content; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _ROImageROFstImageCount = 0; + /// + /// Count of ROImageROFstImages for this ROImage + /// + public int ROImageROFstImageCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROImageROFstImageCount; + } + } + private ROFstImageInfoList _ROImageROFstImages = null; + [TypeConverter(typeof(ROFstImageInfoListConverter))] + public ROFstImageInfoList ROImageROFstImages + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_ROImageROFstImageCount < 0 || (_ROImageROFstImageCount > 0 && _ROImageROFstImages == null)) + _ROImageROFstImages = ROFstImageInfoList.GetByImageID(_ImageID); + if (_ROImageROFstImageCount < 0) + _ROImageROFstImageCount = _ROImageROFstImages.Count; + return _ROImageROFstImages; + } + } + public void RefreshROImageROFstImages() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_ImageID.ToString())) + foreach (ROImageInfo tmp in _CacheByPrimaryKey[_ImageID.ToString()]) + tmp._ROImageROFstImageCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base ROImageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROImageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ROImageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROImageInfo + protected override object GetIdValue() + { + return _ImageID; + } + #endregion + #region Factory Methods + private static int _ROImageInfoUnique = 0; + private static int ROImageInfoUnique + { get { return ++_ROImageInfoUnique; } } + private int _MyROImageInfoUnique = ROImageInfoUnique; + public int MyROImageInfoUnique + { get { return _MyROImageInfoUnique; } } + protected ROImageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ImageID.ToString())) return; + List listROImageInfo = _CacheByPrimaryKey[ImageID.ToString()]; // Get the list of items + while (listROImageInfo.Contains(this)) listROImageInfo.Remove(this); // Remove the item from the list + if (listROImageInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ImageID.ToString()); // remove the list + } + public virtual ROImage Get() + { + return _Editable = ROImage.Get(_ImageID); + } + public static void Refresh(ROImage tmp) + { + string key = tmp.ImageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ROImage tmp) + { + if (_RODbID != tmp.RODbID) + { + if (MyRODb != null) MyRODb.RefreshRODbROImages(); // 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.RefreshRODbROImages(); // Update List for new value + _FileName = tmp.FileName; + _Content = tmp.Content; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROImageInfoExtension.Refresh(this); + if (_MyRODb != null) + { + _MyRODb.Dispose();// Dispose related value + _MyRODb = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(RODbROImage tmp) + { + string key = tmp.ImageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ROImageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODbROImage tmp) + { + _FileName = tmp.FileName; + _Content = tmp.Content; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _ROImageInfoExtension.Refresh(this); + if (_MyRODb != null) + { + _MyRODb.Dispose();// Dispose related value + _MyRODb = null;// Reset related value + } + OnChange();// raise an event + } + public static ROImageInfo Get(int imageID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ROImage"); + try + { + ROImageInfo tmp = GetCachedByPrimaryKey(imageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(imageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ROImageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ROImageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ROImageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.Constructor", ex); + throw new DbCslaException("ROImageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ImageID; + public int ImageID + { get { return _ImageID; } } + public PKCriteria(int imageID) + { + _ImageID = imageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.ReadData", GetHashCode()); + try + { + _ImageID = dr.GetInt32("ImageID"); + _RODbID = dr.GetInt32("RODbID"); + _FileName = dr.GetString("FileName"); + _Content = (byte[])dr.GetValue("Content"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _ROImageROFstImageCount = dr.GetInt32("ROFstImageCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getROImage"; + cm.Parameters.AddWithValue("@ImageID", criteria.ImageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ROImageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ROImageInfoExtension _ROImageInfoExtension = new ROImageInfoExtension(); + [Serializable()] + partial class ROImageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ROImageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ROImageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROImageInfo) + { + // Return the ToString value + return ((ROImageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageROFstImage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageROFstImage.cs index 3e32f439..f8e5d5a9 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageROFstImage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ROImageROFstImage.cs @@ -19,374 +19,364 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ROImageROFstImage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ROImageROFstImageConverter))] - public partial class ROImageROFstImage : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _ROFstID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROFstID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFstID", true); - if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; - return _ROFstID; - } - } - private ROFst _MyROFst; - [System.ComponentModel.DataObjectField(true, true)] - public ROFst MyROFst - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyROFst", true); - if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); - return _MyROFst; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - 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 - { - CanReadProperty("ROFst_RODbID", true); - return _ROFst_RODbID; - } - } - private byte[] _ROFst_ROFST; - public byte[] ROFst_ROFST - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_ROFST", true); - return _ROFst_ROFST; - } - } - private DateTime _ROFst_DTS = new DateTime(); - public DateTime ROFst_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_DTS", true); - return _ROFst_DTS; - } - } - private string _ROFst_UserID = string.Empty; - public string ROFst_UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROFst_UserID", true); - return _ROFst_UserID; - } - } - // TODO: Check ROImageROFstImage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ROImageROFstImage - protected override object GetIdValue() - { - return _ROFstID; - } - // TODO: Replace base ROImageROFstImage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ROImageROFstImage - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROFstID, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static ROImageROFstImage New(ROFst myROFst) - { - return new ROImageROFstImage(myROFst); - } - internal static ROImageROFstImage Get(SafeDataReader dr) - { - return new ROImageROFstImage(dr); - } - public ROImageROFstImage() - { - MarkAsChild(); + /// + /// ROImageROFstImage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ROImageROFstImageConverter))] + public partial class ROImageROFstImage : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _ROFstID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROFstID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst != null) _ROFstID = _MyROFst.ROFstID; + return _ROFstID; + } + } + private ROFst _MyROFst; + [System.ComponentModel.DataObjectField(true, true)] + public ROFst MyROFst + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyROFst == null && _ROFstID != 0) _MyROFst = ROFst.Get(_ROFstID); + return _MyROFst; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + 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_ROFST; + public byte[] ROFst_ROFST + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_ROFST; + } + } + private DateTime _ROFst_DTS = new DateTime(); + public DateTime ROFst_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_DTS; + } + } + private string _ROFst_UserID = string.Empty; + public string ROFst_UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROFst_UserID; + } + } + // TODO: Check ROImageROFstImage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ROImageROFstImage + protected override object GetIdValue() + { + return _ROFstID; + } + // TODO: Replace base ROImageROFstImage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ROImageROFstImage + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROFstID, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static ROImageROFstImage New(ROFst myROFst) + { + return new ROImageROFstImage(myROFst); + } + internal static ROImageROFstImage Get(SafeDataReader dr) + { + return new ROImageROFstImage(dr); + } + public ROImageROFstImage() + { + MarkAsChild(); - _DTS = _ROImageROFstImageExtension.DefaultDTS; - _UserID = _ROImageROFstImageExtension.DefaultUserID; - ValidationRules.CheckRules(); - } - private ROImageROFstImage(ROFst myROFst) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _DTS = _ROImageROFstImageExtension.DefaultDTS; - _UserID = _ROImageROFstImageExtension.DefaultUserID; - _MyROFst = myROFst; - ValidationRules.CheckRules(); - } - internal ROImageROFstImage(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageROFstImage.FetchDR", GetHashCode()); - try - { - _ROFstID = dr.GetInt32("ROFstID"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _ROFst_RODbID = dr.GetInt32("ROFst_RODbID"); - _ROFst_ROFST = (byte[])dr.GetValue("ROFst_ROFST"); - _ROFst_DTS = dr.GetDateTime("ROFst_DTS"); - _ROFst_UserID = dr.GetString("ROFst_UserID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageROFstImage.FetchDR", ex); - throw new DbCslaException("ROImageROFstImage.Fetch", ex); - } - MarkOld(); - } - internal void Insert(ROImage myROImage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFstImage.Add(cn, _MyROFst, myROImage, _DTS, _UserID); - MarkOld(); - } - internal void Update(ROImage myROImage) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = ROFstImage.Update(cn, _MyROFst, myROImage, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(ROImage myROImage) - { - // 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"]; - ROFstImage.Remove(cn, _ROFstID, myROImage.ImageID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - ROImageROFstImageExtension _ROImageROFstImageExtension = new ROImageROFstImageExtension(); - [Serializable()] - partial class ROImageROFstImageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ROImageROFstImageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ROImageROFstImage) - { - // Return the ToString value - return ((ROImageROFstImage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + _DTS = _ROImageROFstImageExtension.DefaultDTS; + _UserID = _ROImageROFstImageExtension.DefaultUserID; + ValidationRules.CheckRules(); + } + private ROImageROFstImage(ROFst myROFst) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _DTS = _ROImageROFstImageExtension.DefaultDTS; + _UserID = _ROImageROFstImageExtension.DefaultUserID; + _MyROFst = myROFst; + ValidationRules.CheckRules(); + } + internal ROImageROFstImage(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROImageROFstImage.FetchDR", GetHashCode()); + try + { + _ROFstID = dr.GetInt32("ROFstID"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _ROFst_RODbID = dr.GetInt32("ROFst_RODbID"); + _ROFst_ROFST = (byte[])dr.GetValue("ROFst_ROFST"); + _ROFst_DTS = dr.GetDateTime("ROFst_DTS"); + _ROFst_UserID = dr.GetString("ROFst_UserID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ROImageROFstImage.FetchDR", ex); + throw new DbCslaException("ROImageROFstImage.Fetch", ex); + } + MarkOld(); + } + internal void Insert(ROImage myROImage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFstImage.Add(cn, _MyROFst, myROImage, _DTS, _UserID); + MarkOld(); + } + internal void Update(ROImage myROImage) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = ROFstImage.Update(cn, _MyROFst, myROImage, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(ROImage myROImage) + { + // 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"]; + ROFstImage.Remove(cn, _ROFstID, myROImage.ImageID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + ROImageROFstImageExtension _ROImageROFstImageExtension = new ROImageROFstImageExtension(); + [Serializable()] + partial class ROImageROFstImageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ROImageROFstImageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ROImageROFstImage) + { + // Return the ToString value + return ((ROImageROFstImage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsage.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsage.cs index 61f9ec90..9cfda9a0 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsage.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsage.cs @@ -20,1053 +20,1038 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RoUsage Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoUsageConverter))] - public partial class RoUsage : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshRoUsages = new List(); - private void AddToRefreshList(List refreshRoUsages) - { - if (IsDirty) - refreshRoUsages.Add(this); - } - private void BuildRefreshList() - { - _RefreshRoUsages = new List(); - AddToRefreshList(_RefreshRoUsages); - } - private void ProcessRefreshList() - { - foreach (RoUsage tmp in _RefreshRoUsages) - { - RoUsageInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RoUsage roUsage) - { - if (!_CacheList.Contains(roUsage)) _CacheList.Add(roUsage); // In AddToCache - } - protected static void RemoveFromCache(RoUsage roUsage) - { - while (_CacheList.Contains(roUsage)) _CacheList.Remove(roUsage); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (RoUsage tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) - { - _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (RoUsage tmp in remove) - RemoveFromCache(tmp); - } - protected static RoUsage GetCachedByPrimaryKey(int rOUsageID) - { - ConvertListToDictionary(); - string key = rOUsageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextROUsageID = -1; - public static int NextROUsageID - { - get { return _nextROUsageID--; } - } - private int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - return _ROUsageID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - PropertyHasChanged(); - } - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("ROID", true); - if (value == null) value = string.Empty; - if (_ROID != value) - { - _ROID = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODb _MyRODb; - public RODb MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); - return _MyRODb; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyRODb", true); - if (_MyRODb != value) - { - _MyRODb = value; - PropertyHasChanged(); - } - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyRODb == null ? false : _MyRODb.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } - } - // TODO: Replace base RoUsage.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoUsage - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check RoUsage.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoUsage - protected override object GetIdValue() - { - return _ROUsageID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "ROID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule(MyRODbRequired, "MyRODb"); - //ValidationRules.AddDependantProperty("x", "y"); - _RoUsageExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _RoUsageExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyContentRequired(RoUsage target, Csla.Validation.RuleArgs e) - { - if (target._ContentID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyRODbRequired(RoUsage target, Csla.Validation.RuleArgs e) - { - if (target._RODbID == 0 && target._MyRODb == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ROUsageID, ""); - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(ROID, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(RODbID, ""); - //AuthorizationRules.AllowWrite(ContentID, ""); - //AuthorizationRules.AllowWrite(ROID, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(RODbID, ""); - _RoUsageExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _RoUsageExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _RoUsageUnique = 0; - protected static int RoUsageUnique - { get { return ++_RoUsageUnique; } } - private int _MyRoUsageUnique = RoUsageUnique; - public int MyRoUsageUnique - { get { return _MyRoUsageUnique; } } - protected RoUsage() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) - { - List listRoUsage = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items - while (listRoUsage.Contains(this)) listRoUsage.Remove(this); // Remove the item from the list - if (listRoUsage.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list - } - } - public static RoUsage New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RoUsage"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.New", ex); - } - } - public static RoUsage New(string roid, RODb myRODb) - { - RoUsage tmp = RoUsage.New(); - tmp.ROID = roid; - tmp.MyRODb = myRODb; - return tmp; - } - public static RoUsage New(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - RoUsage tmp = RoUsage.New(); - tmp.MyContent = myContent; - tmp.ROID = roid; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - tmp.MyRODb = myRODb; - return tmp; - } - public static RoUsage MakeRoUsage(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID, myRODb); - if (tmp.IsSavable) - { - RoUsage tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RoUsage New(Content myContent, string roid, string config, RODb myRODb) - { - RoUsage tmp = RoUsage.New(); - tmp.MyContent = myContent; - tmp.ROID = roid; - tmp.Config = config; - tmp.MyRODb = myRODb; - return tmp; - } - public static RoUsage MakeRoUsage(Content myContent, string roid, string config, RODb myRODb) - { - RoUsage tmp = RoUsage.New(myContent, roid, config, myRODb); - if (tmp.IsSavable) - { - RoUsage tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static RoUsage Get(int rOUsageID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a RoUsage"); - try - { - RoUsage tmp = GetCachedByPrimaryKey(rOUsageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RoUsage - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.Get", ex); - } - } - public static RoUsage Get(SafeDataReader dr) - { - if (dr.Read()) return new RoUsage(dr); - return null; - } - internal RoUsage(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rOUsageID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); - try - { - DataPortal.Delete(new PKCriteria(rOUsageID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.Delete", ex); - } - } - public override RoUsage Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a RoUsage"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a RoUsage"); - try - { - BuildRefreshList(); - RoUsage roUsage = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(roUsage);//Refresh the item in AllList - ProcessRefreshList(); - return roUsage; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ROUsageID; - public int ROUsageID - { get { return _ROUsageID; } } - public PKCriteria(int rOUsageID) - { - _ROUsageID = rOUsageID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _ROUsageID = NextROUsageID; - // Database Defaults - _ContentID = _RoUsageExtension.DefaultContentID; - _DTS = _RoUsageExtension.DefaultDTS; - _UserID = _RoUsageExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.ReadData", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ContentID = dr.GetInt32("ContentID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RODbID = dr.GetInt32("RODbID"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRoUsage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", ContentID); - 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_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); - param_ROUsageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROUsageID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _ROUsageID = (int)cm.Parameters["@newROUsageID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRoUsage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - 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", myRODb.RODbID); - // Output Calculated Columns - SqlParameter param_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); - param_ROUsageID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ROUsageID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - rOUsageID = (int)cm.Parameters["@newROUsageID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Add", ex); - throw new DbCslaException("RoUsage.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] RoUsage.SQLUpdate", GetHashCode()); - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyRODb != null) _MyRODb.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRoUsage"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); - cm.Parameters.AddWithValue("@ContentID", ContentID); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, _MyRODb); - else - _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _MyRODb); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, ref byte[] lastChanged, RODb myRODb) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRoUsage"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - 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", myRODb.RODbID); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Update", ex); - throw new DbCslaException("RoUsage.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ROUsageID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsage.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rOUsageID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRoUsage"; - // Input PK Fields - cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Remove", ex); - throw new DbCslaException("RoUsage.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rOUsageID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rOUsageID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsage.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ROUsageID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rOUsageID) - { - _ROUsageID = rOUsageID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Execute", ex); - throw new DbCslaException("RoUsage.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - RoUsageExtension _RoUsageExtension = new RoUsageExtension(); - [Serializable()] - partial class RoUsageExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultContentID - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RoUsageConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoUsage) - { - // Return the ToString value - return ((RoUsage)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RoUsage Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoUsageConverter))] + public partial class RoUsage : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRoUsages = new List(); + private void AddToRefreshList(List refreshRoUsages) + { + if (IsDirty) + refreshRoUsages.Add(this); + } + private void BuildRefreshList() + { + _RefreshRoUsages = new List(); + AddToRefreshList(_RefreshRoUsages); + } + private void ProcessRefreshList() + { + foreach (RoUsage tmp in _RefreshRoUsages) + { + RoUsageInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + if (tmp._MyRODb != null) RODbInfo.Refresh(tmp._MyRODb); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RoUsage roUsage) + { + if (!_CacheList.Contains(roUsage)) _CacheList.Add(roUsage); // In AddToCache + } + protected static void RemoveFromCache(RoUsage roUsage) + { + while (_CacheList.Contains(roUsage)) _CacheList.Remove(roUsage); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RoUsage tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) + { + _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (RoUsage tmp in remove) + RemoveFromCache(tmp); + } + protected static RoUsage GetCachedByPrimaryKey(int rOUsageID) + { + ConvertListToDictionary(); + string key = rOUsageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextROUsageID = -1; + public static int NextROUsageID + { + get { return _nextROUsageID--; } + } + private int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROUsageID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + PropertyHasChanged(); + } + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_ROID != value) + { + _ROID = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODb _MyRODb; + public RODb MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODb.Get(_RODbID); + return _MyRODb; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyRODb != value) + { + _MyRODb = value; + PropertyHasChanged(); + } + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyRODb == null ? false : _MyRODb.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyRODb == null ? true : _MyRODb.IsValid); } + } + // TODO: Replace base RoUsage.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoUsage + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check RoUsage.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoUsage + protected override object GetIdValue() + { + return _ROUsageID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + if (_MyRODb != null && (hasBrokenRules = _MyRODb.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "ROID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ROID", 16)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule(MyRODbRequired, "MyRODb"); + //ValidationRules.AddDependantProperty("x", "y"); + _RoUsageExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _RoUsageExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyContentRequired(RoUsage target, Csla.Validation.RuleArgs e) + { + if (target._ContentID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyRODbRequired(RoUsage target, Csla.Validation.RuleArgs e) + { + if (target._RODbID == 0 && target._MyRODb == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ROUsageID, ""); + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(ROID, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(RODbID, ""); + //AuthorizationRules.AllowWrite(ContentID, ""); + //AuthorizationRules.AllowWrite(ROID, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(RODbID, ""); + _RoUsageExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _RoUsageExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _RoUsageUnique = 0; + protected static int RoUsageUnique + { get { return ++_RoUsageUnique; } } + private int _MyRoUsageUnique = RoUsageUnique; + public int MyRoUsageUnique + { get { return _MyRoUsageUnique; } } + protected RoUsage() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) + { + List listRoUsage = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items + while (listRoUsage.Contains(this)) listRoUsage.Remove(this); // Remove the item from the list + if (listRoUsage.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list + } + } + public static RoUsage New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RoUsage"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.New", ex); + } + } + public static RoUsage New(string roid, RODb myRODb) + { + RoUsage tmp = RoUsage.New(); + tmp.ROID = roid; + tmp.MyRODb = myRODb; + return tmp; + } + public static RoUsage New(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + RoUsage tmp = RoUsage.New(); + tmp.MyContent = myContent; + tmp.ROID = roid; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + tmp.MyRODb = myRODb; + return tmp; + } + public static RoUsage MakeRoUsage(Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + RoUsage tmp = RoUsage.New(myContent, roid, config, dts, userID, myRODb); + if (tmp.IsSavable) + { + RoUsage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RoUsage New(Content myContent, string roid, string config, RODb myRODb) + { + RoUsage tmp = RoUsage.New(); + tmp.MyContent = myContent; + tmp.ROID = roid; + tmp.Config = config; + tmp.MyRODb = myRODb; + return tmp; + } + public static RoUsage MakeRoUsage(Content myContent, string roid, string config, RODb myRODb) + { + RoUsage tmp = RoUsage.New(myContent, roid, config, myRODb); + if (tmp.IsSavable) + { + RoUsage tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static RoUsage Get(int rOUsageID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a RoUsage"); + try + { + RoUsage tmp = GetCachedByPrimaryKey(rOUsageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoUsage + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.Get", ex); + } + } + public static RoUsage Get(SafeDataReader dr) + { + if (dr.Read()) return new RoUsage(dr); + return null; + } + internal RoUsage(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rOUsageID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); + try + { + DataPortal.Delete(new PKCriteria(rOUsageID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.Delete", ex); + } + } + public override RoUsage Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a RoUsage"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a RoUsage"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a RoUsage"); + try + { + BuildRefreshList(); + RoUsage roUsage = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(roUsage);//Refresh the item in AllList + ProcessRefreshList(); + return roUsage; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ROUsageID; + public int ROUsageID + { get { return _ROUsageID; } } + public PKCriteria(int rOUsageID) + { + _ROUsageID = rOUsageID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _ROUsageID = NextROUsageID; + // Database Defaults + _ContentID = _RoUsageExtension.DefaultContentID; + _DTS = _RoUsageExtension.DefaultDTS; + _UserID = _RoUsageExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.ReadData", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ContentID = dr.GetInt32("ContentID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RODbID = dr.GetInt32("RODbID"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRoUsage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", ContentID); + 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_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); + param_ROUsageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROUsageID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _ROUsageID = (int)cm.Parameters["@newROUsageID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, RODb myRODb) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRoUsage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + 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", myRODb.RODbID); + // Output Calculated Columns + SqlParameter param_ROUsageID = new SqlParameter("@newROUsageID", SqlDbType.Int); + param_ROUsageID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ROUsageID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + rOUsageID = (int)cm.Parameters["@newROUsageID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Add", ex); + throw new DbCslaException("RoUsage.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] RoUsage.SQLUpdate", GetHashCode()); + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyRODb != null) _MyRODb.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRoUsage"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); + cm.Parameters.AddWithValue("@ContentID", ContentID); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = RoUsage.Add(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, _MyRODb); + else + _LastChanged = RoUsage.Update(cn, ref _ROUsageID, _MyContent, _ROID, _Config, _DTS, _UserID, ref _LastChanged, _MyRODb); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rOUsageID, Content myContent, string roid, string config, DateTime dts, string userID, ref byte[] lastChanged, RODb myRODb) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRoUsage"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + 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", myRODb.RODbID); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Update", ex); + throw new DbCslaException("RoUsage.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ROUsageID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsage.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rOUsageID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRoUsage"; + // Input PK Fields + cm.Parameters.AddWithValue("@ROUsageID", rOUsageID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.Remove", ex); + throw new DbCslaException("RoUsage.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rOUsageID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rOUsageID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsage.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ROUsageID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rOUsageID) + { + _ROUsageID = rOUsageID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsage.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", _ROUsageID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsage.DataPortal_Execute", ex); + throw new DbCslaException("RoUsage.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + RoUsageExtension _RoUsageExtension = new RoUsageExtension(); + [Serializable()] + partial class RoUsageExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultContentID + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RoUsageConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoUsage) + { + // Return the ToString value + return ((RoUsage)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsageInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsageInfo.cs index 4690708e..6cae7319 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsageInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoUsageInfo.cs @@ -19,455 +19,446 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void RoUsageInfoEvent(object sender); - /// - /// RoUsageInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoUsageInfoConverter))] - public partial class RoUsageInfo : ReadOnlyBase, IDisposable - { - public event RoUsageInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RoUsageInfo roUsageInfo) - { - if (!_CacheList.Contains(roUsageInfo)) _CacheList.Add(roUsageInfo); // In AddToCache - } - protected static void RemoveFromCache(RoUsageInfo roUsageInfo) - { - while (_CacheList.Contains(roUsageInfo)) _CacheList.Remove(roUsageInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (RoUsageInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) - { - _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (RoUsageInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(RoUsageInfoList lst) - { - foreach (RoUsageInfo item in lst) AddToCache(item); - } - protected static RoUsageInfo GetCachedByPrimaryKey(int rOUsageID) - { - ConvertListToDictionary(); - string key = rOUsageID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected RoUsage _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _ROUsageID; - [System.ComponentModel.DataObjectField(true, true)] - public int ROUsageID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROUsageID", true); - return _ROUsageID; - } - } - private int _ContentID; - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private string _ROID = string.Empty; - public string ROID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ROID", true); - return _ROID; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _RODbID; - public int RODbID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RODbID", true); - if (_MyRODb != null) _RODbID = _MyRODb.RODbID; - return _RODbID; - } - } - private RODbInfo _MyRODb; - public RODbInfo MyRODb - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyRODb", true); - if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); - return _MyRODb; - } - } - // TODO: Replace base RoUsageInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoUsageInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check RoUsageInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoUsageInfo - protected override object GetIdValue() - { - return _ROUsageID; - } - #endregion - #region Factory Methods - private static int _RoUsageInfoUnique = 0; - private static int RoUsageInfoUnique - { get { return ++_RoUsageInfoUnique; } } - private int _MyRoUsageInfoUnique = RoUsageInfoUnique; - public int MyRoUsageInfoUnique - { get { return _MyRoUsageInfoUnique; } } - protected RoUsageInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; - List listRoUsageInfo = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items - while (listRoUsageInfo.Contains(this)) listRoUsageInfo.Remove(this); // Remove the item from the list - if (listRoUsageInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list - } - public virtual RoUsage Get() - { - return _Editable = RoUsage.Get(_ROUsageID); - } - public static void Refresh(RoUsage tmp) - { - string key = tmp.ROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RoUsage tmp) - { - if (_ContentID != tmp.ContentID) - { - if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // 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.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value - _RoUsageInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyRODb != null) - { - _MyRODb.Dispose();// Dispose related value - _MyRODb = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(ContentRoUsage tmp) - { - string key = tmp.ROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentRoUsage tmp) - { - _ROID = tmp.ROID; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - if (_RODbID != tmp.RODbID) - { - if (MyRODb != null) MyRODb.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value - _RoUsageInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyRODb != null) - { - _MyRODb.Dispose();// Dispose related value - _MyRODb = null;// Reset related value - } - OnChange();// raise an event - } - public static void Refresh(RODbRoUsage tmp) - { - string key = tmp.ROUsageID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(RODbRoUsage tmp) - { - if (_ContentID != tmp.ContentID) - { - if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // Update List for new value - _ROID = tmp.ROID; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _RoUsageInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyRODb != null) - { - _MyRODb.Dispose();// Dispose related value - _MyRODb = null;// Reset related value - } - OnChange();// raise an event - } - public static RoUsageInfo Get(int rOUsageID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a RoUsage"); - try - { - RoUsageInfo tmp = GetCachedByPrimaryKey(rOUsageID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RoUsageInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoUsageInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal RoUsageInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.Constructor", ex); - throw new DbCslaException("RoUsageInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ROUsageID; - public int ROUsageID - { get { return _ROUsageID; } } - public PKCriteria(int rOUsageID) - { - _ROUsageID = rOUsageID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.ReadData", GetHashCode()); - try - { - _ROUsageID = dr.GetInt32("ROUsageID"); - _ContentID = dr.GetInt32("ContentID"); - _ROID = dr.GetString("ROID"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _RODbID = dr.GetInt32("RODbID"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsageInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRoUsage"; - cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoUsageInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - RoUsageInfoExtension _RoUsageInfoExtension = new RoUsageInfoExtension(); - [Serializable()] - partial class RoUsageInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(RoUsageInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class RoUsageInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoUsageInfo) - { - // Return the ToString value - return ((RoUsageInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void RoUsageInfoEvent(object sender); + /// + /// RoUsageInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoUsageInfoConverter))] + public partial class RoUsageInfo : ReadOnlyBase, IDisposable + { + public event RoUsageInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RoUsageInfo roUsageInfo) + { + if (!_CacheList.Contains(roUsageInfo)) _CacheList.Add(roUsageInfo); // In AddToCache + } + protected static void RemoveFromCache(RoUsageInfo roUsageInfo) + { + while (_CacheList.Contains(roUsageInfo)) _CacheList.Remove(roUsageInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RoUsageInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ROUsageID.ToString())) + { + _CacheByPrimaryKey[tmp.ROUsageID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ROUsageID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (RoUsageInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(RoUsageInfoList lst) + { + foreach (RoUsageInfo item in lst) AddToCache(item); + } + protected static RoUsageInfo GetCachedByPrimaryKey(int rOUsageID) + { + ConvertListToDictionary(); + string key = rOUsageID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected RoUsage _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _ROUsageID; + [System.ComponentModel.DataObjectField(true, true)] + public int ROUsageID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROUsageID; + } + } + private int _ContentID; + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private string _ROID = string.Empty; + public string ROID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ROID; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _RODbID; + public int RODbID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb != null) _RODbID = _MyRODb.RODbID; + return _RODbID; + } + } + private RODbInfo _MyRODb; + public RODbInfo MyRODb + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyRODb == null && _RODbID != 0) _MyRODb = RODbInfo.Get(_RODbID); + return _MyRODb; + } + } + // TODO: Replace base RoUsageInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoUsageInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check RoUsageInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoUsageInfo + protected override object GetIdValue() + { + return _ROUsageID; + } + #endregion + #region Factory Methods + private static int _RoUsageInfoUnique = 0; + private static int RoUsageInfoUnique + { get { return ++_RoUsageInfoUnique; } } + private int _MyRoUsageInfoUnique = RoUsageInfoUnique; + public int MyRoUsageInfoUnique + { get { return _MyRoUsageInfoUnique; } } + protected RoUsageInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ROUsageID.ToString())) return; + List listRoUsageInfo = _CacheByPrimaryKey[ROUsageID.ToString()]; // Get the list of items + while (listRoUsageInfo.Contains(this)) listRoUsageInfo.Remove(this); // Remove the item from the list + if (listRoUsageInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ROUsageID.ToString()); // remove the list + } + public virtual RoUsage Get() + { + return _Editable = RoUsage.Get(_ROUsageID); + } + public static void Refresh(RoUsage tmp) + { + string key = tmp.ROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RoUsage tmp) + { + if (_ContentID != tmp.ContentID) + { + if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // 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.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value + _RoUsageInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyRODb != null) + { + _MyRODb.Dispose();// Dispose related value + _MyRODb = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(ContentRoUsage tmp) + { + string key = tmp.ROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentRoUsage tmp) + { + _ROID = tmp.ROID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + if (_RODbID != tmp.RODbID) + { + if (MyRODb != null) MyRODb.RefreshRODbRoUsages(); // 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.RefreshRODbRoUsages(); // Update List for new value + _RoUsageInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyRODb != null) + { + _MyRODb.Dispose();// Dispose related value + _MyRODb = null;// Reset related value + } + OnChange();// raise an event + } + public static void Refresh(RODbRoUsage tmp) + { + string key = tmp.ROUsageID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoUsageInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(RODbRoUsage tmp) + { + if (_ContentID != tmp.ContentID) + { + if (MyContent != null) MyContent.RefreshContentRoUsages(); // 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.RefreshContentRoUsages(); // Update List for new value + _ROID = tmp.ROID; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _RoUsageInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyRODb != null) + { + _MyRODb.Dispose();// Dispose related value + _MyRODb = null;// Reset related value + } + OnChange();// raise an event + } + public static RoUsageInfo Get(int rOUsageID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a RoUsage"); + try + { + RoUsageInfo tmp = GetCachedByPrimaryKey(rOUsageID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rOUsageID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoUsageInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoUsageInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RoUsageInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.Constructor", ex); + throw new DbCslaException("RoUsageInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ROUsageID; + public int ROUsageID + { get { return _ROUsageID; } } + public PKCriteria(int rOUsageID) + { + _ROUsageID = rOUsageID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.ReadData", GetHashCode()); + try + { + _ROUsageID = dr.GetInt32("ROUsageID"); + _ContentID = dr.GetInt32("ContentID"); + _ROID = dr.GetString("ROID"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _RODbID = dr.GetInt32("RODbID"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsageInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoUsageInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoUsage"; + cm.Parameters.AddWithValue("@ROUsageID", criteria.ROUsageID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoUsageInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoUsageInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RoUsageInfoExtension _RoUsageInfoExtension = new RoUsageInfoExtension(); + [Serializable()] + partial class RoUsageInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RoUsageInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RoUsageInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoUsageInfo) + { + // Return the ToString value + return ((RoUsageInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Role.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Role.cs index 8a039745..e537da3e 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Role.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Role.cs @@ -20,1143 +20,1130 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Role Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoleConverter))] - public partial class Role : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshRoles = new List(); - private List _RefreshRoleAssignments = new List(); - private List _RefreshRolePermissions = new List(); - private void AddToRefreshList(List refreshRoles, List refreshRoleAssignments, List refreshRolePermissions) - { - if (IsDirty) - refreshRoles.Add(this); - if (_RoleAssignments != null && _RoleAssignments.IsDirty) - { - foreach (RoleAssignment tmp in _RoleAssignments) - { - if (tmp.IsDirty) refreshRoleAssignments.Add(tmp); - } - } - if (_RolePermissions != null && _RolePermissions.IsDirty) - { - foreach (RolePermission tmp in _RolePermissions) - { - if (tmp.IsDirty) refreshRolePermissions.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshRoles = new List(); - _RefreshRoleAssignments = new List(); - _RefreshRolePermissions = new List(); - AddToRefreshList(_RefreshRoles, _RefreshRoleAssignments, _RefreshRolePermissions); - } - private void ProcessRefreshList() - { - foreach (Role tmp in _RefreshRoles) - { - RoleInfo.Refresh(tmp); - } - foreach (RoleAssignment tmp in _RefreshRoleAssignments) - { - AssignmentInfo.Refresh(tmp); - } - foreach (RolePermission tmp in _RefreshRolePermissions) - { - PermissionInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Role role) - { - if (!_CacheList.Contains(role)) _CacheList.Add(role); // In AddToCache - } - protected static void RemoveFromCache(Role role) - { - while (_CacheList.Contains(role)) _CacheList.Remove(role); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static Dictionary> _CacheByName = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Role tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString())) - { - _CacheByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey - _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name - } - _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list - _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index - remove.Add(tmp); - } - foreach (Role tmp in remove) - RemoveFromCache(tmp); - } - protected static Role GetCachedByPrimaryKey(int rid) - { - ConvertListToDictionary(); - string key = rid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - protected static Role GetCachedByName(string name) - { - ConvertListToDictionary(); - string key = name.ToString(); - if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextRID = -1; - public static int NextRID - { - get { return _nextRID--; } - } - private int _RID; - [System.ComponentModel.DataObjectField(true, true)] - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - return _RID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Name", true); - if (value == null) value = string.Empty; - if (_Name != value) - { - _Name = value; - PropertyHasChanged(); - } - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Title", true); - if (value == null) value = string.Empty; - if (_Title != value) - { - _Title = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _RoleAssignmentCount = 0; - /// - /// Count of RoleAssignments for this Role - /// - public int RoleAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignmentCount", true); - return _RoleAssignmentCount; - } - } - private RoleAssignments _RoleAssignments = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RoleAssignmentsConverter))] - public RoleAssignments RoleAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignments", true); - if (_RoleAssignmentCount > 0 && _RoleAssignments == null) - _RoleAssignments = RoleAssignments.GetByRID(RID); - else if (_RoleAssignments == null) - _RoleAssignments = RoleAssignments.New(); - return _RoleAssignments; - } - } - private int _RolePermissionCount = 0; - /// - /// Count of RolePermissions for this Role - /// - public int RolePermissionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissionCount", true); - return _RolePermissionCount; - } - } - private RolePermissions _RolePermissions = null; - /// - /// Related Field - /// - [TypeConverter(typeof(RolePermissionsConverter))] - public RolePermissions RolePermissions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissions", true); - if (_RolePermissionCount > 0 && _RolePermissions == null) - _RolePermissions = RolePermissions.GetByRID(RID); - else if (_RolePermissions == null) - _RolePermissions = RolePermissions.New(); - return _RolePermissions; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_RoleAssignments == null ? false : _RoleAssignments.IsDirty) || (_RolePermissions == null ? false : _RolePermissions.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_RoleAssignments == null ? true : _RoleAssignments.IsValid) && (_RolePermissions == null ? true : _RolePermissions.IsValid); } - } - // TODO: Replace base Role.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Role - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Role.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Role - protected override object GetIdValue() - { - return _RID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_RoleAssignments != null && (hasBrokenRules = _RoleAssignments.HasBrokenRules) != null) return hasBrokenRules; - if (_RolePermissions != null && (hasBrokenRules = _RolePermissions.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Title"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _RoleExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _RoleExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(RID, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _RoleExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _RoleExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _RoleAssignmentCount; - usedByCount += _RolePermissionCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _RoleUnique = 0; - protected static int RoleUnique - { get { return ++_RoleUnique; } } - private int _MyRoleUnique = RoleUnique; - public int MyRoleUnique - { get { return _MyRoleUnique; } } - protected Role() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(RID.ToString())) - { - List listRole = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items - while (listRole.Contains(this)) listRole.Remove(this); // Remove the item from the list - if (listRole.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list - } - string myKey; - myKey = null; - foreach (string key in _CacheByName.Keys) - if (_CacheByName[key].Contains(this)) - myKey = key; - if (myKey != null) - { - List listRole = _CacheByName[myKey]; // Get the list of items - listRole.Remove(this); // Remove the item from the list - if (listRole.Count == 0) //If there are no items left in the list - _CacheByName.Remove(myKey); // remove the list - } - } - public static Role New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.New", ex); - } - } - public static Role New(string name, string title) - { - Role tmp = Role.New(); - tmp.Name = name; - tmp.Title = title; - return tmp; - } - public static Role MakeRole(string name, string title) - { - Role tmp = Role.New(name, title); - if (tmp.IsSavable) - { - Role tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Role New(string name, string title, DateTime dts, string usrID) - { - Role tmp = Role.New(); - tmp.Name = name; - tmp.Title = title; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static Role MakeRole(string name, string title, DateTime dts, string usrID) - { - Role tmp = Role.New(name, title, dts, usrID); - if (tmp.IsSavable) - { - Role tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Role Get(int rid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Role"); - try - { - Role tmp = GetCachedByPrimaryKey(rid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Role - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.Get", ex); - } - } - public static Role GetByName(string name) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Role"); - try - { - Role tmp = GetCachedByName(name); - if (tmp == null) - { - tmp = DataPortal.Fetch(new NameCriteria(name)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Role - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.GetByName", ex); - } - } - public static Role Get(SafeDataReader dr) - { - if (dr.Read()) return new Role(dr); - return null; - } - internal Role(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int rid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); - try - { - DataPortal.Delete(new PKCriteria(rid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.Delete", ex); - } - } - public override Role Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Role"); - try - { - BuildRefreshList(); - Role role = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(role);//Refresh the item in AllList - ProcessRefreshList(); - return role; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _RID; - public int RID - { get { return _RID; } } - public PKCriteria(int rid) - { - _RID = rid; - } - } - [Serializable()] - private class NameCriteria - { - private string _Name; - public string Name - { get { return _Name; } } - public NameCriteria(string name) - { - _Name = name; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _RID = NextRID; - // Database Defaults - _DTS = _RoleExtension.DefaultDTS; - _UsrID = _RoleExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.ReadData", GetHashCode()); - try - { - _RID = dr.GetInt32("RID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); - _RolePermissionCount = dr.GetInt32("PermissionCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRole"; - cm.Parameters.AddWithValue("@RID", criteria.RID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _RoleAssignments = RoleAssignments.Get(dr); - // load child objects - dr.NextResult(); - _RolePermissions = RolePermissions.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Fetch", ex); - } - } - private void DataPortal_Fetch(NameCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRoleByName"; - cm.Parameters.AddWithValue("@Name", criteria.Name); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); - cm.Parameters.AddWithValue("@UsrID", _UsrID); - // Output Calculated Columns - SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); - param_RID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _RID = (int)cm.Parameters["@newRID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); - cm.Parameters.AddWithValue("@UsrID", usrID); - // Output Calculated Columns - SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); - param_RID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_RID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - rid = (int)cm.Parameters["@newRID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Add", ex); - throw new DbCslaException("Role.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Role.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRole"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@RID", _RID); - cm.Parameters.AddWithValue("@Name", _Name); - cm.Parameters.AddWithValue("@Title", _Title); - 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); - // TODO: 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 (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Role.Add(cn, ref _RID, _Name, _Title, _DTS, _UsrID); - else - _LastChanged = Role.Update(cn, ref _RID, _Name, _Title, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - if (_RoleAssignments != null) _RoleAssignments.Update(this); - if (_RolePermissions != null) _RolePermissions.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@RID", rid); - cm.Parameters.AddWithValue("@Name", name); - cm.Parameters.AddWithValue("@Title", title); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Update", ex); - throw new DbCslaException("Role.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_RID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRole"; - cm.Parameters.AddWithValue("@RID", criteria.RID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Role.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int rid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRole"; - // Input PK Fields - cm.Parameters.AddWithValue("@RID", rid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Remove", ex); - throw new DbCslaException("Role.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int rid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(rid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Role.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _RID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int rid) - { - _RID = rid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsRole"; - cm.Parameters.AddWithValue("@RID", _RID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Execute", ex); - throw new DbCslaException("Role.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - RoleExtension _RoleExtension = new RoleExtension(); - [Serializable()] - partial class RoleExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RoleConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Role) - { - // Return the ToString value - return ((Role)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Role Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleConverter))] + public partial class Role : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshRoles = new List(); + private List _RefreshRoleAssignments = new List(); + private List _RefreshRolePermissions = new List(); + private void AddToRefreshList(List refreshRoles, List refreshRoleAssignments, List refreshRolePermissions) + { + if (IsDirty) + refreshRoles.Add(this); + if (_RoleAssignments != null && _RoleAssignments.IsDirty) + { + foreach (RoleAssignment tmp in _RoleAssignments) + { + if (tmp.IsDirty) refreshRoleAssignments.Add(tmp); + } + } + if (_RolePermissions != null && _RolePermissions.IsDirty) + { + foreach (RolePermission tmp in _RolePermissions) + { + if (tmp.IsDirty) refreshRolePermissions.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshRoles = new List(); + _RefreshRoleAssignments = new List(); + _RefreshRolePermissions = new List(); + AddToRefreshList(_RefreshRoles, _RefreshRoleAssignments, _RefreshRolePermissions); + } + private void ProcessRefreshList() + { + foreach (Role tmp in _RefreshRoles) + { + RoleInfo.Refresh(tmp); + } + foreach (RoleAssignment tmp in _RefreshRoleAssignments) + { + AssignmentInfo.Refresh(tmp); + } + foreach (RolePermission tmp in _RefreshRolePermissions) + { + PermissionInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Role role) + { + if (!_CacheList.Contains(role)) _CacheList.Add(role); // In AddToCache + } + protected static void RemoveFromCache(Role role) + { + while (_CacheList.Contains(role)) _CacheList.Remove(role); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static Dictionary> _CacheByName = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Role tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString())) + { + _CacheByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey + _CacheByName[tmp.Name.ToString()] = new List(); // Add new list for Name + } + _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list + _CacheByName[tmp.Name.ToString()].Add(tmp); // Unique Index + remove.Add(tmp); + } + foreach (Role tmp in remove) + RemoveFromCache(tmp); + } + protected static Role GetCachedByPrimaryKey(int rid) + { + ConvertListToDictionary(); + string key = rid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + protected static Role GetCachedByName(string name) + { + ConvertListToDictionary(); + string key = name.ToString(); + if (_CacheByName.ContainsKey(key)) return _CacheByName[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextRID = -1; + public static int NextRID + { + get { return _nextRID--; } + } + private int _RID; + [System.ComponentModel.DataObjectField(true, true)] + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Name != value) + { + _Name = value; + PropertyHasChanged(); + } + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Title != value) + { + _Title = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _RoleAssignmentCount = 0; + /// + /// Count of RoleAssignments for this Role + /// + public int RoleAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RoleAssignmentCount; + } + } + private RoleAssignments _RoleAssignments = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RoleAssignmentsConverter))] + public RoleAssignments RoleAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RoleAssignmentCount > 0 && _RoleAssignments == null) + _RoleAssignments = RoleAssignments.GetByRID(RID); + else if (_RoleAssignments == null) + _RoleAssignments = RoleAssignments.New(); + return _RoleAssignments; + } + } + private int _RolePermissionCount = 0; + /// + /// Count of RolePermissions for this Role + /// + public int RolePermissionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RolePermissionCount; + } + } + private RolePermissions _RolePermissions = null; + /// + /// Related Field + /// + [TypeConverter(typeof(RolePermissionsConverter))] + public RolePermissions RolePermissions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RolePermissionCount > 0 && _RolePermissions == null) + _RolePermissions = RolePermissions.GetByRID(RID); + else if (_RolePermissions == null) + _RolePermissions = RolePermissions.New(); + return _RolePermissions; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_RoleAssignments == null ? false : _RoleAssignments.IsDirty) || (_RolePermissions == null ? false : _RolePermissions.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_RoleAssignments == null ? true : _RoleAssignments.IsValid) && (_RolePermissions == null ? true : _RolePermissions.IsValid); } + } + // TODO: Replace base Role.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Role + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Role.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Role + protected override object GetIdValue() + { + return _RID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_RoleAssignments != null && (hasBrokenRules = _RoleAssignments.HasBrokenRules) != null) return hasBrokenRules; + if (_RolePermissions != null && (hasBrokenRules = _RolePermissions.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Title"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _RoleExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _RoleExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(RID, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _RoleExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _RoleExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _RoleAssignmentCount; + usedByCount += _RolePermissionCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _RoleUnique = 0; + protected static int RoleUnique + { get { return ++_RoleUnique; } } + private int _MyRoleUnique = RoleUnique; + public int MyRoleUnique + { get { return _MyRoleUnique; } } + protected Role() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(RID.ToString())) + { + List listRole = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items + while (listRole.Contains(this)) listRole.Remove(this); // Remove the item from the list + if (listRole.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list + } + string myKey; + myKey = null; + foreach (string key in _CacheByName.Keys) + if (_CacheByName[key].Contains(this)) + myKey = key; + if (myKey != null) + { + List listRole = _CacheByName[myKey]; // Get the list of items + listRole.Remove(this); // Remove the item from the list + if (listRole.Count == 0) //If there are no items left in the list + _CacheByName.Remove(myKey); // remove the list + } + } + public static Role New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Role"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.New", ex); + } + } + public static Role New(string name, string title) + { + Role tmp = Role.New(); + tmp.Name = name; + tmp.Title = title; + return tmp; + } + public static Role MakeRole(string name, string title) + { + Role tmp = Role.New(name, title); + if (tmp.IsSavable) + { + Role tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Role New(string name, string title, DateTime dts, string usrID) + { + Role tmp = Role.New(); + tmp.Name = name; + tmp.Title = title; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static Role MakeRole(string name, string title, DateTime dts, string usrID) + { + Role tmp = Role.New(name, title, dts, usrID); + if (tmp.IsSavable) + { + Role tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Role Get(int rid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Role"); + try + { + Role tmp = GetCachedByPrimaryKey(rid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Role + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.Get", ex); + } + } + public static Role GetByName(string name) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Role"); + try + { + Role tmp = GetCachedByName(name); + if (tmp == null) + { + tmp = DataPortal.Fetch(new NameCriteria(name)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Role + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.GetByName", ex); + } + } + public static Role Get(SafeDataReader dr) + { + if (dr.Read()) return new Role(dr); + return null; + } + internal Role(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int rid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Role"); + try + { + DataPortal.Delete(new PKCriteria(rid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.Delete", ex); + } + } + public override Role Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Role"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Role"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Role"); + try + { + BuildRefreshList(); + Role role = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(role);//Refresh the item in AllList + ProcessRefreshList(); + return role; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _RID; + public int RID + { get { return _RID; } } + public PKCriteria(int rid) + { + _RID = rid; + } + } + [Serializable()] + private class NameCriteria + { + private string _Name; + public string Name + { get { return _Name; } } + public NameCriteria(string name) + { + _Name = name; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _RID = NextRID; + // Database Defaults + _DTS = _RoleExtension.DefaultDTS; + _UsrID = _RoleExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.ReadData", GetHashCode()); + try + { + _RID = dr.GetInt32("RID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); + _RolePermissionCount = dr.GetInt32("PermissionCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRole"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _RoleAssignments = RoleAssignments.Get(dr); + // load child objects + dr.NextResult(); + _RolePermissions = RolePermissions.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Fetch", ex); + } + } + private void DataPortal_Fetch(NameCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRoleByName"; + cm.Parameters.AddWithValue("@Name", criteria.Name); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); + cm.Parameters.AddWithValue("@UsrID", _UsrID); + // Output Calculated Columns + SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); + param_RID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _RID = (int)cm.Parameters["@newRID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_RoleAssignments != null) _RoleAssignments.Update(this); + if (_RolePermissions != null) _RolePermissions.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); + cm.Parameters.AddWithValue("@UsrID", usrID); + // Output Calculated Columns + SqlParameter param_RID = new SqlParameter("@newRID", SqlDbType.Int); + param_RID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_RID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + rid = (int)cm.Parameters["@newRID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Add", ex); + throw new DbCslaException("Role.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Role.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRole"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@RID", _RID); + cm.Parameters.AddWithValue("@Name", _Name); + cm.Parameters.AddWithValue("@Title", _Title); + 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); + // TODO: 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 (_RoleAssignments != null) _RoleAssignments.Update(this); + if (_RolePermissions != null) _RolePermissions.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Role.Add(cn, ref _RID, _Name, _Title, _DTS, _UsrID); + else + _LastChanged = Role.Update(cn, ref _RID, _Name, _Title, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + if (_RoleAssignments != null) _RoleAssignments.Update(this); + if (_RolePermissions != null) _RolePermissions.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@RID", rid); + cm.Parameters.AddWithValue("@Name", name); + cm.Parameters.AddWithValue("@Title", title); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Update", ex); + throw new DbCslaException("Role.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_RID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRole"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Role.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRole"; + // Input PK Fields + cm.Parameters.AddWithValue("@RID", rid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.Remove", ex); + throw new DbCslaException("Role.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int rid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(rid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Role.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _RID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int rid) + { + _RID = rid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Role.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsRole"; + cm.Parameters.AddWithValue("@RID", _RID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Role.DataPortal_Execute", ex); + throw new DbCslaException("Role.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + RoleExtension _RoleExtension = new RoleExtension(); + [Serializable()] + partial class RoleExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RoleConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Role) + { + // Return the ToString value + return ((Role)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleAssignment.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleAssignment.cs index a7fc0b23..8c9010c6 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleAssignment.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleAssignment.cs @@ -19,698 +19,667 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RoleAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoleAssignmentConverter))] - public partial class RoleAssignment : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _AID; - [System.ComponentModel.DataObjectField(true, true)] - public int AID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("AID", true); - if (_MyAssignment != null) _AID = _MyAssignment.AID; - return _AID; - } - } - private Assignment _MyAssignment; - [System.ComponentModel.DataObjectField(true, true)] - public Assignment MyAssignment - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyAssignment", true); - if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); - return _MyAssignment; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - PropertyHasChanged(); - } - } - } - private int _FolderID; - public int FolderID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FolderID", true); - if (_MyFolder != null) _FolderID = _MyFolder.FolderID; - return _FolderID; - } - } - private Folder _MyFolder; - public Folder MyFolder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyFolder", true); - if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); - return _MyFolder; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyFolder", true); - if (_MyFolder != value) - { - _MyFolder = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _Folder_ParentID; - public int Folder_ParentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ParentID", true); - return _Folder_ParentID; - } - } - private int _Folder_DBID; - public int Folder_DBID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DBID", true); - return _Folder_DBID; - } - } - private string _Folder_Name = string.Empty; - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Name", true); - return _Folder_Name; - } - } - private string _Folder_Title = string.Empty; - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Title", true); - return _Folder_Title; - } - } - private string _Folder_ShortName = string.Empty; - public string Folder_ShortName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ShortName", true); - return _Folder_ShortName; - } - } - private int? _Folder_FormatID; - public int? Folder_FormatID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_FormatID", true); - return _Folder_FormatID; - } - } - private double? _Folder_ManualOrder; - public double? Folder_ManualOrder - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_ManualOrder", true); - return _Folder_ManualOrder; - } - } - private string _Folder_Config = string.Empty; - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_Config", true); - return _Folder_Config; - } - } - private DateTime _Folder_DTS = new DateTime(); - public DateTime Folder_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_DTS", true); - return _Folder_DTS; - } - } - private string _Folder_UsrID = string.Empty; - public string Folder_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Folder_UsrID", true); - return _Folder_UsrID; - } - } - private string _Group_GroupName = string.Empty; - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupName", true); - return _Group_GroupName; - } - } - private int? _Group_GroupType; - public int? Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupType", true); - return _Group_GroupType; - } - } - private string _Group_Config = string.Empty; - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_Config", true); - return _Group_Config; - } - } - private DateTime _Group_DTS = new DateTime(); - public DateTime Group_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_DTS", true); - return _Group_DTS; - } - } - private string _Group_UsrID = string.Empty; - public string Group_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_UsrID", true); - return _Group_UsrID; - } - } - // TODO: Check RoleAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoleAssignment - protected override object GetIdValue() - { - return _AID; - } - // TODO: Replace base RoleAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoleAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyFolder == null ? false : _MyFolder.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule(MyFolderRequired, "MyFolder"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool StartDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyGroupRequired(RoleAssignment target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyFolderRequired(RoleAssignment target, Csla.Validation.RuleArgs e) - { - if (target._FolderID == 0 && target._MyFolder == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(AID, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowRead(FolderID, ""); - //AuthorizationRules.AllowWrite(FolderID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static RoleAssignment New(Group myGroup, Folder myFolder) - { - return new RoleAssignment(myGroup, myFolder); - } - internal static RoleAssignment Get(SafeDataReader dr) - { - return new RoleAssignment(dr); - } - public RoleAssignment() - { - MarkAsChild(); - _AID = Assignment.NextAID; - _StartDate = _RoleAssignmentExtension.DefaultStartDate; - _DTS = _RoleAssignmentExtension.DefaultDTS; - _UsrID = _RoleAssignmentExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private RoleAssignment(Group myGroup, Folder myFolder) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _StartDate = _RoleAssignmentExtension.DefaultStartDate; - _DTS = _RoleAssignmentExtension.DefaultDTS; - _UsrID = _RoleAssignmentExtension.DefaultUsrID; - _MyGroup = myGroup; - _MyFolder = myFolder; - ValidationRules.CheckRules(); - } - internal RoleAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleAssignment.FetchDR", GetHashCode()); - try - { - _AID = dr.GetInt32("AID"); - _GID = dr.GetInt32("GID"); - _FolderID = dr.GetInt32("FolderID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Folder_ParentID = dr.GetInt32("Folder_ParentID"); - _Folder_DBID = dr.GetInt32("Folder_DBID"); - _Folder_Name = dr.GetString("Folder_Name"); - _Folder_Title = dr.GetString("Folder_Title"); - _Folder_ShortName = dr.GetString("Folder_ShortName"); - _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); - _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); - _Folder_Config = dr.GetString("Folder_Config"); - _Folder_DTS = dr.GetDateTime("Folder_DTS"); - _Folder_UsrID = dr.GetString("Folder_UsrID"); - _Group_GroupName = dr.GetString("Group_GroupName"); - _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); - _Group_Config = dr.GetString("Group_Config"); - _Group_DTS = dr.GetDateTime("Group_DTS"); - _Group_UsrID = dr.GetString("Group_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleAssignment.FetchDR", ex); - throw new DbCslaException("RoleAssignment.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Role myRole) - { - // 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); - MarkOld(); - } - internal void Update(Role myRole) - { - // 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, myRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Role myRole) - { - // 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); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RoleAssignmentExtension _RoleAssignmentExtension = new RoleAssignmentExtension(); - [Serializable()] - partial class RoleAssignmentExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RoleAssignmentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoleAssignment) - { - // Return the ToString value - return ((RoleAssignment)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RoleAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleAssignmentConverter))] + public partial class RoleAssignment : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _AID; + [System.ComponentModel.DataObjectField(true, true)] + public int AID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment != null) _AID = _MyAssignment.AID; + return _AID; + } + } + private Assignment _MyAssignment; + [System.ComponentModel.DataObjectField(true, true)] + public Assignment MyAssignment + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyAssignment == null && _AID != 0) _MyAssignment = Assignment.Get(_AID); + return _MyAssignment; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + PropertyHasChanged(); + } + } + } + private int _FolderID; + public int FolderID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder != null) _FolderID = _MyFolder.FolderID; + return _FolderID; + } + } + private Folder _MyFolder; + public Folder MyFolder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyFolder == null && _FolderID != 0) _MyFolder = Folder.Get(_FolderID); + return _MyFolder; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyFolder != value) + { + _MyFolder = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _Folder_ParentID; + public int Folder_ParentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ParentID; + } + } + private int _Folder_DBID; + public int Folder_DBID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DBID; + } + } + private string _Folder_Name = string.Empty; + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Name; + } + } + private string _Folder_Title = string.Empty; + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Title; + } + } + private string _Folder_ShortName = string.Empty; + public string Folder_ShortName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ShortName; + } + } + private int? _Folder_FormatID; + public int? Folder_FormatID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_FormatID; + } + } + private double? _Folder_ManualOrder; + public double? Folder_ManualOrder + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_ManualOrder; + } + } + private string _Folder_Config = string.Empty; + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_Config; + } + } + private DateTime _Folder_DTS = new DateTime(); + public DateTime Folder_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_DTS; + } + } + private string _Folder_UsrID = string.Empty; + public string Folder_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Folder_UsrID; + } + } + private string _Group_GroupName = string.Empty; + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupName; + } + } + private int? _Group_GroupType; + public int? Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupType; + } + } + private string _Group_Config = string.Empty; + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_Config; + } + } + private DateTime _Group_DTS = new DateTime(); + public DateTime Group_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_DTS; + } + } + private string _Group_UsrID = string.Empty; + public string Group_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_UsrID; + } + } + // TODO: Check RoleAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoleAssignment + protected override object GetIdValue() + { + return _AID; + } + // TODO: Replace base RoleAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoleAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty) || (_MyFolder == null ? false : _MyFolder.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid) && (_MyFolder == null ? true : _MyFolder.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + if (_MyFolder != null && (hasBrokenRules = _MyFolder.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule(MyFolderRequired, "MyFolder"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool StartDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(RoleAssignment target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyGroupRequired(RoleAssignment target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyFolderRequired(RoleAssignment target, Csla.Validation.RuleArgs e) + { + if (target._FolderID == 0 && target._MyFolder == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(AID, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowRead(FolderID, ""); + //AuthorizationRules.AllowWrite(FolderID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static RoleAssignment New(Group myGroup, Folder myFolder) + { + return new RoleAssignment(myGroup, myFolder); + } + internal static RoleAssignment Get(SafeDataReader dr) + { + return new RoleAssignment(dr); + } + public RoleAssignment() + { + MarkAsChild(); + _AID = Assignment.NextAID; + _StartDate = _RoleAssignmentExtension.DefaultStartDate; + _DTS = _RoleAssignmentExtension.DefaultDTS; + _UsrID = _RoleAssignmentExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private RoleAssignment(Group myGroup, Folder myFolder) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _StartDate = _RoleAssignmentExtension.DefaultStartDate; + _DTS = _RoleAssignmentExtension.DefaultDTS; + _UsrID = _RoleAssignmentExtension.DefaultUsrID; + _MyGroup = myGroup; + _MyFolder = myFolder; + ValidationRules.CheckRules(); + } + internal RoleAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleAssignment.FetchDR", GetHashCode()); + try + { + _AID = dr.GetInt32("AID"); + _GID = dr.GetInt32("GID"); + _FolderID = dr.GetInt32("FolderID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Folder_ParentID = dr.GetInt32("Folder_ParentID"); + _Folder_DBID = dr.GetInt32("Folder_DBID"); + _Folder_Name = dr.GetString("Folder_Name"); + _Folder_Title = dr.GetString("Folder_Title"); + _Folder_ShortName = dr.GetString("Folder_ShortName"); + _Folder_FormatID = (int?)dr.GetValue("Folder_FormatID"); + _Folder_ManualOrder = (double?)dr.GetValue("Folder_ManualOrder"); + _Folder_Config = dr.GetString("Folder_Config"); + _Folder_DTS = dr.GetDateTime("Folder_DTS"); + _Folder_UsrID = dr.GetString("Folder_UsrID"); + _Group_GroupName = dr.GetString("Group_GroupName"); + _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); + _Group_Config = dr.GetString("Group_Config"); + _Group_DTS = dr.GetDateTime("Group_DTS"); + _Group_UsrID = dr.GetString("Group_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleAssignment.FetchDR", ex); + throw new DbCslaException("RoleAssignment.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Role myRole) + { + // 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); + MarkOld(); + } + internal void Update(Role myRole) + { + // 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, myRole, _MyFolder, new SmartDate(_StartDate), new SmartDate(_EndDate), _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Role myRole) + { + // 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); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RoleAssignmentExtension _RoleAssignmentExtension = new RoleAssignmentExtension(); + [Serializable()] + partial class RoleAssignmentExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RoleAssignmentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoleAssignment) + { + // Return the ToString value + return ((RoleAssignment)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleInfo.cs index 95524c04..546d8cd1 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RoleInfo.cs @@ -19,389 +19,380 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void RoleInfoEvent(object sender); - /// - /// RoleInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RoleInfoConverter))] - public partial class RoleInfo : ReadOnlyBase, IDisposable - { - public event RoleInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(RoleInfo roleInfo) - { - if (!_CacheList.Contains(roleInfo)) _CacheList.Add(roleInfo); // In AddToCache - } - protected static void RemoveFromCache(RoleInfo roleInfo) - { - while (_CacheList.Contains(roleInfo)) _CacheList.Remove(roleInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (RoleInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString())) - { - _CacheByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (RoleInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(RoleInfoList lst) - { - foreach (RoleInfo item in lst) AddToCache(item); - } - protected static RoleInfo GetCachedByPrimaryKey(int rid) - { - ConvertListToDictionary(); - string key = rid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Role _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _RID; - [System.ComponentModel.DataObjectField(true, true)] - public int RID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RID", true); - return _RID; - } - } - private string _Name = string.Empty; - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Name", true); - return _Name; - } - } - private string _Title = string.Empty; - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Title", true); - return _Title; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _RoleAssignmentCount = 0; - /// - /// Count of RoleAssignments for this Role - /// - public int RoleAssignmentCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignmentCount", true); - return _RoleAssignmentCount; - } - } - private AssignmentInfoList _RoleAssignments = null; - [TypeConverter(typeof(AssignmentInfoListConverter))] - public AssignmentInfoList RoleAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RoleAssignments", true); - if (_RoleAssignmentCount < 0 || (_RoleAssignmentCount > 0 && _RoleAssignments == null)) - _RoleAssignments = AssignmentInfoList.GetByRID(_RID); - if (_RoleAssignmentCount < 0) - _RoleAssignmentCount = _RoleAssignments.Count; - return _RoleAssignments; - } - } - public void RefreshRoleAssignments() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) - foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) - tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried - } - private int _RolePermissionCount = 0; - /// - /// Count of RolePermissions for this Role - /// - public int RolePermissionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissionCount", true); - return _RolePermissionCount; - } - } - private PermissionInfoList _RolePermissions = null; - [TypeConverter(typeof(PermissionInfoListConverter))] - public PermissionInfoList RolePermissions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RolePermissions", true); - if (_RolePermissionCount < 0 || (_RolePermissionCount > 0 && _RolePermissions == null)) - _RolePermissions = PermissionInfoList.GetByRID(_RID); - if (_RolePermissionCount < 0) - _RolePermissionCount = _RolePermissions.Count; - return _RolePermissions; - } - } - public void RefreshRolePermissions() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) - foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) - tmp._RolePermissionCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base RoleInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoleInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check RoleInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoleInfo - protected override object GetIdValue() - { - return _RID; - } - #endregion - #region Factory Methods - private static int _RoleInfoUnique = 0; - private static int RoleInfoUnique - { get { return ++_RoleInfoUnique; } } - private int _MyRoleInfoUnique = RoleInfoUnique; - public int MyRoleInfoUnique - { get { return _MyRoleInfoUnique; } } - protected RoleInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(RID.ToString())) return; - List listRoleInfo = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items - while (listRoleInfo.Contains(this)) listRoleInfo.Remove(this); // Remove the item from the list - if (listRoleInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list - } - public virtual Role Get() - { - return _Editable = Role.Get(_RID); - } - public static void Refresh(Role tmp) - { - string key = tmp.RID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (RoleInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Role tmp) - { - _Name = tmp.Name; - _Title = tmp.Title; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _RoleInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static RoleInfo Get(int rid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Role"); - try - { - RoleInfo tmp = GetCachedByPrimaryKey(rid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(rid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up RoleInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on RoleInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal RoleInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.Constructor", ex); - throw new DbCslaException("RoleInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _RID; - public int RID - { get { return _RID; } } - public PKCriteria(int rid) - { - _RID = rid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.ReadData", GetHashCode()); - try - { - _RID = dr.GetInt32("RID"); - _Name = dr.GetString("Name"); - _Title = dr.GetString("Title"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); - _RolePermissionCount = dr.GetInt32("PermissionCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoleInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRole"; - cm.Parameters.AddWithValue("@RID", criteria.RID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("RoleInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - RoleInfoExtension _RoleInfoExtension = new RoleInfoExtension(); - [Serializable()] - partial class RoleInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(RoleInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class RoleInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RoleInfo) - { - // Return the ToString value - return ((RoleInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void RoleInfoEvent(object sender); + /// + /// RoleInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RoleInfoConverter))] + public partial class RoleInfo : ReadOnlyBase, IDisposable + { + public event RoleInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(RoleInfo roleInfo) + { + if (!_CacheList.Contains(roleInfo)) _CacheList.Add(roleInfo); // In AddToCache + } + protected static void RemoveFromCache(RoleInfo roleInfo) + { + while (_CacheList.Contains(roleInfo)) _CacheList.Remove(roleInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (RoleInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.RID.ToString())) + { + _CacheByPrimaryKey[tmp.RID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.RID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (RoleInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(RoleInfoList lst) + { + foreach (RoleInfo item in lst) AddToCache(item); + } + protected static RoleInfo GetCachedByPrimaryKey(int rid) + { + ConvertListToDictionary(); + string key = rid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Role _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _RID; + [System.ComponentModel.DataObjectField(true, true)] + public int RID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RID; + } + } + private string _Name = string.Empty; + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Name; + } + } + private string _Title = string.Empty; + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Title; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _RoleAssignmentCount = 0; + /// + /// Count of RoleAssignments for this Role + /// + public int RoleAssignmentCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RoleAssignmentCount; + } + } + private AssignmentInfoList _RoleAssignments = null; + [TypeConverter(typeof(AssignmentInfoListConverter))] + public AssignmentInfoList RoleAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RoleAssignmentCount < 0 || (_RoleAssignmentCount > 0 && _RoleAssignments == null)) + _RoleAssignments = AssignmentInfoList.GetByRID(_RID); + if (_RoleAssignmentCount < 0) + _RoleAssignmentCount = _RoleAssignments.Count; + return _RoleAssignments; + } + } + public void RefreshRoleAssignments() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) + foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) + tmp._RoleAssignmentCount = -1; // This will cause the data to be requeried + } + private int _RolePermissionCount = 0; + /// + /// Count of RolePermissions for this Role + /// + public int RolePermissionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _RolePermissionCount; + } + } + private PermissionInfoList _RolePermissions = null; + [TypeConverter(typeof(PermissionInfoListConverter))] + public PermissionInfoList RolePermissions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_RolePermissionCount < 0 || (_RolePermissionCount > 0 && _RolePermissions == null)) + _RolePermissions = PermissionInfoList.GetByRID(_RID); + if (_RolePermissionCount < 0) + _RolePermissionCount = _RolePermissions.Count; + return _RolePermissions; + } + } + public void RefreshRolePermissions() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_RID.ToString())) + foreach (RoleInfo tmp in _CacheByPrimaryKey[_RID.ToString()]) + tmp._RolePermissionCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base RoleInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoleInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check RoleInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoleInfo + protected override object GetIdValue() + { + return _RID; + } + #endregion + #region Factory Methods + private static int _RoleInfoUnique = 0; + private static int RoleInfoUnique + { get { return ++_RoleInfoUnique; } } + private int _MyRoleInfoUnique = RoleInfoUnique; + public int MyRoleInfoUnique + { get { return _MyRoleInfoUnique; } } + protected RoleInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(RID.ToString())) return; + List listRoleInfo = _CacheByPrimaryKey[RID.ToString()]; // Get the list of items + while (listRoleInfo.Contains(this)) listRoleInfo.Remove(this); // Remove the item from the list + if (listRoleInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(RID.ToString()); // remove the list + } + public virtual Role Get() + { + return _Editable = Role.Get(_RID); + } + public static void Refresh(Role tmp) + { + string key = tmp.RID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (RoleInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Role tmp) + { + _Name = tmp.Name; + _Title = tmp.Title; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _RoleInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static RoleInfo Get(int rid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Role"); + try + { + RoleInfo tmp = GetCachedByPrimaryKey(rid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(rid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up RoleInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoleInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal RoleInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.Constructor", ex); + throw new DbCslaException("RoleInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _RID; + public int RID + { get { return _RID; } } + public PKCriteria(int rid) + { + _RID = rid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.ReadData", GetHashCode()); + try + { + _RID = dr.GetInt32("RID"); + _Name = dr.GetString("Name"); + _Title = dr.GetString("Title"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _RoleAssignmentCount = dr.GetInt32("AssignmentCount"); + _RolePermissionCount = dr.GetInt32("PermissionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoleInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RoleInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRole"; + cm.Parameters.AddWithValue("@RID", criteria.RID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RoleInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("RoleInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + RoleInfoExtension _RoleInfoExtension = new RoleInfoExtension(); + [Serializable()] + partial class RoleInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(RoleInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class RoleInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RoleInfo) + { + // Return the ToString value + return ((RoleInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RolePermission.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RolePermission.cs index 379d7285..23f47a52 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/RolePermission.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/RolePermission.cs @@ -19,571 +19,551 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// RolePermission Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(RolePermissionConverter))] - public partial class RolePermission : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _PID; - [System.ComponentModel.DataObjectField(true, true)] - public int PID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PID", true); - if (_MyPermission != null) _PID = _MyPermission.PID; - return _PID; - } - } - private Permission _MyPermission; - [System.ComponentModel.DataObjectField(true, true)] - public Permission MyPermission - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyPermission", true); - if (_MyPermission == null && _PID != 0) _MyPermission = Permission.Get(_PID); - return _MyPermission; - } - } - private int _PermLevel; - /// - /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments - /// - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermLevel", true); - return _PermLevel; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermLevel", true); - if (_PermLevel != value) - { - _PermLevel = value; - PropertyHasChanged(); - } - } - } - private int _VersionType; - /// - /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) - /// - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("VersionType", true); - return _VersionType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("VersionType", true); - if (_VersionType != value) - { - _VersionType = value; - PropertyHasChanged(); - } - } - } - private int _PermValue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermValue", true); - return _PermValue; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermValue", true); - if (_PermValue != value) - { - _PermValue = value; - PropertyHasChanged(); - } - } - } - private int _PermAD; - /// - /// 0 - Allow, 1 - Deny - /// - public int PermAD - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PermAD", true); - return _PermAD; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PermAD", true); - if (_PermAD != value) - { - _PermAD = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - // TODO: Check RolePermission.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RolePermission - protected override object GetIdValue() - { - return _PID; - } - // TODO: Replace base RolePermission.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RolePermission - //public override string ToString() - //{ - // return base.ToString(); - //} - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool StartDateValid(RolePermission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(RolePermission target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(PID, ""); - //AuthorizationRules.AllowRead(PermLevel, ""); - //AuthorizationRules.AllowWrite(PermLevel, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(PermValue, ""); - //AuthorizationRules.AllowWrite(PermValue, ""); - //AuthorizationRules.AllowRead(PermAD, ""); - //AuthorizationRules.AllowWrite(PermAD, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static RolePermission New(int permLevel, int versionType, int permValue) - { - return new RolePermission(permLevel, versionType, permValue); - } - internal static RolePermission Get(SafeDataReader dr) - { - return new RolePermission(dr); - } - public RolePermission() - { - MarkAsChild(); - _PID = Permission.NextPID; - _PermAD = _RolePermissionExtension.DefaultPermAD; - _StartDate = _RolePermissionExtension.DefaultStartDate; - _DTS = _RolePermissionExtension.DefaultDTS; - _UsrID = _RolePermissionExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private RolePermission(int permLevel, int versionType, int permValue) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _PermAD = _RolePermissionExtension.DefaultPermAD; - _StartDate = _RolePermissionExtension.DefaultStartDate; - _DTS = _RolePermissionExtension.DefaultDTS; - _UsrID = _RolePermissionExtension.DefaultUsrID; - _PermLevel = permLevel; - _VersionType = versionType; - _PermValue = permValue; - ValidationRules.CheckRules(); - } - internal RolePermission(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RolePermission.FetchDR", GetHashCode()); - try - { - _PID = dr.GetInt32("PID"); - _PermLevel = dr.GetInt32("PermLevel"); - _VersionType = dr.GetInt32("VersionType"); - _PermValue = dr.GetInt32("PermValue"); - _PermAD = dr.GetInt32("PermAD"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("RolePermission.FetchDR", ex); - throw new DbCslaException("RolePermission.Fetch", ex); - } - MarkOld(); - } - internal void Insert(Role myRole) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Permission.Add(cn, ref _PID, myRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); - MarkOld(); - } - internal void Update(Role myRole) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - _LastChanged = Permission.Update(cn, ref _PID, myRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(Role myRole) - { - // 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"]; - Permission.Remove(cn, _PID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - RolePermissionExtension _RolePermissionExtension = new RolePermissionExtension(); - [Serializable()] - partial class RolePermissionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultPermAD - { - get { return 0; } - } - public virtual string DefaultStartDate - { - get { return DateTime.Now.ToShortDateString(); } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class RolePermissionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is RolePermission) - { - // Return the ToString value - return ((RolePermission)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// RolePermission Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(RolePermissionConverter))] + public partial class RolePermission : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _PID; + [System.ComponentModel.DataObjectField(true, true)] + public int PID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPermission != null) _PID = _MyPermission.PID; + return _PID; + } + } + private Permission _MyPermission; + [System.ComponentModel.DataObjectField(true, true)] + public Permission MyPermission + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyPermission == null && _PID != 0) _MyPermission = Permission.Get(_PID); + return _MyPermission; + } + } + private int _PermLevel; + /// + /// 0 - None, 1 - Security, 2 - System, 3 - RO, 4 - Procdures, 5 - Sections, 6 - Steps, 7 - Comments + /// + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermLevel; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermLevel != value) + { + _PermLevel = value; + PropertyHasChanged(); + } + } + } + private int _VersionType; + /// + /// 0 - None, 1 - Working Draft, 2 - Approved, (3 - All) + /// + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _VersionType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_VersionType != value) + { + _VersionType = value; + PropertyHasChanged(); + } + } + } + private int _PermValue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermValue; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermValue != value) + { + _PermValue = value; + PropertyHasChanged(); + } + } + } + private int _PermAD; + /// + /// 0 - Allow, 1 - Deny + /// + public int PermAD + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PermAD; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_PermAD != value) + { + _PermAD = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + // TODO: Check RolePermission.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RolePermission + protected override object GetIdValue() + { + return _PID; + } + // TODO: Replace base RolePermission.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RolePermission + //public override string ToString() + //{ + // return base.ToString(); + //} + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool StartDateValid(RolePermission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(RolePermission target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(PID, ""); + //AuthorizationRules.AllowRead(PermLevel, ""); + //AuthorizationRules.AllowWrite(PermLevel, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(PermValue, ""); + //AuthorizationRules.AllowWrite(PermValue, ""); + //AuthorizationRules.AllowRead(PermAD, ""); + //AuthorizationRules.AllowWrite(PermAD, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static RolePermission New(int permLevel, int versionType, int permValue) + { + return new RolePermission(permLevel, versionType, permValue); + } + internal static RolePermission Get(SafeDataReader dr) + { + return new RolePermission(dr); + } + public RolePermission() + { + MarkAsChild(); + _PID = Permission.NextPID; + _PermAD = _RolePermissionExtension.DefaultPermAD; + _StartDate = _RolePermissionExtension.DefaultStartDate; + _DTS = _RolePermissionExtension.DefaultDTS; + _UsrID = _RolePermissionExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private RolePermission(int permLevel, int versionType, int permValue) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _PermAD = _RolePermissionExtension.DefaultPermAD; + _StartDate = _RolePermissionExtension.DefaultStartDate; + _DTS = _RolePermissionExtension.DefaultDTS; + _UsrID = _RolePermissionExtension.DefaultUsrID; + _PermLevel = permLevel; + _VersionType = versionType; + _PermValue = permValue; + ValidationRules.CheckRules(); + } + internal RolePermission(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] RolePermission.FetchDR", GetHashCode()); + try + { + _PID = dr.GetInt32("PID"); + _PermLevel = dr.GetInt32("PermLevel"); + _VersionType = dr.GetInt32("VersionType"); + _PermValue = dr.GetInt32("PermValue"); + _PermAD = dr.GetInt32("PermAD"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("RolePermission.FetchDR", ex); + throw new DbCslaException("RolePermission.Fetch", ex); + } + MarkOld(); + } + internal void Insert(Role myRole) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Permission.Add(cn, ref _PID, myRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID); + MarkOld(); + } + internal void Update(Role myRole) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + _LastChanged = Permission.Update(cn, ref _PID, myRole, _PermLevel, _VersionType, _PermValue, _PermAD, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(Role myRole) + { + // 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"]; + Permission.Remove(cn, _PID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + RolePermissionExtension _RolePermissionExtension = new RolePermissionExtension(); + [Serializable()] + partial class RolePermissionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultPermAD + { + get { return 0; } + } + public virtual string DefaultStartDate + { + get { return DateTime.Now.ToShortDateString(); } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class RolePermissionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is RolePermission) + { + // Return the ToString value + return ((RolePermission)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Transition.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Transition.cs index 4a92be9d..4e5e7798 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/Transition.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/Transition.cs @@ -20,1154 +20,1134 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// Transition Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(TransitionConverter))] - public partial class Transition : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshTransitions = new List(); - private void AddToRefreshList(List refreshTransitions) - { - if (IsDirty) - refreshTransitions.Add(this); - } - private void BuildRefreshList() - { - _RefreshTransitions = new List(); - AddToRefreshList(_RefreshTransitions); - } - private void ProcessRefreshList() - { - foreach (Transition tmp in _RefreshTransitions) - { - TransitionInfo.Refresh(tmp); - if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); - if (tmp._MyItemRangeID != null) ItemInfo.Refresh(tmp._MyItemRangeID); - if (tmp._MyItemToID != null) ItemInfo.Refresh(tmp._MyItemToID); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(Transition transition) - { - if (!_CacheList.Contains(transition)) _CacheList.Add(transition); // In AddToCache - } - protected static void RemoveFromCache(Transition transition) - { - while (_CacheList.Contains(transition)) _CacheList.Remove(transition); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (Transition tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) - { - _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (Transition tmp in remove) - RemoveFromCache(tmp); - } - protected static Transition GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextTransitionID = -1; - public static int NextTransitionID - { - get { return _nextTransitionID--; } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - return _TransitionID; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private Content _MyContent; - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); - return _MyContent; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyContent", true); - if (_MyContent != value) - { - _MyContent = value; - PropertyHasChanged(); - } - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private Item _MyItemToID; - public Item MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); - return _MyItemToID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemToID", true); - if (_MyItemToID != value) - { - _MyItemToID = value; - PropertyHasChanged(); - } - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private Item _MyItemRangeID; - public Item MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); - return _MyItemRangeID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyItemRangeID", true); - if (_MyItemRangeID != value) - { - _MyItemRangeID = value; - PropertyHasChanged(); - } - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("TranType", true); - if (_TranType != value) - { - _TranType = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _TransitionZTransitionCount = 0; - /// - /// Count of TransitionZTransitions for this Transition - /// - public int TransitionZTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionZTransitionCount", true); - return _TransitionZTransitionCount; - } - } - private ZTransition _MyZTransition = null; - /// - /// Related Field - /// - [TypeConverter(typeof(ZTransitionConverter))] - public ZTransition MyZTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZTransition", true); - if (_MyZTransition == null) _MyZTransition = ZTransition.New(this); - return _MyZTransition; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_MyZTransition == null ? false : _MyZTransition.IsDirty) || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirty) || (_MyItemToID == null ? false : _MyItemToID.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyZTransition == null ? true : _MyZTransition.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValid) && (_MyItemToID == null ? true : _MyItemToID.IsValid); } - } - // TODO: Replace base Transition.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Transition - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check Transition.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Transition - protected override object GetIdValue() - { - return _TransitionID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyZTransition != null && (hasBrokenRules = _MyZTransition.HasBrokenRules) != null) return hasBrokenRules; - if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; - if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyContentRequired, "MyContent"); - ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); - ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _TransitionExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _TransitionExtension.AddInstanceValidationRules(ValidationRules); - // TODO: Add other validation rules - } - private static bool MyContentRequired(Transition target, Csla.Validation.RuleArgs e) - { - if (target._FromID == 0 && target._MyContent == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyItemToIDRequired(Transition target, Csla.Validation.RuleArgs e) - { - if (target._ToID == 0 && target._MyItemToID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - return true; - } - private static bool MyItemRangeIDRequired(Transition target, Csla.Validation.RuleArgs e) - { - if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(TransitionID, ""); - //AuthorizationRules.AllowRead(FromID, ""); - //AuthorizationRules.AllowRead(ToID, ""); - //AuthorizationRules.AllowRead(RangeID, ""); - //AuthorizationRules.AllowRead(TranType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowWrite(FromID, ""); - //AuthorizationRules.AllowWrite(ToID, ""); - //AuthorizationRules.AllowWrite(RangeID, ""); - //AuthorizationRules.AllowWrite(TranType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - _TransitionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _TransitionExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _TransitionZTransitionCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _TransitionUnique = 0; - protected static int TransitionUnique - { get { return ++_TransitionUnique; } } - private int _MyTransitionUnique = TransitionUnique; - public int MyTransitionUnique - { get { return _MyTransitionUnique; } } - protected Transition() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) - { - List listTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listTransition.Contains(this)) listTransition.Remove(this); // Remove the item from the list - if (listTransition.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - } - public static Transition New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Transition"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.New", ex); - } - } - public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID) - { - Transition tmp = Transition.New(); - tmp.MyContent = myContent; - tmp.MyItemToID = myItemToID; - tmp.MyItemRangeID = myItemRangeID; - return tmp; - } - public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID) - { - Transition tmp = Transition.New(); - tmp.MyContent = myContent; - tmp.MyItemToID = myItemToID; - tmp.MyItemRangeID = myItemRangeID; - tmp.TranType = tranType; - tmp.Config = config; - tmp.DTS = dts; - tmp.UserID = userID; - return tmp; - } - public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID) - { - Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, tranType, config, dts, userID); - if (tmp.IsSavable) - { - Transition tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, string config) - { - Transition tmp = Transition.New(); - tmp.MyContent = myContent; - tmp.MyItemToID = myItemToID; - tmp.MyItemRangeID = myItemRangeID; - tmp.Config = config; - return tmp; - } - public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, string config) - { - Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, config); - if (tmp.IsSavable) - { - Transition tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static Transition Get(int transitionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Transition"); - try - { - Transition tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up Transition - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.Get", ex); - } - } - public static Transition Get(SafeDataReader dr) - { - if (dr.Read()) return new Transition(dr); - return null; - } - internal Transition(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int transitionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Transition"); - try - { - DataPortal.Delete(new PKCriteria(transitionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.Delete", ex); - } - } - public override Transition Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Transition"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Transition"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Transition"); - try - { - BuildRefreshList(); - Transition transition = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(transition);//Refresh the item in AllList - ProcessRefreshList(); - return transition; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _TransitionID = NextTransitionID; - // Database Defaults - _TranType = _TransitionExtension.DefaultTranType; - _DTS = _TransitionExtension.DefaultDTS; - _UserID = _TransitionExtension.DefaultUserID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _ToID = dr.GetInt32("ToID"); - _RangeID = dr.GetInt32("RangeID"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _MyZTransition = ZTransition.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItemRangeID != null) _MyItemRangeID.Update(); - if (_MyItemToID != null) _MyItemToID.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FromID", FromID); - cm.Parameters.AddWithValue("@ToID", ToID); - cm.Parameters.AddWithValue("@RangeID", RangeID); - cm.Parameters.AddWithValue("@TranType", _TranType); - 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); - param_TransitionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_TransitionID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _TransitionID = (int)cm.Parameters["@newTransitionID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_MyZTransition != null) _MyZTransition.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int transitionID, Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@FromID", myContent.ContentID); - cm.Parameters.AddWithValue("@ToID", myItemToID.ItemID); - cm.Parameters.AddWithValue("@RangeID", myItemRangeID.ItemID); - cm.Parameters.AddWithValue("@TranType", tranType); - 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); - param_TransitionID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_TransitionID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - transitionID = (int)cm.Parameters["@newTransitionID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Add", ex); - throw new DbCslaException("Transition.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] Transition.SQLUpdate", GetHashCode()); - try - { - if (_MyContent != null) _MyContent.Update(); - if (_MyItemRangeID != null) _MyItemRangeID.Update(); - if (_MyItemToID != null) _MyItemToID.Update(); - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateTransition"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@TransitionID", _TransitionID); - cm.Parameters.AddWithValue("@FromID", FromID); - cm.Parameters.AddWithValue("@ToID", ToID); - cm.Parameters.AddWithValue("@RangeID", RangeID); - cm.Parameters.AddWithValue("@TranType", _TranType); - 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); - // TODO: 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 (_MyZTransition != null) _MyZTransition.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID); - else - _LastChanged = Transition.Update(cn, ref _TransitionID, _MyContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); - MarkOld(); - } - if (_MyZTransition != null) _MyZTransition.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int transitionID, Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", transitionID); - cm.Parameters.AddWithValue("@FromID", myContent.ContentID); - cm.Parameters.AddWithValue("@ToID", myItemToID.ItemID); - cm.Parameters.AddWithValue("@RangeID", myItemRangeID.ItemID); - cm.Parameters.AddWithValue("@TranType", tranType); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Update", ex); - throw new DbCslaException("Transition.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_TransitionID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("Transition.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int transitionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteTransition"; - // Input PK Fields - cm.Parameters.AddWithValue("@TransitionID", transitionID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Remove", ex); - throw new DbCslaException("Transition.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int transitionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(transitionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on Transition.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _TransitionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int transitionID) - { - _TransitionID = transitionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsTransition"; - cm.Parameters.AddWithValue("@TransitionID", _TransitionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Execute", ex); - throw new DbCslaException("Transition.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - TransitionExtension _TransitionExtension = new TransitionExtension(); - [Serializable()] - partial class TransitionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultTranType - { - get { return 0; } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class TransitionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is Transition) - { - // Return the ToString value - return ((Transition)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// Transition Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(TransitionConverter))] + public partial class Transition : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshTransitions = new List(); + private void AddToRefreshList(List refreshTransitions) + { + if (IsDirty) + refreshTransitions.Add(this); + } + private void BuildRefreshList() + { + _RefreshTransitions = new List(); + AddToRefreshList(_RefreshTransitions); + } + private void ProcessRefreshList() + { + foreach (Transition tmp in _RefreshTransitions) + { + TransitionInfo.Refresh(tmp); + if (tmp._MyContent != null) ContentInfo.Refresh(tmp._MyContent); + if (tmp._MyItemRangeID != null) ItemInfo.Refresh(tmp._MyItemRangeID); + if (tmp._MyItemToID != null) ItemInfo.Refresh(tmp._MyItemToID); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(Transition transition) + { + if (!_CacheList.Contains(transition)) _CacheList.Add(transition); // In AddToCache + } + protected static void RemoveFromCache(Transition transition) + { + while (_CacheList.Contains(transition)) _CacheList.Remove(transition); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (Transition tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) + { + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (Transition tmp in remove) + RemoveFromCache(tmp); + } + protected static Transition GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextTransitionID = -1; + public static int NextTransitionID + { + get { return _nextTransitionID--; } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionID; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private Content _MyContent; + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = Content.Get(_FromID); + return _MyContent; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyContent != value) + { + _MyContent = value; + PropertyHasChanged(); + } + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private Item _MyItemToID; + public Item MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = Item.Get(_ToID); + return _MyItemToID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemToID != value) + { + _MyItemToID = value; + PropertyHasChanged(); + } + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private Item _MyItemRangeID; + public Item MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = Item.Get(_RangeID); + return _MyItemRangeID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyItemRangeID != value) + { + _MyItemRangeID = value; + PropertyHasChanged(); + } + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_TranType != value) + { + _TranType = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _TransitionZTransitionCount = 0; + /// + /// Count of TransitionZTransitions for this Transition + /// + public int TransitionZTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionZTransitionCount; + } + } + private ZTransition _MyZTransition = null; + /// + /// Related Field + /// + [TypeConverter(typeof(ZTransitionConverter))] + public ZTransition MyZTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyZTransition == null) _MyZTransition = ZTransition.New(this); + return _MyZTransition; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_MyZTransition == null ? false : _MyZTransition.IsDirty) || (_MyContent == null ? false : _MyContent.IsDirty) || (_MyItemRangeID == null ? false : _MyItemRangeID.IsDirty) || (_MyItemToID == null ? false : _MyItemToID.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyZTransition == null ? true : _MyZTransition.IsValid) && (_MyContent == null ? true : _MyContent.IsValid) && (_MyItemRangeID == null ? true : _MyItemRangeID.IsValid) && (_MyItemToID == null ? true : _MyItemToID.IsValid); } + } + // TODO: Replace base Transition.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Transition + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check Transition.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Transition + protected override object GetIdValue() + { + return _TransitionID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyZTransition != null && (hasBrokenRules = _MyZTransition.HasBrokenRules) != null) return hasBrokenRules; + if (_MyContent != null && (hasBrokenRules = _MyContent.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItemToID != null && (hasBrokenRules = _MyItemToID.HasBrokenRules) != null) return hasBrokenRules; + if (_MyItemRangeID != null && (hasBrokenRules = _MyItemRangeID.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyContentRequired, "MyContent"); + ValidationRules.AddRule(MyItemToIDRequired, "MyItemToID"); + ValidationRules.AddRule(MyItemRangeIDRequired, "MyItemRangeID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _TransitionExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _TransitionExtension.AddInstanceValidationRules(ValidationRules); + // TODO: Add other validation rules + } + private static bool MyContentRequired(Transition target, Csla.Validation.RuleArgs e) + { + if (target._FromID == 0 && target._MyContent == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyItemToIDRequired(Transition target, Csla.Validation.RuleArgs e) + { + if (target._ToID == 0 && target._MyItemToID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + return true; + } + private static bool MyItemRangeIDRequired(Transition target, Csla.Validation.RuleArgs e) + { + if (target._RangeID == 0 && target._MyItemRangeID == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(TransitionID, ""); + //AuthorizationRules.AllowRead(FromID, ""); + //AuthorizationRules.AllowRead(ToID, ""); + //AuthorizationRules.AllowRead(RangeID, ""); + //AuthorizationRules.AllowRead(TranType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowWrite(FromID, ""); + //AuthorizationRules.AllowWrite(ToID, ""); + //AuthorizationRules.AllowWrite(RangeID, ""); + //AuthorizationRules.AllowWrite(TranType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + _TransitionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _TransitionExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _TransitionZTransitionCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _TransitionUnique = 0; + protected static int TransitionUnique + { get { return ++_TransitionUnique; } } + private int _MyTransitionUnique = TransitionUnique; + public int MyTransitionUnique + { get { return _MyTransitionUnique; } } + protected Transition() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) + { + List listTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listTransition.Contains(this)) listTransition.Remove(this); // Remove the item from the list + if (listTransition.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + } + public static Transition New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Transition"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.New", ex); + } + } + public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID) + { + Transition tmp = Transition.New(); + tmp.MyContent = myContent; + tmp.MyItemToID = myItemToID; + tmp.MyItemRangeID = myItemRangeID; + return tmp; + } + public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID) + { + Transition tmp = Transition.New(); + tmp.MyContent = myContent; + tmp.MyItemToID = myItemToID; + tmp.MyItemRangeID = myItemRangeID; + tmp.TranType = tranType; + tmp.Config = config; + tmp.DTS = dts; + tmp.UserID = userID; + return tmp; + } + public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID) + { + Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, tranType, config, dts, userID); + if (tmp.IsSavable) + { + Transition tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Transition New(Content myContent, Item myItemToID, Item myItemRangeID, string config) + { + Transition tmp = Transition.New(); + tmp.MyContent = myContent; + tmp.MyItemToID = myItemToID; + tmp.MyItemRangeID = myItemRangeID; + tmp.Config = config; + return tmp; + } + public static Transition MakeTransition(Content myContent, Item myItemToID, Item myItemRangeID, string config) + { + Transition tmp = Transition.New(myContent, myItemToID, myItemRangeID, config); + if (tmp.IsSavable) + { + Transition tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static Transition Get(int transitionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Transition"); + try + { + Transition tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up Transition + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.Get", ex); + } + } + public static Transition Get(SafeDataReader dr) + { + if (dr.Read()) return new Transition(dr); + return null; + } + internal Transition(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int transitionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Transition"); + try + { + DataPortal.Delete(new PKCriteria(transitionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.Delete", ex); + } + } + public override Transition Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Transition"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Transition"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Transition"); + try + { + BuildRefreshList(); + Transition transition = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(transition);//Refresh the item in AllList + ProcessRefreshList(); + return transition; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _TransitionID = NextTransitionID; + // Database Defaults + _TranType = _TransitionExtension.DefaultTranType; + _DTS = _TransitionExtension.DefaultDTS; + _UserID = _TransitionExtension.DefaultUserID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _ToID = dr.GetInt32("ToID"); + _RangeID = dr.GetInt32("RangeID"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _MyZTransition = ZTransition.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItemRangeID != null) _MyItemRangeID.Update(); + if (_MyItemToID != null) _MyItemToID.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FromID", FromID); + cm.Parameters.AddWithValue("@ToID", ToID); + cm.Parameters.AddWithValue("@RangeID", RangeID); + cm.Parameters.AddWithValue("@TranType", _TranType); + 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); + param_TransitionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_TransitionID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _TransitionID = (int)cm.Parameters["@newTransitionID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_MyZTransition != null) _MyZTransition.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int transitionID, Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@FromID", myContent.ContentID); + cm.Parameters.AddWithValue("@ToID", myItemToID.ItemID); + cm.Parameters.AddWithValue("@RangeID", myItemRangeID.ItemID); + cm.Parameters.AddWithValue("@TranType", tranType); + 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_TransitionID = new SqlParameter("@newTransitionID", SqlDbType.Int); + param_TransitionID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_TransitionID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + transitionID = (int)cm.Parameters["@newTransitionID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Add", ex); + throw new DbCslaException("Transition.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] Transition.SQLUpdate", GetHashCode()); + try + { + if (_MyContent != null) _MyContent.Update(); + if (_MyItemRangeID != null) _MyItemRangeID.Update(); + if (_MyItemToID != null) _MyItemToID.Update(); + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateTransition"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@TransitionID", _TransitionID); + cm.Parameters.AddWithValue("@FromID", FromID); + cm.Parameters.AddWithValue("@ToID", ToID); + cm.Parameters.AddWithValue("@RangeID", RangeID); + cm.Parameters.AddWithValue("@TranType", _TranType); + 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); + // TODO: 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 (_MyZTransition != null) _MyZTransition.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = Transition.Add(cn, ref _TransitionID, _MyContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID); + else + _LastChanged = Transition.Update(cn, ref _TransitionID, _MyContent, _MyItemToID, _MyItemRangeID, _TranType, _Config, _DTS, _UserID, ref _LastChanged); + MarkOld(); + } + if (_MyZTransition != null) _MyZTransition.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int transitionID, Content myContent, Item myItemToID, Item myItemRangeID, int tranType, string config, DateTime dts, string userID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", transitionID); + cm.Parameters.AddWithValue("@FromID", myContent.ContentID); + cm.Parameters.AddWithValue("@ToID", myItemToID.ItemID); + cm.Parameters.AddWithValue("@RangeID", myItemRangeID.ItemID); + cm.Parameters.AddWithValue("@TranType", tranType); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Update", ex); + throw new DbCslaException("Transition.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_TransitionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("Transition.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int transitionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteTransition"; + // Input PK Fields + cm.Parameters.AddWithValue("@TransitionID", transitionID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.Remove", ex); + throw new DbCslaException("Transition.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int transitionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(transitionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on Transition.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _TransitionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int transitionID) + { + _TransitionID = transitionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Transition.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsTransition"; + cm.Parameters.AddWithValue("@TransitionID", _TransitionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("Transition.DataPortal_Execute", ex); + throw new DbCslaException("Transition.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + TransitionExtension _TransitionExtension = new TransitionExtension(); + [Serializable()] + partial class TransitionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultTranType + { + get { return 0; } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class TransitionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is Transition) + { + // Return the ToString value + return ((Transition)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/TransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/TransitionInfo.cs index 7a2288c8..60e3a203 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/TransitionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/TransitionInfo.cs @@ -19,617 +19,604 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void TransitionInfoEvent(object sender); - /// - /// TransitionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(TransitionInfoConverter))] - public partial class TransitionInfo : ReadOnlyBase, IDisposable - { - public event TransitionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(TransitionInfo transitionInfo) - { - if (!_CacheList.Contains(transitionInfo)) _CacheList.Add(transitionInfo); // In AddToCache - } - protected static void RemoveFromCache(TransitionInfo transitionInfo) - { - while (_CacheList.Contains(transitionInfo)) _CacheList.Remove(transitionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (TransitionInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) - { - _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (TransitionInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(TransitionInfoList lst) - { - foreach (TransitionInfo item in lst) AddToCache(item); - } - protected static TransitionInfo GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected Transition _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - return _TransitionID; - } - } - private int _FromID; - public int FromID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FromID", true); - if (_MyContent != null) _FromID = _MyContent.ContentID; - return _FromID; - } - } - private ContentInfo _MyContent; - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _FromID != 0) _MyContent = ContentInfo.Get(_FromID); - return _MyContent; - } - } - private int _ToID; - /// - /// StructureID - /// - public int ToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ToID", true); - if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; - return _ToID; - } - } - private ItemInfo _MyItemToID; - public ItemInfo MyItemToID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemToID", true); - if (_MyItemToID == null && _ToID != 0) _MyItemToID = ItemInfo.Get(_ToID); - return _MyItemToID; - } - } - private int _RangeID; - public int RangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("RangeID", true); - if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; - return _RangeID; - } - } - private ItemInfo _MyItemRangeID; - public ItemInfo MyItemRangeID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyItemRangeID", true); - if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = ItemInfo.Get(_RangeID); - return _MyItemRangeID; - } - } - private int _TranType; - public int TranType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TranType", true); - return _TranType; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private int _TransitionZTransitionCount = 0; - /// - /// Count of TransitionZTransitions for this Transition - /// - public int TransitionZTransitionCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionZTransitionCount", true); - return _TransitionZTransitionCount; - } - } - private ZTransitionInfo _MyZTransition = null; - [TypeConverter(typeof(ZTransitionInfoConverter))] - public ZTransitionInfo MyZTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyZTransition", true); - if (_TransitionZTransitionCount != 0 && _MyZTransition == null) - { - _MyZTransition = ZTransitionInfo.Get(_TransitionID); - _TransitionZTransitionCount = _MyZTransition == null ? 0 : 1; - } - return _MyZTransition; - } - } - // TODO: Replace base TransitionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current TransitionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check TransitionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current TransitionInfo - protected override object GetIdValue() - { - return _TransitionID; - } - #endregion - #region Factory Methods - private static int _TransitionInfoUnique = 0; - private static int TransitionInfoUnique - { get { return ++_TransitionInfoUnique; } } - private int _MyTransitionInfoUnique = TransitionInfoUnique; - public int MyTransitionInfoUnique - { get { return _MyTransitionInfoUnique; } } - protected TransitionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; - List listTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listTransitionInfo.Contains(this)) listTransitionInfo.Remove(this); // Remove the item from the list - if (listTransitionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - public virtual Transition Get() - { - return _Editable = Transition.Get(_TransitionID); - } - public static void Refresh(Transition tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(Transition tmp) - { - if (_FromID != tmp.FromID) - { - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value - _FromID = tmp.FromID; // Update the value - } - _MyContent = null; // Reset list so that the next line gets a new list - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value - if (_ToID != tmp.ToID) - { - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value - _ToID = tmp.ToID; // Update the value - } - _MyItemToID = null; // Reset list so that the next line gets a new list - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value - if (_RangeID != tmp.RangeID) - { - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value - _RangeID = tmp.RangeID; // Update the value - } - _MyItemRangeID = null; // Reset list so that the next line gets a new list - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyItemToID != null) - { - _MyItemToID.Dispose();// Dispose related value - _MyItemToID = null;// Reset related value - } - if(_MyItemRangeID != null) - { - _MyItemRangeID.Dispose();// Dispose related value - _MyItemRangeID = null;// Reset related value - } - if(_MyZTransition != null) - { - _MyZTransition.Dispose();// Dispose related value - _MyZTransition = null;// Reset related value - } - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static void Refresh(ContentTransition tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ContentTransition tmp) - { - if (_ToID != tmp.ToID) - { - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value - _ToID = tmp.ToID; // Update the value - } - _MyItemToID = null; // Reset list so that the next line gets a new list - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value - if (_RangeID != tmp.RangeID) - { - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value - _RangeID = tmp.RangeID; // Update the value - } - _MyItemRangeID = null; // Reset list so that the next line gets a new list - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyItemToID != null) - { - _MyItemToID.Dispose();// Dispose related value - _MyItemToID = null;// Reset related value - } - if(_MyItemRangeID != null) - { - _MyItemRangeID.Dispose();// Dispose related value - _MyItemRangeID = null;// Reset related value - } - if(_MyZTransition != null) - { - _MyZTransition.Dispose();// Dispose related value - _MyZTransition = null;// Reset related value - } - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static void Refresh(ItemTransition_RangeID tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemTransition_RangeID tmp) - { - if (_FromID != tmp.FromID) - { - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value - _FromID = tmp.FromID; // Update the value - } - _MyContent = null; // Reset list so that the next line gets a new list - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value - if (_ToID != tmp.ToID) - { - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value - _ToID = tmp.ToID; // Update the value - } - _MyItemToID = null; // Reset list so that the next line gets a new list - if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyItemToID != null) - { - _MyItemToID.Dispose();// Dispose related value - _MyItemToID = null;// Reset related value - } - if(_MyItemRangeID != null) - { - _MyItemRangeID.Dispose();// Dispose related value - _MyItemRangeID = null;// Reset related value - } - if(_MyZTransition != null) - { - _MyZTransition.Dispose();// Dispose related value - _MyZTransition = null;// Reset related value - } - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static void Refresh(ItemTransition_ToID tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ItemTransition_ToID tmp) - { - if (_FromID != tmp.FromID) - { - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value - _FromID = tmp.FromID; // Update the value - } - _MyContent = null; // Reset list so that the next line gets a new list - if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value - if (_RangeID != tmp.RangeID) - { - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value - _RangeID = tmp.RangeID; // Update the value - } - _MyItemRangeID = null; // Reset list so that the next line gets a new list - if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value - _TranType = tmp.TranType; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UserID = tmp.UserID; - _TransitionInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - if(_MyItemToID != null) - { - _MyItemToID.Dispose();// Dispose related value - _MyItemToID = null;// Reset related value - } - if(_MyItemRangeID != null) - { - _MyItemRangeID.Dispose();// Dispose related value - _MyItemRangeID = null;// Reset related value - } - if(_MyZTransition != null) - { - _MyZTransition.Dispose();// Dispose related value - _MyZTransition = null;// Reset related value - } - _TransitionZTransitionCount = -1;// Reset Count - OnChange();// raise an event - } - public static TransitionInfo Get(int transitionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a Transition"); - try - { - TransitionInfo tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up TransitionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on TransitionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal TransitionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.Constructor", ex); - throw new DbCslaException("TransitionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _FromID = dr.GetInt32("FromID"); - _ToID = dr.GetInt32("ToID"); - _RangeID = dr.GetInt32("RangeID"); - _TranType = dr.GetInt32("TranType"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UserID = dr.GetString("UserID"); - _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("TransitionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("TransitionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - TransitionInfoExtension _TransitionInfoExtension = new TransitionInfoExtension(); - [Serializable()] - partial class TransitionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(TransitionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class TransitionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is TransitionInfo) - { - // Return the ToString value - return ((TransitionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void TransitionInfoEvent(object sender); + /// + /// TransitionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(TransitionInfoConverter))] + public partial class TransitionInfo : ReadOnlyBase, IDisposable + { + public event TransitionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(TransitionInfo transitionInfo) + { + if (!_CacheList.Contains(transitionInfo)) _CacheList.Add(transitionInfo); // In AddToCache + } + protected static void RemoveFromCache(TransitionInfo transitionInfo) + { + while (_CacheList.Contains(transitionInfo)) _CacheList.Remove(transitionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (TransitionInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) + { + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (TransitionInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(TransitionInfoList lst) + { + foreach (TransitionInfo item in lst) AddToCache(item); + } + protected static TransitionInfo GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected Transition _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionID; + } + } + private int _FromID; + public int FromID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _FromID = _MyContent.ContentID; + return _FromID; + } + } + private ContentInfo _MyContent; + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _FromID != 0) _MyContent = ContentInfo.Get(_FromID); + return _MyContent; + } + } + private int _ToID; + /// + /// StructureID + /// + public int ToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID != null) _ToID = _MyItemToID.ItemID; + return _ToID; + } + } + private ItemInfo _MyItemToID; + public ItemInfo MyItemToID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemToID == null && _ToID != 0) _MyItemToID = ItemInfo.Get(_ToID); + return _MyItemToID; + } + } + private int _RangeID; + public int RangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID != null) _RangeID = _MyItemRangeID.ItemID; + return _RangeID; + } + } + private ItemInfo _MyItemRangeID; + public ItemInfo MyItemRangeID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyItemRangeID == null && _RangeID != 0) _MyItemRangeID = ItemInfo.Get(_RangeID); + return _MyItemRangeID; + } + } + private int _TranType; + public int TranType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TranType; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private int _TransitionZTransitionCount = 0; + /// + /// Count of TransitionZTransitions for this Transition + /// + public int TransitionZTransitionCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _TransitionZTransitionCount; + } + } + private ZTransitionInfo _MyZTransition = null; + [TypeConverter(typeof(ZTransitionInfoConverter))] + public ZTransitionInfo MyZTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_TransitionZTransitionCount != 0 && _MyZTransition == null) + { + _MyZTransition = ZTransitionInfo.Get(_TransitionID); + _TransitionZTransitionCount = _MyZTransition == null ? 0 : 1; + } + return _MyZTransition; + } + } + // TODO: Replace base TransitionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current TransitionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check TransitionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current TransitionInfo + protected override object GetIdValue() + { + return _TransitionID; + } + #endregion + #region Factory Methods + private static int _TransitionInfoUnique = 0; + private static int TransitionInfoUnique + { get { return ++_TransitionInfoUnique; } } + private int _MyTransitionInfoUnique = TransitionInfoUnique; + public int MyTransitionInfoUnique + { get { return _MyTransitionInfoUnique; } } + protected TransitionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; + List listTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listTransitionInfo.Contains(this)) listTransitionInfo.Remove(this); // Remove the item from the list + if (listTransitionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + public virtual Transition Get() + { + return _Editable = Transition.Get(_TransitionID); + } + public static void Refresh(Transition tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(Transition tmp) + { + if (_FromID != tmp.FromID) + { + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value + _FromID = tmp.FromID; // Update the value + } + _MyContent = null; // Reset list so that the next line gets a new list + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value + if (_ToID != tmp.ToID) + { + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value + _ToID = tmp.ToID; // Update the value + } + _MyItemToID = null; // Reset list so that the next line gets a new list + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value + if (_RangeID != tmp.RangeID) + { + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value + _RangeID = tmp.RangeID; // Update the value + } + _MyItemRangeID = null; // Reset list so that the next line gets a new list + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyItemToID != null) + { + _MyItemToID.Dispose();// Dispose related value + _MyItemToID = null;// Reset related value + } + if (_MyItemRangeID != null) + { + _MyItemRangeID.Dispose();// Dispose related value + _MyItemRangeID = null;// Reset related value + } + if (_MyZTransition != null) + { + _MyZTransition.Dispose();// Dispose related value + _MyZTransition = null;// Reset related value + } + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static void Refresh(ContentTransition tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ContentTransition tmp) + { + if (_ToID != tmp.ToID) + { + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value + _ToID = tmp.ToID; // Update the value + } + _MyItemToID = null; // Reset list so that the next line gets a new list + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value + if (_RangeID != tmp.RangeID) + { + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value + _RangeID = tmp.RangeID; // Update the value + } + _MyItemRangeID = null; // Reset list so that the next line gets a new list + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyItemToID != null) + { + _MyItemToID.Dispose();// Dispose related value + _MyItemToID = null;// Reset related value + } + if (_MyItemRangeID != null) + { + _MyItemRangeID.Dispose();// Dispose related value + _MyItemRangeID = null;// Reset related value + } + if (_MyZTransition != null) + { + _MyZTransition.Dispose();// Dispose related value + _MyZTransition = null;// Reset related value + } + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static void Refresh(ItemTransition_RangeID tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemTransition_RangeID tmp) + { + if (_FromID != tmp.FromID) + { + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value + _FromID = tmp.FromID; // Update the value + } + _MyContent = null; // Reset list so that the next line gets a new list + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value + if (_ToID != tmp.ToID) + { + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for old value + _ToID = tmp.ToID; // Update the value + } + _MyItemToID = null; // Reset list so that the next line gets a new list + if (MyItemToID != null) MyItemToID.RefreshItemTransitions_ToID(); // Update List for new value + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyItemToID != null) + { + _MyItemToID.Dispose();// Dispose related value + _MyItemToID = null;// Reset related value + } + if (_MyItemRangeID != null) + { + _MyItemRangeID.Dispose();// Dispose related value + _MyItemRangeID = null;// Reset related value + } + if (_MyZTransition != null) + { + _MyZTransition.Dispose();// Dispose related value + _MyZTransition = null;// Reset related value + } + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static void Refresh(ItemTransition_ToID tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (TransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ItemTransition_ToID tmp) + { + if (_FromID != tmp.FromID) + { + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for old value + _FromID = tmp.FromID; // Update the value + } + _MyContent = null; // Reset list so that the next line gets a new list + if (MyContent != null) MyContent.RefreshContentTransitions(); // Update List for new value + if (_RangeID != tmp.RangeID) + { + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for old value + _RangeID = tmp.RangeID; // Update the value + } + _MyItemRangeID = null; // Reset list so that the next line gets a new list + if (MyItemRangeID != null) MyItemRangeID.RefreshItemTransitions_RangeID(); // Update List for new value + _TranType = tmp.TranType; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UserID = tmp.UserID; + _TransitionInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + if (_MyItemToID != null) + { + _MyItemToID.Dispose();// Dispose related value + _MyItemToID = null;// Reset related value + } + if (_MyItemRangeID != null) + { + _MyItemRangeID.Dispose();// Dispose related value + _MyItemRangeID = null;// Reset related value + } + if (_MyZTransition != null) + { + _MyZTransition.Dispose();// Dispose related value + _MyZTransition = null;// Reset related value + } + _TransitionZTransitionCount = -1;// Reset Count + OnChange();// raise an event + } + public static TransitionInfo Get(int transitionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a Transition"); + try + { + TransitionInfo tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up TransitionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on TransitionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal TransitionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.Constructor", ex); + throw new DbCslaException("TransitionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _FromID = dr.GetInt32("FromID"); + _ToID = dr.GetInt32("ToID"); + _RangeID = dr.GetInt32("RangeID"); + _TranType = dr.GetInt32("TranType"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UserID = dr.GetString("UserID"); + _TransitionZTransitionCount = dr.GetInt32("ZTransitionCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("TransitionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] TransitionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("TransitionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("TransitionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + TransitionInfoExtension _TransitionInfoExtension = new TransitionInfoExtension(); + [Serializable()] + partial class TransitionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(TransitionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class TransitionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is TransitionInfo) + { + // Return the ToString value + return ((TransitionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/User.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/User.cs index aa48f537..6d964d1a 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/User.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/User.cs @@ -20,1297 +20,1268 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// User Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(UserConverter))] - public partial class User : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshUsers = new List(); - private List _RefreshUserMemberships = new List(); - private void AddToRefreshList(List refreshUsers, List refreshUserMemberships) - { - if (IsDirty) - refreshUsers.Add(this); - if (_UserMemberships != null && _UserMemberships.IsDirty) - { - foreach (UserMembership tmp in _UserMemberships) - { - if (tmp.IsDirty) refreshUserMemberships.Add(tmp); - } - } - } - private void BuildRefreshList() - { - _RefreshUsers = new List(); - _RefreshUserMemberships = new List(); - AddToRefreshList(_RefreshUsers, _RefreshUserMemberships); - } - private void ProcessRefreshList() - { - foreach (User tmp in _RefreshUsers) - { - UserInfo.Refresh(tmp); - } - foreach (UserMembership tmp in _RefreshUserMemberships) - { - MembershipInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(User user) - { - if (!_CacheList.Contains(user)) _CacheList.Add(user); // In AddToCache - } - protected static void RemoveFromCache(User user) - { - while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (User tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString())) - { - _CacheByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (User tmp in remove) - RemoveFromCache(tmp); - } - protected static User GetCachedByPrimaryKey(int uid) - { - ConvertListToDictionary(); - string key = uid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private static int _nextUID = -1; - public static int NextUID - { - get { return _nextUID--; } - } - private int _UID; - [System.ComponentModel.DataObjectField(true, true)] - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - return _UID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserID", true); - if (value == null) value = string.Empty; - if (_UserID != value) - { - _UserID = value; - PropertyHasChanged(); - } - } - } - private string _FirstName = string.Empty; - public string FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FirstName", true); - return _FirstName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("FirstName", true); - if (value == null) value = string.Empty; - if (_FirstName != value) - { - _FirstName = value; - PropertyHasChanged(); - } - } - } - private string _MiddleName = string.Empty; - public string MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MiddleName", true); - return _MiddleName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MiddleName", true); - if (value == null) value = string.Empty; - if (_MiddleName != value) - { - _MiddleName = value; - PropertyHasChanged(); - } - } - } - private string _LastName = string.Empty; - public string LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LastName", true); - return _LastName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("LastName", true); - if (value == null) value = string.Empty; - if (_LastName != value) - { - _LastName = value; - PropertyHasChanged(); - } - } - } - private string _Suffix = string.Empty; - public string Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Suffix", true); - return _Suffix; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Suffix", true); - if (value == null) value = string.Empty; - if (_Suffix != value) - { - _Suffix = value; - PropertyHasChanged(); - } - } - } - private string _CourtesyTitle = string.Empty; - public string CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CourtesyTitle", true); - return _CourtesyTitle; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("CourtesyTitle", true); - if (value == null) value = string.Empty; - if (_CourtesyTitle != value) - { - _CourtesyTitle = value; - PropertyHasChanged(); - } - } - } - private string _PhoneNumber = string.Empty; - public string PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PhoneNumber", true); - return _PhoneNumber; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("PhoneNumber", true); - if (value == null) value = string.Empty; - if (_PhoneNumber != value) - { - _PhoneNumber = value; - PropertyHasChanged(); - } - } - } - private string _CFGName = string.Empty; - public string CFGName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CFGName", true); - return _CFGName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("CFGName", true); - if (value == null) value = string.Empty; - if (_CFGName != value) - { - _CFGName = value; - PropertyHasChanged(); - } - } - } - private string _UserLogin = string.Empty; - public string UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserLogin", true); - return _UserLogin; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserLogin", true); - if (value == null) value = string.Empty; - if (_UserLogin != value) - { - _UserLogin = value; - PropertyHasChanged(); - } - } - } - private string _UserName = string.Empty; - public string UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserName", true); - return _UserName; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UserName", true); - if (value == null) value = string.Empty; - if (_UserName != value) - { - _UserName = value; - PropertyHasChanged(); - } - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private int _UserMembershipCount = 0; - /// - /// Count of UserMemberships for this User - /// - public int UserMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMembershipCount", true); - return _UserMembershipCount; - } - } - private UserMemberships _UserMemberships = null; - /// - /// Related Field - /// - [TypeConverter(typeof(UserMembershipsConverter))] - public UserMemberships UserMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMemberships", true); - if (_UserMembershipCount > 0 && _UserMemberships == null) - _UserMemberships = UserMemberships.GetByUID(UID); - else if (_UserMemberships == null) - _UserMemberships = UserMemberships.New(); - return _UserMemberships; - } - } - public override bool IsDirty - { - get { return base.IsDirty || (_UserMemberships == null ? false : _UserMemberships.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_UserMemberships == null ? true : _UserMemberships.IsValid); } - } - // TODO: Replace base User.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current User - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check User.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current User - protected override object GetIdValue() - { - return _UID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_UserMemberships != null && (hasBrokenRules = _UserMemberships.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UserID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FirstName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("MiddleName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("LastName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Suffix", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("CourtesyTitle", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("PhoneNumber", 30)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("CFGName", 8)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserLogin", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserName", 32)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - //ValidationRules.AddDependantProperty("x", "y"); - _UserExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _UserExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(UID, ""); - //AuthorizationRules.AllowRead(UserID, ""); - //AuthorizationRules.AllowRead(FirstName, ""); - //AuthorizationRules.AllowRead(MiddleName, ""); - //AuthorizationRules.AllowRead(LastName, ""); - //AuthorizationRules.AllowRead(Suffix, ""); - //AuthorizationRules.AllowRead(CourtesyTitle, ""); - //AuthorizationRules.AllowRead(PhoneNumber, ""); - //AuthorizationRules.AllowRead(CFGName, ""); - //AuthorizationRules.AllowRead(UserLogin, ""); - //AuthorizationRules.AllowRead(UserName, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UserID, ""); - //AuthorizationRules.AllowWrite(FirstName, ""); - //AuthorizationRules.AllowWrite(MiddleName, ""); - //AuthorizationRules.AllowWrite(LastName, ""); - //AuthorizationRules.AllowWrite(Suffix, ""); - //AuthorizationRules.AllowWrite(CourtesyTitle, ""); - //AuthorizationRules.AllowWrite(PhoneNumber, ""); - //AuthorizationRules.AllowWrite(CFGName, ""); - //AuthorizationRules.AllowWrite(UserLogin, ""); - //AuthorizationRules.AllowWrite(UserName, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - _UserExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _UserExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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; - } - /// - /// determines if related records (Foreign Keys) will keep this Item from being deleted - /// - public bool CanDelete - { - get - { - // Check to make sure that there are not any related records - int usedByCount = 0; - usedByCount += _UserMembershipCount; - return (usedByCount == 0); - } - } - public static bool CanEditObject() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _UserUnique = 0; - protected static int UserUnique - { get { return ++_UserUnique; } } - private int _MyUserUnique = UserUnique; - public int MyUserUnique - { get { return _MyUserUnique; } } - protected User() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(UID.ToString())) - { - List listUser = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items - while (listUser.Contains(this)) listUser.Remove(this); // Remove the item from the list - if (listUser.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list - } - } - public static User New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a User"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.New", ex); - } - } - public static User New(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) - { - User tmp = User.New(); - tmp.UserID = userID; - tmp.FirstName = firstName; - tmp.MiddleName = middleName; - tmp.LastName = lastName; - tmp.Suffix = suffix; - tmp.CourtesyTitle = courtesyTitle; - tmp.PhoneNumber = phoneNumber; - tmp.CFGName = cFGName; - tmp.UserLogin = userLogin; - tmp.UserName = userName; - tmp.Config = config; - tmp.DTS = dts; - tmp.UsrID = usrID; - return tmp; - } - public static User MakeUser(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) - { - User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID); - if (tmp.IsSavable) - { - User tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static User New(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) - { - User tmp = User.New(); - tmp.FirstName = firstName; - tmp.MiddleName = middleName; - tmp.LastName = lastName; - tmp.Suffix = suffix; - tmp.CourtesyTitle = courtesyTitle; - tmp.PhoneNumber = phoneNumber; - tmp.CFGName = cFGName; - tmp.UserLogin = userLogin; - tmp.UserName = userName; - tmp.Config = config; - return tmp; - } - public static User MakeUser(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) - { - User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config); - if (tmp.IsSavable) - { - User tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static User Get(int uid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a User"); - try - { - User tmp = GetCachedByPrimaryKey(uid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(uid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up User - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.Get", ex); - } - } - public static User Get(SafeDataReader dr) - { - if (dr.Read()) return new User(dr); - return null; - } - internal User(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int uid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a User"); - try - { - DataPortal.Delete(new PKCriteria(uid)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.Delete", ex); - } - } - public override User Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a User"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a User"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a User"); - try - { - BuildRefreshList(); - User user = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(user);//Refresh the item in AllList - ProcessRefreshList(); - return user; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _UID; - public int UID - { get { return _UID; } } - public PKCriteria(int uid) - { - _UID = uid; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { - _UID = NextUID; - // Database Defaults - _UserID = _UserExtension.DefaultUserID; - _DTS = _UserExtension.DefaultDTS; - _UsrID = _UserExtension.DefaultUsrID; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.ReadData", GetHashCode()); - try - { - _UID = dr.GetInt32("UID"); - _UserID = dr.GetString("UserID"); - _FirstName = dr.GetString("FirstName"); - _MiddleName = dr.GetString("MiddleName"); - _LastName = dr.GetString("LastName"); - _Suffix = dr.GetString("Suffix"); - _CourtesyTitle = dr.GetString("CourtesyTitle"); - _PhoneNumber = dr.GetString("PhoneNumber"); - _CFGName = dr.GetString("CFGName"); - _UserLogin = dr.GetString("UserLogin"); - _UserName = dr.GetString("UserName"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _UserMembershipCount = dr.GetInt32("MembershipCount"); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getUser"; - cm.Parameters.AddWithValue("@UID", criteria.UID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - // load child objects - dr.NextResult(); - _UserMemberships = UserMemberships.Get(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addUser"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@FirstName", _FirstName); - cm.Parameters.AddWithValue("@MiddleName", _MiddleName); - cm.Parameters.AddWithValue("@LastName", _LastName); - cm.Parameters.AddWithValue("@Suffix", _Suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); - cm.Parameters.AddWithValue("@CFGName", _CFGName); - cm.Parameters.AddWithValue("@UserLogin", _UserLogin); - cm.Parameters.AddWithValue("@UserName", _UserName); - 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_UID = new SqlParameter("@newUID", SqlDbType.Int); - param_UID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _UID = (int)cm.Parameters["@newUID"].Value; - _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - MarkOld(); - // update child objects - if (_UserMemberships != null) _UserMemberships.Update(this); - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addUser"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UserID", userID); - cm.Parameters.AddWithValue("@FirstName", firstName); - cm.Parameters.AddWithValue("@MiddleName", middleName); - cm.Parameters.AddWithValue("@LastName", lastName); - cm.Parameters.AddWithValue("@Suffix", suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); - cm.Parameters.AddWithValue("@CFGName", cFGName); - cm.Parameters.AddWithValue("@UserLogin", userLogin); - cm.Parameters.AddWithValue("@UserName", userName); - 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_UID = new SqlParameter("@newUID", SqlDbType.Int); - param_UID.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_UID); - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - uid = (int)cm.Parameters["@newUID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Add", ex); - throw new DbCslaException("User.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] User.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateUser"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@UID", _UID); - cm.Parameters.AddWithValue("@UserID", _UserID); - cm.Parameters.AddWithValue("@FirstName", _FirstName); - cm.Parameters.AddWithValue("@MiddleName", _MiddleName); - cm.Parameters.AddWithValue("@LastName", _LastName); - cm.Parameters.AddWithValue("@Suffix", _Suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); - cm.Parameters.AddWithValue("@CFGName", _CFGName); - cm.Parameters.AddWithValue("@UserLogin", _UserLogin); - cm.Parameters.AddWithValue("@UserName", _UserName); - 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); - // TODO: 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 (_UserMemberships != null) _UserMemberships.Update(this); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update() - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = User.Add(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID); - else - _LastChanged = User.Update(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - if (_UserMemberships != null) _UserMemberships.Update(this); - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateUser"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@UID", uid); - cm.Parameters.AddWithValue("@UserID", userID); - cm.Parameters.AddWithValue("@FirstName", firstName); - cm.Parameters.AddWithValue("@MiddleName", middleName); - cm.Parameters.AddWithValue("@LastName", lastName); - cm.Parameters.AddWithValue("@Suffix", suffix); - cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); - cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); - cm.Parameters.AddWithValue("@CFGName", cFGName); - cm.Parameters.AddWithValue("@UserLogin", userLogin); - cm.Parameters.AddWithValue("@UserName", userName); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Update", ex); - throw new DbCslaException("User.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_UID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteUser"; - cm.Parameters.AddWithValue("@UID", criteria.UID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("User.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int uid) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteUser"; - // Input PK Fields - cm.Parameters.AddWithValue("@UID", uid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Remove", ex); - throw new DbCslaException("User.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int uid) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(uid)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on User.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _UID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int uid) - { - _UID = uid; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsUser"; - cm.Parameters.AddWithValue("@UID", _UID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Execute", ex); - throw new DbCslaException("User.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - UserExtension _UserExtension = new UserExtension(); - [Serializable()] - partial class UserExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual string DefaultUserID - { - get { return Environment.UserName.ToUpper(); } - } - public virtual DateTime DefaultDTS - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrID - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class UserConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is User) - { - // Return the ToString value - return ((User)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// User Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserConverter))] + public partial class User : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshUsers = new List(); + private List _RefreshUserMemberships = new List(); + private void AddToRefreshList(List refreshUsers, List refreshUserMemberships) + { + if (IsDirty) + refreshUsers.Add(this); + if (_UserMemberships != null && _UserMemberships.IsDirty) + { + foreach (UserMembership tmp in _UserMemberships) + { + if (tmp.IsDirty) refreshUserMemberships.Add(tmp); + } + } + } + private void BuildRefreshList() + { + _RefreshUsers = new List(); + _RefreshUserMemberships = new List(); + AddToRefreshList(_RefreshUsers, _RefreshUserMemberships); + } + private void ProcessRefreshList() + { + foreach (User tmp in _RefreshUsers) + { + UserInfo.Refresh(tmp); + } + foreach (UserMembership tmp in _RefreshUserMemberships) + { + MembershipInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(User user) + { + if (!_CacheList.Contains(user)) _CacheList.Add(user); // In AddToCache + } + protected static void RemoveFromCache(User user) + { + while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (User tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString())) + { + _CacheByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (User tmp in remove) + RemoveFromCache(tmp); + } + protected static User GetCachedByPrimaryKey(int uid) + { + ConvertListToDictionary(); + string key = uid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private static int _nextUID = -1; + public static int NextUID + { + get { return _nextUID--; } + } + private int _UID; + [System.ComponentModel.DataObjectField(true, true)] + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserID != value) + { + _UserID = value; + PropertyHasChanged(); + } + } + } + private string _FirstName = string.Empty; + public string FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FirstName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_FirstName != value) + { + _FirstName = value; + PropertyHasChanged(); + } + } + } + private string _MiddleName = string.Empty; + public string MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MiddleName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_MiddleName != value) + { + _MiddleName = value; + PropertyHasChanged(); + } + } + } + private string _LastName = string.Empty; + public string LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LastName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_LastName != value) + { + _LastName = value; + PropertyHasChanged(); + } + } + } + private string _Suffix = string.Empty; + public string Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Suffix; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Suffix != value) + { + _Suffix = value; + PropertyHasChanged(); + } + } + } + private string _CourtesyTitle = string.Empty; + public string CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CourtesyTitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_CourtesyTitle != value) + { + _CourtesyTitle = value; + PropertyHasChanged(); + } + } + } + private string _PhoneNumber = string.Empty; + public string PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PhoneNumber; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_PhoneNumber != value) + { + _PhoneNumber = value; + PropertyHasChanged(); + } + } + } + private string _CFGName = string.Empty; + public string CFGName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CFGName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_CFGName != value) + { + _CFGName = value; + PropertyHasChanged(); + } + } + } + private string _UserLogin = string.Empty; + public string UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserLogin; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserLogin != value) + { + _UserLogin = value; + PropertyHasChanged(); + } + } + } + private string _UserName = string.Empty; + public string UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserName; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UserName != value) + { + _UserName = value; + PropertyHasChanged(); + } + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private int _UserMembershipCount = 0; + /// + /// Count of UserMemberships for this User + /// + public int UserMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserMembershipCount; + } + } + private UserMemberships _UserMemberships = null; + /// + /// Related Field + /// + [TypeConverter(typeof(UserMembershipsConverter))] + public UserMemberships UserMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_UserMembershipCount > 0 && _UserMemberships == null) + _UserMemberships = UserMemberships.GetByUID(UID); + else if (_UserMemberships == null) + _UserMemberships = UserMemberships.New(); + return _UserMemberships; + } + } + public override bool IsDirty + { + get { return base.IsDirty || (_UserMemberships == null ? false : _UserMemberships.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_UserMemberships == null ? true : _UserMemberships.IsValid); } + } + // TODO: Replace base User.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current User + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check User.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current User + protected override object GetIdValue() + { + return _UID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_UserMemberships != null && (hasBrokenRules = _UserMemberships.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UserID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FirstName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("MiddleName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("LastName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Suffix", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("CourtesyTitle", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("PhoneNumber", 30)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("CFGName", 8)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserLogin", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserName", 32)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + //ValidationRules.AddDependantProperty("x", "y"); + _UserExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _UserExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(UID, ""); + //AuthorizationRules.AllowRead(UserID, ""); + //AuthorizationRules.AllowRead(FirstName, ""); + //AuthorizationRules.AllowRead(MiddleName, ""); + //AuthorizationRules.AllowRead(LastName, ""); + //AuthorizationRules.AllowRead(Suffix, ""); + //AuthorizationRules.AllowRead(CourtesyTitle, ""); + //AuthorizationRules.AllowRead(PhoneNumber, ""); + //AuthorizationRules.AllowRead(CFGName, ""); + //AuthorizationRules.AllowRead(UserLogin, ""); + //AuthorizationRules.AllowRead(UserName, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UserID, ""); + //AuthorizationRules.AllowWrite(FirstName, ""); + //AuthorizationRules.AllowWrite(MiddleName, ""); + //AuthorizationRules.AllowWrite(LastName, ""); + //AuthorizationRules.AllowWrite(Suffix, ""); + //AuthorizationRules.AllowWrite(CourtesyTitle, ""); + //AuthorizationRules.AllowWrite(PhoneNumber, ""); + //AuthorizationRules.AllowWrite(CFGName, ""); + //AuthorizationRules.AllowWrite(UserLogin, ""); + //AuthorizationRules.AllowWrite(UserName, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + _UserExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _UserExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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; + } + /// + /// determines if related records (Foreign Keys) will keep this Item from being deleted + /// + public bool CanDelete + { + get + { + // Check to make sure that there are not any related records + int usedByCount = 0; + usedByCount += _UserMembershipCount; + return (usedByCount == 0); + } + } + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _UserUnique = 0; + protected static int UserUnique + { get { return ++_UserUnique; } } + private int _MyUserUnique = UserUnique; + public int MyUserUnique + { get { return _MyUserUnique; } } + protected User() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(UID.ToString())) + { + List listUser = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items + while (listUser.Contains(this)) listUser.Remove(this); // Remove the item from the list + if (listUser.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list + } + } + public static User New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a User"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.New", ex); + } + } + public static User New(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) + { + User tmp = User.New(); + tmp.UserID = userID; + tmp.FirstName = firstName; + tmp.MiddleName = middleName; + tmp.LastName = lastName; + tmp.Suffix = suffix; + tmp.CourtesyTitle = courtesyTitle; + tmp.PhoneNumber = phoneNumber; + tmp.CFGName = cFGName; + tmp.UserLogin = userLogin; + tmp.UserName = userName; + tmp.Config = config; + tmp.DTS = dts; + tmp.UsrID = usrID; + return tmp; + } + public static User MakeUser(string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) + { + User tmp = User.New(userID, firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config, dts, usrID); + if (tmp.IsSavable) + { + User tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static User New(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) + { + User tmp = User.New(); + tmp.FirstName = firstName; + tmp.MiddleName = middleName; + tmp.LastName = lastName; + tmp.Suffix = suffix; + tmp.CourtesyTitle = courtesyTitle; + tmp.PhoneNumber = phoneNumber; + tmp.CFGName = cFGName; + tmp.UserLogin = userLogin; + tmp.UserName = userName; + tmp.Config = config; + return tmp; + } + public static User MakeUser(string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config) + { + User tmp = User.New(firstName, middleName, lastName, suffix, courtesyTitle, phoneNumber, cFGName, userLogin, userName, config); + if (tmp.IsSavable) + { + User tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static User Get(int uid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a User"); + try + { + User tmp = GetCachedByPrimaryKey(uid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(uid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up User + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.Get", ex); + } + } + public static User Get(SafeDataReader dr) + { + if (dr.Read()) return new User(dr); + return null; + } + internal User(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int uid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a User"); + try + { + DataPortal.Delete(new PKCriteria(uid)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.Delete", ex); + } + } + public override User Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a User"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a User"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a User"); + try + { + BuildRefreshList(); + User user = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(user);//Refresh the item in AllList + ProcessRefreshList(); + return user; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _UID; + public int UID + { get { return _UID; } } + public PKCriteria(int uid) + { + _UID = uid; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { + _UID = NextUID; + // Database Defaults + _UserID = _UserExtension.DefaultUserID; + _DTS = _UserExtension.DefaultDTS; + _UsrID = _UserExtension.DefaultUsrID; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.ReadData", GetHashCode()); + try + { + _UID = dr.GetInt32("UID"); + _UserID = dr.GetString("UserID"); + _FirstName = dr.GetString("FirstName"); + _MiddleName = dr.GetString("MiddleName"); + _LastName = dr.GetString("LastName"); + _Suffix = dr.GetString("Suffix"); + _CourtesyTitle = dr.GetString("CourtesyTitle"); + _PhoneNumber = dr.GetString("PhoneNumber"); + _CFGName = dr.GetString("CFGName"); + _UserLogin = dr.GetString("UserLogin"); + _UserName = dr.GetString("UserName"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _UserMembershipCount = dr.GetInt32("MembershipCount"); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getUser"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + // load child objects + dr.NextResult(); + _UserMemberships = UserMemberships.Get(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addUser"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@FirstName", _FirstName); + cm.Parameters.AddWithValue("@MiddleName", _MiddleName); + cm.Parameters.AddWithValue("@LastName", _LastName); + cm.Parameters.AddWithValue("@Suffix", _Suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); + cm.Parameters.AddWithValue("@CFGName", _CFGName); + cm.Parameters.AddWithValue("@UserLogin", _UserLogin); + cm.Parameters.AddWithValue("@UserName", _UserName); + 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_UID = new SqlParameter("@newUID", SqlDbType.Int); + param_UID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _UID = (int)cm.Parameters["@newUID"].Value; + _LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + MarkOld(); + // update child objects + if (_UserMemberships != null) _UserMemberships.Update(this); + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addUser"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@FirstName", firstName); + cm.Parameters.AddWithValue("@MiddleName", middleName); + cm.Parameters.AddWithValue("@LastName", lastName); + cm.Parameters.AddWithValue("@Suffix", suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); + cm.Parameters.AddWithValue("@CFGName", cFGName); + cm.Parameters.AddWithValue("@UserLogin", userLogin); + cm.Parameters.AddWithValue("@UserName", userName); + 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_UID = new SqlParameter("@newUID", SqlDbType.Int); + param_UID.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_UID); + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + uid = (int)cm.Parameters["@newUID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Add", ex); + throw new DbCslaException("User.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] User.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateUser"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@UID", _UID); + cm.Parameters.AddWithValue("@UserID", _UserID); + cm.Parameters.AddWithValue("@FirstName", _FirstName); + cm.Parameters.AddWithValue("@MiddleName", _MiddleName); + cm.Parameters.AddWithValue("@LastName", _LastName); + cm.Parameters.AddWithValue("@Suffix", _Suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber); + cm.Parameters.AddWithValue("@CFGName", _CFGName); + cm.Parameters.AddWithValue("@UserLogin", _UserLogin); + cm.Parameters.AddWithValue("@UserName", _UserName); + 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); + // TODO: 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 (_UserMemberships != null) _UserMemberships.Update(this); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update() + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = User.Add(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID); + else + _LastChanged = User.Update(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + if (_UserMemberships != null) _UserMemberships.Update(this); + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateUser"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@UID", uid); + cm.Parameters.AddWithValue("@UserID", userID); + cm.Parameters.AddWithValue("@FirstName", firstName); + cm.Parameters.AddWithValue("@MiddleName", middleName); + cm.Parameters.AddWithValue("@LastName", lastName); + cm.Parameters.AddWithValue("@Suffix", suffix); + cm.Parameters.AddWithValue("@CourtesyTitle", courtesyTitle); + cm.Parameters.AddWithValue("@PhoneNumber", phoneNumber); + cm.Parameters.AddWithValue("@CFGName", cFGName); + cm.Parameters.AddWithValue("@UserLogin", userLogin); + cm.Parameters.AddWithValue("@UserName", userName); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Update", ex); + throw new DbCslaException("User.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_UID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteUser"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("User.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int uid) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteUser"; + // Input PK Fields + cm.Parameters.AddWithValue("@UID", uid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.Remove", ex); + throw new DbCslaException("User.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int uid) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(uid)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on User.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _UID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int uid) + { + _UID = uid; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsUser"; + cm.Parameters.AddWithValue("@UID", _UID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("User.DataPortal_Execute", ex); + throw new DbCslaException("User.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + UserExtension _UserExtension = new UserExtension(); + [Serializable()] + partial class UserExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual string DefaultUserID + { + get { return Environment.UserName.ToUpper(); } + } + public virtual DateTime DefaultDTS + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrID + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class UserConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is User) + { + // Return the ToString value + return ((User)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserInfo.cs index 2134f120..98d4bbb1 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserInfo.cs @@ -19,461 +19,445 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void UserInfoEvent(object sender); - /// - /// UserInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(UserInfoConverter))] - public partial class UserInfo : ReadOnlyBase, IDisposable - { - public event UserInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(UserInfo userInfo) - { - if (!_CacheList.Contains(userInfo)) _CacheList.Add(userInfo); // In AddToCache - } - protected static void RemoveFromCache(UserInfo userInfo) - { - while (_CacheList.Contains(userInfo)) _CacheList.Remove(userInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (UserInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString())) - { - _CacheByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (UserInfo tmp in remove) - RemoveFromCache(tmp); - } - internal static void AddList(UserInfoList lst) - { - foreach (UserInfo item in lst) AddToCache(item); - } - protected static UserInfo GetCachedByPrimaryKey(int uid) - { - ConvertListToDictionary(); - string key = uid.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected User _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _UID; - [System.ComponentModel.DataObjectField(true, true)] - public int UID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UID", true); - return _UID; - } - } - private string _UserID = string.Empty; - public string UserID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserID", true); - return _UserID; - } - } - private string _FirstName = string.Empty; - public string FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("FirstName", true); - return _FirstName; - } - } - private string _MiddleName = string.Empty; - public string MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MiddleName", true); - return _MiddleName; - } - } - private string _LastName = string.Empty; - public string LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("LastName", true); - return _LastName; - } - } - private string _Suffix = string.Empty; - public string Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Suffix", true); - return _Suffix; - } - } - private string _CourtesyTitle = string.Empty; - public string CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CourtesyTitle", true); - return _CourtesyTitle; - } - } - private string _PhoneNumber = string.Empty; - public string PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("PhoneNumber", true); - return _PhoneNumber; - } - } - private string _CFGName = string.Empty; - public string CFGName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("CFGName", true); - return _CFGName; - } - } - private string _UserLogin = string.Empty; - public string UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserLogin", true); - return _UserLogin; - } - } - private string _UserName = string.Empty; - public string UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserName", true); - return _UserName; - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - } - private int _UserMembershipCount = 0; - /// - /// Count of UserMemberships for this User - /// - public int UserMembershipCount - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMembershipCount", true); - return _UserMembershipCount; - } - } - private MembershipInfoList _UserMemberships = null; - [TypeConverter(typeof(MembershipInfoListConverter))] - public MembershipInfoList UserMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UserMemberships", true); - if (_UserMembershipCount < 0 || (_UserMembershipCount > 0 && _UserMemberships == null)) - _UserMemberships = MembershipInfoList.GetByUID(_UID); - if (_UserMembershipCount < 0) - _UserMembershipCount = _UserMemberships.Count; - return _UserMemberships; - } - } - public void RefreshUserMemberships() - { - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(_UID.ToString())) - foreach (UserInfo tmp in _CacheByPrimaryKey[_UID.ToString()]) - tmp._UserMembershipCount = -1; // This will cause the data to be requeried - } - // TODO: Replace base UserInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current UserInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check UserInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current UserInfo - protected override object GetIdValue() - { - return _UID; - } - #endregion - #region Factory Methods - private static int _UserInfoUnique = 0; - private static int UserInfoUnique - { get { return ++_UserInfoUnique; } } - private int _MyUserInfoUnique = UserInfoUnique; - public int MyUserInfoUnique - { get { return _MyUserInfoUnique; } } - protected UserInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(UID.ToString())) return; - List listUserInfo = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items - while (listUserInfo.Contains(this)) listUserInfo.Remove(this); // Remove the item from the list - if (listUserInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list - } - public virtual User Get() - { - return _Editable = User.Get(_UID); - } - public static void Refresh(User tmp) - { - string key = tmp.UID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (UserInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(User tmp) - { - _UserID = tmp.UserID; - _FirstName = tmp.FirstName; - _MiddleName = tmp.MiddleName; - _LastName = tmp.LastName; - _Suffix = tmp.Suffix; - _CourtesyTitle = tmp.CourtesyTitle; - _PhoneNumber = tmp.PhoneNumber; - _CFGName = tmp.CFGName; - _UserLogin = tmp.UserLogin; - _UserName = tmp.UserName; - _Config = tmp.Config; - _DTS = tmp.DTS; - _UsrID = tmp.UsrID; - _UserInfoExtension.Refresh(this); - OnChange();// raise an event - } - public static UserInfo Get(int uid) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a User"); - try - { - UserInfo tmp = GetCachedByPrimaryKey(uid); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(uid)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up UserInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on UserInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal UserInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.Constructor", ex); - throw new DbCslaException("UserInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _UID; - public int UID - { get { return _UID; } } - public PKCriteria(int uid) - { - _UID = uid; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.ReadData", GetHashCode()); - try - { - _UID = dr.GetInt32("UID"); - _UserID = dr.GetString("UserID"); - _FirstName = dr.GetString("FirstName"); - _MiddleName = dr.GetString("MiddleName"); - _LastName = dr.GetString("LastName"); - _Suffix = dr.GetString("Suffix"); - _CourtesyTitle = dr.GetString("CourtesyTitle"); - _PhoneNumber = dr.GetString("PhoneNumber"); - _CFGName = dr.GetString("CFGName"); - _UserLogin = dr.GetString("UserLogin"); - _UserName = dr.GetString("UserName"); - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - _UserMembershipCount = dr.GetInt32("MembershipCount"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("UserInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getUser"; - cm.Parameters.AddWithValue("@UID", criteria.UID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("UserInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - UserInfoExtension _UserInfoExtension = new UserInfoExtension(); - [Serializable()] - partial class UserInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(UserInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class UserInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is UserInfo) - { - // Return the ToString value - return ((UserInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void UserInfoEvent(object sender); + /// + /// UserInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserInfoConverter))] + public partial class UserInfo : ReadOnlyBase, IDisposable + { + public event UserInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(UserInfo userInfo) + { + if (!_CacheList.Contains(userInfo)) _CacheList.Add(userInfo); // In AddToCache + } + protected static void RemoveFromCache(UserInfo userInfo) + { + while (_CacheList.Contains(userInfo)) _CacheList.Remove(userInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (UserInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.UID.ToString())) + { + _CacheByPrimaryKey[tmp.UID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.UID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (UserInfo tmp in remove) + RemoveFromCache(tmp); + } + internal static void AddList(UserInfoList lst) + { + foreach (UserInfo item in lst) AddToCache(item); + } + protected static UserInfo GetCachedByPrimaryKey(int uid) + { + ConvertListToDictionary(); + string key = uid.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected User _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _UID; + [System.ComponentModel.DataObjectField(true, true)] + public int UID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UID; + } + } + private string _UserID = string.Empty; + public string UserID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserID; + } + } + private string _FirstName = string.Empty; + public string FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _FirstName; + } + } + private string _MiddleName = string.Empty; + public string MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _MiddleName; + } + } + private string _LastName = string.Empty; + public string LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _LastName; + } + } + private string _Suffix = string.Empty; + public string Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Suffix; + } + } + private string _CourtesyTitle = string.Empty; + public string CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CourtesyTitle; + } + } + private string _PhoneNumber = string.Empty; + public string PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _PhoneNumber; + } + } + private string _CFGName = string.Empty; + public string CFGName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _CFGName; + } + } + private string _UserLogin = string.Empty; + public string UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserLogin; + } + } + private string _UserName = string.Empty; + public string UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserName; + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + } + private int _UserMembershipCount = 0; + /// + /// Count of UserMemberships for this User + /// + public int UserMembershipCount + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UserMembershipCount; + } + } + private MembershipInfoList _UserMemberships = null; + [TypeConverter(typeof(MembershipInfoListConverter))] + public MembershipInfoList UserMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_UserMembershipCount < 0 || (_UserMembershipCount > 0 && _UserMemberships == null)) + _UserMemberships = MembershipInfoList.GetByUID(_UID); + if (_UserMembershipCount < 0) + _UserMembershipCount = _UserMemberships.Count; + return _UserMemberships; + } + } + public void RefreshUserMemberships() + { + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(_UID.ToString())) + foreach (UserInfo tmp in _CacheByPrimaryKey[_UID.ToString()]) + tmp._UserMembershipCount = -1; // This will cause the data to be requeried + } + // TODO: Replace base UserInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current UserInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check UserInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current UserInfo + protected override object GetIdValue() + { + return _UID; + } + #endregion + #region Factory Methods + private static int _UserInfoUnique = 0; + private static int UserInfoUnique + { get { return ++_UserInfoUnique; } } + private int _MyUserInfoUnique = UserInfoUnique; + public int MyUserInfoUnique + { get { return _MyUserInfoUnique; } } + protected UserInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(UID.ToString())) return; + List listUserInfo = _CacheByPrimaryKey[UID.ToString()]; // Get the list of items + while (listUserInfo.Contains(this)) listUserInfo.Remove(this); // Remove the item from the list + if (listUserInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(UID.ToString()); // remove the list + } + public virtual User Get() + { + return _Editable = User.Get(_UID); + } + public static void Refresh(User tmp) + { + string key = tmp.UID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (UserInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(User tmp) + { + _UserID = tmp.UserID; + _FirstName = tmp.FirstName; + _MiddleName = tmp.MiddleName; + _LastName = tmp.LastName; + _Suffix = tmp.Suffix; + _CourtesyTitle = tmp.CourtesyTitle; + _PhoneNumber = tmp.PhoneNumber; + _CFGName = tmp.CFGName; + _UserLogin = tmp.UserLogin; + _UserName = tmp.UserName; + _Config = tmp.Config; + _DTS = tmp.DTS; + _UsrID = tmp.UsrID; + _UserInfoExtension.Refresh(this); + OnChange();// raise an event + } + public static UserInfo Get(int uid) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a User"); + try + { + UserInfo tmp = GetCachedByPrimaryKey(uid); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(uid)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up UserInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on UserInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal UserInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.Constructor", ex); + throw new DbCslaException("UserInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _UID; + public int UID + { get { return _UID; } } + public PKCriteria(int uid) + { + _UID = uid; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.ReadData", GetHashCode()); + try + { + _UID = dr.GetInt32("UID"); + _UserID = dr.GetString("UserID"); + _FirstName = dr.GetString("FirstName"); + _MiddleName = dr.GetString("MiddleName"); + _LastName = dr.GetString("LastName"); + _Suffix = dr.GetString("Suffix"); + _CourtesyTitle = dr.GetString("CourtesyTitle"); + _PhoneNumber = dr.GetString("PhoneNumber"); + _CFGName = dr.GetString("CFGName"); + _UserLogin = dr.GetString("UserLogin"); + _UserName = dr.GetString("UserName"); + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + _UserMembershipCount = dr.GetInt32("MembershipCount"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("UserInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getUser"; + cm.Parameters.AddWithValue("@UID", criteria.UID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("UserInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + UserInfoExtension _UserInfoExtension = new UserInfoExtension(); + [Serializable()] + partial class UserInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(UserInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class UserInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is UserInfo) + { + // Return the ToString value + return ((UserInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserMembership.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserMembership.cs index 3071fc6d..efcb755c 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserMembership.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/UserMembership.cs @@ -19,568 +19,548 @@ using System.ComponentModel; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// UserMembership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(UserMembershipConverter))] - public partial class UserMembership : BusinessBase, IVEHasBrokenRules - { - #region Log4Net - 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 int _UGID; - [System.ComponentModel.DataObjectField(true, true)] - public int UGID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UGID", true); - if (_MyMembership != null) _UGID = _MyMembership.UGID; - return _UGID; - } - } - private Membership _MyMembership; - [System.ComponentModel.DataObjectField(true, true)] - public Membership MyMembership - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyMembership", true); - if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); - return _MyMembership; - } - } - private int _GID; - public int GID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("GID", true); - if (_MyGroup != null) _GID = _MyGroup.GID; - return _GID; - } - } - private Group _MyGroup; - public Group MyGroup - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyGroup", true); - if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); - return _MyGroup; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("MyGroup", true); - if (_MyGroup != value) - { - _MyGroup = value; - PropertyHasChanged(); - } - } - } - private string _StartDate = string.Empty; - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("StartDate", true); - return _StartDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("StartDate", true); - if (value == null) value = string.Empty; - _StartDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_StartDate != tmp.ToString()) - { - _StartDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _EndDate = string.Empty; - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("EndDate", true); - return _EndDate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("EndDate", true); - if (value == null) value = string.Empty; - _EndDate = value; - try - { - SmartDate tmp = new SmartDate(value); - if (_EndDate != tmp.ToString()) - { - _EndDate = tmp.ToString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _Config = string.Empty; - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Config", true); - return _Config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Config", true); - if (value == null) value = string.Empty; - if (_Config != value) - { - _Config = value; - PropertyHasChanged(); - } - } - } - private DateTime _DTS = new DateTime(); - public DateTime DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("DTS", true); - return _DTS; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("DTS", true); - if (_DTS != value) - { - _DTS = value; - PropertyHasChanged(); - } - } - } - private string _UsrID = string.Empty; - public string UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("UsrID", true); - return _UsrID; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("UsrID", true); - if (value == null) value = string.Empty; - if (_UsrID != value) - { - _UsrID = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - private string _Group_GroupName = string.Empty; - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupName", true); - return _Group_GroupName; - } - } - private int? _Group_GroupType; - public int? Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_GroupType", true); - return _Group_GroupType; - } - } - private string _Group_Config = string.Empty; - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_Config", true); - return _Group_Config; - } - } - private DateTime _Group_DTS = new DateTime(); - public DateTime Group_DTS - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_DTS", true); - return _Group_DTS; - } - } - private string _Group_UsrID = string.Empty; - public string Group_UsrID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Group_UsrID", true); - return _Group_UsrID; - } - } - // TODO: Check UserMembership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current UserMembership - protected override object GetIdValue() - { - return _UGID; - } - // TODO: Replace base UserMembership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current UserMembership - //public override string ToString() - //{ - // return base.ToString(); - //} - public override bool IsDirty - { - get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty); } - } - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid); } - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if (BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule(MyGroupRequired, "MyGroup"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "StartDate"); - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "UsrID"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); - // TODO: Add other validation rules - } - private static bool StartDateValid(UserMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._StartDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool EndDateValid(UserMembership target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(target._EndDate); - } - catch - { - e.Description = "Invalid Date"; - return false; - } - return true; - } - private static bool MyGroupRequired(UserMembership target, Csla.Validation.RuleArgs e) - { - if (target._GID == 0 && target._MyGroup == null) // Required field missing - { - e.Description = "Required"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(UGID, ""); - //AuthorizationRules.AllowRead(GID, ""); - //AuthorizationRules.AllowWrite(GID, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(DTS, ""); - //AuthorizationRules.AllowWrite(DTS, ""); - //AuthorizationRules.AllowRead(UsrID, ""); - //AuthorizationRules.AllowWrite(UsrID, ""); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - internal static UserMembership New(Group myGroup) - { - return new UserMembership(myGroup); - } - internal static UserMembership Get(SafeDataReader dr) - { - return new UserMembership(dr); - } - public UserMembership() - { - MarkAsChild(); - _UGID = Membership.NextUGID; - _StartDate = _UserMembershipExtension.DefaultStartDate; - _DTS = _UserMembershipExtension.DefaultDTS; - _UsrID = _UserMembershipExtension.DefaultUsrID; - ValidationRules.CheckRules(); - } - private UserMembership(Group myGroup) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _StartDate = _UserMembershipExtension.DefaultStartDate; - _DTS = _UserMembershipExtension.DefaultDTS; - _UsrID = _UserMembershipExtension.DefaultUsrID; - _MyGroup = myGroup; - ValidationRules.CheckRules(); - } - internal UserMembership(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } - #endregion - #region Data Access Portal - private void Fetch(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserMembership.FetchDR", GetHashCode()); - try - { - _UGID = dr.GetInt32("UGID"); - _GID = dr.GetInt32("GID"); - _StartDate = dr.GetSmartDate("StartDate").Text; - _EndDate = dr.GetSmartDate("EndDate").Text; - _Config = dr.GetString("Config"); - _DTS = dr.GetDateTime("DTS"); - _UsrID = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - _Group_GroupName = dr.GetString("Group_GroupName"); - _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); - _Group_Config = dr.GetString("Group_Config"); - _Group_DTS = dr.GetDateTime("Group_DTS"); - _Group_UsrID = dr.GetString("Group_UsrID"); - } - catch (Exception ex) // FKItem Fetch - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("UserMembership.FetchDR", ex); - throw new DbCslaException("UserMembership.Fetch", ex); - } - MarkOld(); - } - internal void Insert(User myUser) - { - // 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); - MarkOld(); - } - internal void Update(User myUser) - { - // 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, myUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); - MarkOld(); - } - internal void DeleteSelf(User myUser) - { - // 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"]; - Membership.Remove(cn, _UGID); - MarkNew(); - } - #endregion - // Standard Default Code - #region extension - UserMembershipExtension _UserMembershipExtension = new UserMembershipExtension(); - [Serializable()] - partial class UserMembershipExtension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class UserMembershipConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is UserMembership) - { - // Return the ToString value - return ((UserMembership)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + /// + /// UserMembership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(UserMembershipConverter))] + public partial class UserMembership : BusinessBase, IVEHasBrokenRules + { + #region Log4Net + 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 int _UGID; + [System.ComponentModel.DataObjectField(true, true)] + public int UGID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership != null) _UGID = _MyMembership.UGID; + return _UGID; + } + } + private Membership _MyMembership; + [System.ComponentModel.DataObjectField(true, true)] + public Membership MyMembership + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyMembership == null && _UGID != 0) _MyMembership = Membership.Get(_UGID); + return _MyMembership; + } + } + private int _GID; + public int GID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup != null) _GID = _MyGroup.GID; + return _GID; + } + } + private Group _MyGroup; + public Group MyGroup + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyGroup == null && _GID != 0) _MyGroup = Group.Get(_GID); + return _MyGroup; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_MyGroup != value) + { + _MyGroup = value; + PropertyHasChanged(); + } + } + } + private string _StartDate = string.Empty; + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _StartDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _StartDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_StartDate != tmp.ToString()) + { + _StartDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _EndDate = string.Empty; + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _EndDate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _EndDate = value; + try + { + SmartDate tmp = new SmartDate(value); + if (_EndDate != tmp.ToString()) + { + _EndDate = tmp.ToString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } + private DateTime _DTS = new DateTime(); + public DateTime DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _DTS; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_DTS != value) + { + _DTS = value; + PropertyHasChanged(); + } + } + } + private string _UsrID = string.Empty; + public string UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _UsrID; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_UsrID != value) + { + _UsrID = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + private string _Group_GroupName = string.Empty; + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupName; + } + } + private int? _Group_GroupType; + public int? Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_GroupType; + } + } + private string _Group_Config = string.Empty; + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_Config; + } + } + private DateTime _Group_DTS = new DateTime(); + public DateTime Group_DTS + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_DTS; + } + } + private string _Group_UsrID = string.Empty; + public string Group_UsrID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Group_UsrID; + } + } + // TODO: Check UserMembership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current UserMembership + protected override object GetIdValue() + { + return _UGID; + } + // TODO: Replace base UserMembership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current UserMembership + //public override string ToString() + //{ + // return base.ToString(); + //} + public override bool IsDirty + { + get { return base.IsDirty || (_MyGroup == null ? false : _MyGroup.IsDirty); } + } + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid) && (_MyGroup == null ? true : _MyGroup.IsValid); } + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if (BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + if (_MyGroup != null && (hasBrokenRules = _MyGroup.HasBrokenRules) != null) return hasBrokenRules; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(MyGroupRequired, "MyGroup"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "StartDate"); + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "UsrID"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UsrID", 100)); + // TODO: Add other validation rules + } + private static bool StartDateValid(UserMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._StartDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool EndDateValid(UserMembership target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(target._EndDate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private static bool MyGroupRequired(UserMembership target, Csla.Validation.RuleArgs e) + { + if (target._GID == 0 && target._MyGroup == null) // Required field missing + { + e.Description = "Required"; + return false; + } + 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(UGID, ""); + //AuthorizationRules.AllowRead(GID, ""); + //AuthorizationRules.AllowWrite(GID, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(DTS, ""); + //AuthorizationRules.AllowWrite(DTS, ""); + //AuthorizationRules.AllowRead(UsrID, ""); + //AuthorizationRules.AllowWrite(UsrID, ""); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + internal static UserMembership New(Group myGroup) + { + return new UserMembership(myGroup); + } + internal static UserMembership Get(SafeDataReader dr) + { + return new UserMembership(dr); + } + public UserMembership() + { + MarkAsChild(); + _UGID = Membership.NextUGID; + _StartDate = _UserMembershipExtension.DefaultStartDate; + _DTS = _UserMembershipExtension.DefaultDTS; + _UsrID = _UserMembershipExtension.DefaultUsrID; + ValidationRules.CheckRules(); + } + private UserMembership(Group myGroup) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _StartDate = _UserMembershipExtension.DefaultStartDate; + _DTS = _UserMembershipExtension.DefaultDTS; + _UsrID = _UserMembershipExtension.DefaultUsrID; + _MyGroup = myGroup; + ValidationRules.CheckRules(); + } + internal UserMembership(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + #endregion + #region Data Access Portal + private void Fetch(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] UserMembership.FetchDR", GetHashCode()); + try + { + _UGID = dr.GetInt32("UGID"); + _GID = dr.GetInt32("GID"); + _StartDate = dr.GetSmartDate("StartDate").Text; + _EndDate = dr.GetSmartDate("EndDate").Text; + _Config = dr.GetString("Config"); + _DTS = dr.GetDateTime("DTS"); + _UsrID = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + _Group_GroupName = dr.GetString("Group_GroupName"); + _Group_GroupType = (int?)dr.GetValue("Group_GroupType"); + _Group_Config = dr.GetString("Group_Config"); + _Group_DTS = dr.GetDateTime("Group_DTS"); + _Group_UsrID = dr.GetString("Group_UsrID"); + } + catch (Exception ex) // FKItem Fetch + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("UserMembership.FetchDR", ex); + throw new DbCslaException("UserMembership.Fetch", ex); + } + MarkOld(); + } + internal void Insert(User myUser) + { + // 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); + MarkOld(); + } + internal void Update(User myUser) + { + // 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, myUser, _MyGroup, new SmartDate(_StartDate), new SmartDate(_EndDate), _Config, _DTS, _UsrID, ref _LastChanged); + MarkOld(); + } + internal void DeleteSelf(User myUser) + { + // 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"]; + Membership.Remove(cn, _UGID); + MarkNew(); + } + #endregion + // Standard Default Code + #region extension + UserMembershipExtension _UserMembershipExtension = new UserMembershipExtension(); + [Serializable()] + partial class UserMembershipExtension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class UserMembershipConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is UserMembership) + { + // Return the ToString value + return ((UserMembership)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContent.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContent.cs index cee1a28c..c8e38d85 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContent.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContent.cs @@ -20,808 +20,804 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ZContent Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZContentConverter))] - public partial class ZContent : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshZContents = new List(); - private void AddToRefreshList(List refreshZContents) - { - if (IsDirty) - refreshZContents.Add(this); - } - private void BuildRefreshList() - { - _RefreshZContents = new List(); - AddToRefreshList(_RefreshZContents); - } - private void ProcessRefreshList() - { - foreach (ZContent tmp in _RefreshZContents) - { - ZContentInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZContent zContent) - { - if (!_CacheList.Contains(zContent)) _CacheList.Add(zContent); // In AddToCache - } - protected static void RemoveFromCache(ZContent zContent) - { - while (_CacheList.Contains(zContent)) _CacheList.Remove(zContent); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ZContent tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ZContent tmp in remove) - RemoveFromCache(tmp); - } - protected static ZContent GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _ContentID; - [System.ComponentModel.DataObjectField(true, true)] - public int ContentID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private Content _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public Content MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); - return _MyContent; - } - } - private string _OldStepSequence = string.Empty; - public string OldStepSequence - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OldStepSequence", true); - return _OldStepSequence; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("OldStepSequence", true); - if (value == null) value = string.Empty; - if (_OldStepSequence != value) - { - _OldStepSequence = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid); } - } - // TODO: Replace base ZContent.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZContent - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ZContent.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZContent - protected override object GetIdValue() - { - return _ContentID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "OldStepSequence"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("OldStepSequence", 32)); - //ValidationRules.AddDependantProperty("x", "y"); - _ZContentExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ZContentExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(ContentID, ""); - //AuthorizationRules.AllowRead(OldStepSequence, ""); - //AuthorizationRules.AllowWrite(OldStepSequence, ""); - _ZContentExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ZContentExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ZContentUnique = 0; - protected static int ZContentUnique - { get { return ++_ZContentUnique; } } - private int _MyZContentUnique = ZContentUnique; - public int MyZContentUnique - { get { return _MyZContentUnique; } } - protected ZContent() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) - { - List listZContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listZContent.Contains(this)) listZContent.Remove(this); // Remove the item from the list - if (listZContent.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - } - public static ZContent New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZContent"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.New", ex); - } - } - public static ZContent New(Content myContent, string oldStepSequence) - { - ZContent tmp = ZContent.New(); - tmp._MyContent = myContent; - tmp.OldStepSequence = oldStepSequence; - return tmp; - } - public static ZContent MakeZContent(Content myContent, string oldStepSequence) - { - ZContent tmp = ZContent.New(myContent, oldStepSequence); - if (tmp.IsSavable) - { - ZContent tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ZContent New(Content myContent) - { - ZContent tmp = ZContent.New(); - tmp._MyContent = myContent; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - public static ZContent Get(int contentID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ZContent"); - try - { - ZContent tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZContent - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.Get", ex); - } - } - public static ZContent Get(SafeDataReader dr) - { - if (dr.Read()) return new ZContent(dr); - return null; - } - internal ZContent(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int contentID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZContent"); - try - { - DataPortal.Delete(new PKCriteria(contentID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.Delete", ex); - } - } - public override ZContent Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZContent"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZContent"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ZContent"); - try - { - BuildRefreshList(); - ZContent zContent = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(zContent);//Refresh the item in AllList - ProcessRefreshList(); - return zContent; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// ZContent Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZContentConverter))] + public partial class ZContent : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshZContents = new List(); + private void AddToRefreshList(List refreshZContents) + { + if (IsDirty) + refreshZContents.Add(this); + } + private void BuildRefreshList() + { + _RefreshZContents = new List(); + AddToRefreshList(_RefreshZContents); + } + private void ProcessRefreshList() + { + foreach (ZContent tmp in _RefreshZContents) + { + ZContentInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZContent zContent) + { + if (!_CacheList.Contains(zContent)) _CacheList.Add(zContent); // In AddToCache + } + protected static void RemoveFromCache(ZContent zContent) + { + while (_CacheList.Contains(zContent)) _CacheList.Remove(zContent); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZContent tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ZContent tmp in remove) + RemoveFromCache(tmp); + } + protected static ZContent GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _ContentID; + [System.ComponentModel.DataObjectField(true, true)] + public int ContentID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private Content _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public Content MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = Content.Get(_ContentID); + return _MyContent; + } + } + private string _OldStepSequence = string.Empty; + public string OldStepSequence + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OldStepSequence; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_OldStepSequence != value) + { + _OldStepSequence = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid); } + } + // TODO: Replace base ZContent.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZContent + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ZContent.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZContent + protected override object GetIdValue() + { + return _ContentID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "OldStepSequence"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("OldStepSequence", 32)); + //ValidationRules.AddDependantProperty("x", "y"); + _ZContentExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ZContentExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(ContentID, ""); + //AuthorizationRules.AllowRead(OldStepSequence, ""); + //AuthorizationRules.AllowWrite(OldStepSequence, ""); + _ZContentExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ZContentExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ZContentUnique = 0; + protected static int ZContentUnique + { get { return ++_ZContentUnique; } } + private int _MyZContentUnique = ZContentUnique; + public int MyZContentUnique + { get { return _MyZContentUnique; } } + protected ZContent() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) + { + List listZContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listZContent.Contains(this)) listZContent.Remove(this); // Remove the item from the list + if (listZContent.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + } + public static ZContent New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZContent"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.New", ex); + } + } + public static ZContent New(Content myContent, string oldStepSequence) + { + ZContent tmp = ZContent.New(); + tmp._MyContent = myContent; + tmp.OldStepSequence = oldStepSequence; + return tmp; + } + public static ZContent MakeZContent(Content myContent, string oldStepSequence) + { + ZContent tmp = ZContent.New(myContent, oldStepSequence); + if (tmp.IsSavable) + { + ZContent tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ZContent New(Content myContent) + { + ZContent tmp = ZContent.New(); + tmp._MyContent = myContent; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + public static ZContent Get(int contentID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ZContent"); + try + { + ZContent tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZContent + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.Get", ex); + } + } + public static ZContent Get(SafeDataReader dr) + { + if (dr.Read()) return new ZContent(dr); + return null; + } + internal ZContent(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int contentID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZContent"); + try + { + DataPortal.Delete(new PKCriteria(contentID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.Delete", ex); + } + } + public override ZContent Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZContent"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZContent"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ZContent"); + try + { + BuildRefreshList(); + ZContent zContent = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(zContent);//Refresh the item in AllList + ProcessRefreshList(); + return zContent; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults + // Database Defaults - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _OldStepSequence = dr.GetString("OldStepSequence"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addZContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: 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}] ZContent.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, Content myContent, string oldStepSequence) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addZContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Add", ex); - throw new DbCslaException("ZContent.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ZContent.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateZContent"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@ContentID", ContentID); - cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Content content) - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ZContent.Add(cn, content, _OldStepSequence); - else - _LastChanged = ZContent.Update(cn, content, _OldStepSequence, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, Content myContent, string oldStepSequence, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateZContent"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); - cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Update", ex); - throw new DbCslaException("ZContent.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}] ZContent.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteZContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContent.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int contentID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteZContent"; - // Input PK Fields - cm.Parameters.AddWithValue("@ContentID", contentID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Remove", ex); - throw new DbCslaException("ZContent.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int contentID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(contentID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContent.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _ContentID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int contentID) - { - _ContentID = contentID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsZContent"; - cm.Parameters.AddWithValue("@ContentID", _ContentID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Execute", ex); - throw new DbCslaException("ZContent.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ZContentExtension _ZContentExtension = new ZContentExtension(); - [Serializable()] - partial class ZContentExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ZContentConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZContent) - { - // Return the ToString value - return ((ZContent)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _OldStepSequence = dr.GetString("OldStepSequence"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addZContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: 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}] ZContent.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, Content myContent, string oldStepSequence) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addZContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Add", ex); + throw new DbCslaException("ZContent.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ZContent.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateZContent"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@ContentID", ContentID); + cm.Parameters.AddWithValue("@OldStepSequence", _OldStepSequence); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Content content) + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ZContent.Add(cn, content, _OldStepSequence); + else + _LastChanged = ZContent.Update(cn, content, _OldStepSequence, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, Content myContent, string oldStepSequence, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateZContent"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@ContentID", myContent.ContentID); + cm.Parameters.AddWithValue("@OldStepSequence", oldStepSequence); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Update", ex); + throw new DbCslaException("ZContent.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}] ZContent.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteZContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContent.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int contentID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteZContent"; + // Input PK Fields + cm.Parameters.AddWithValue("@ContentID", contentID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.Remove", ex); + throw new DbCslaException("ZContent.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int contentID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(contentID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContent.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _ContentID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int contentID) + { + _ContentID = contentID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContent.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsZContent"; + cm.Parameters.AddWithValue("@ContentID", _ContentID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContent.DataPortal_Execute", ex); + throw new DbCslaException("ZContent.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ZContentExtension _ZContentExtension = new ZContentExtension(); + [Serializable()] + partial class ZContentExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ZContentConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZContent) + { + // Return the ToString value + return ((ZContent)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContentInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContentInfo.cs index 017f7295..3603bdba 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContentInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZContentInfo.cs @@ -19,295 +19,292 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ZContentInfoEvent(object sender); - /// - /// ZContentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZContentInfoConverter))] - public partial class ZContentInfo : ReadOnlyBase, IDisposable - { - public event ZContentInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZContentInfo zContentInfo) - { - if (!_CacheList.Contains(zContentInfo)) _CacheList.Add(zContentInfo); // In AddToCache - } - protected static void RemoveFromCache(ZContentInfo zContentInfo) - { - while (_CacheList.Contains(zContentInfo)) _CacheList.Remove(zContentInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ZContentInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) - { - _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ZContentInfo tmp in remove) - RemoveFromCache(tmp); - } - protected static ZContentInfo GetCachedByPrimaryKey(int contentID) - { - ConvertListToDictionary(); - string key = contentID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ZContent _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 - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("ContentID", true); - if (_MyContent != null) _ContentID = _MyContent.ContentID; - return _ContentID; - } - } - private ContentInfo _MyContent; - [System.ComponentModel.DataObjectField(true, true)] - public ContentInfo MyContent - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyContent", true); - if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); - return _MyContent; - } - } - private string _OldStepSequence = string.Empty; - public string OldStepSequence - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("OldStepSequence", true); - return _OldStepSequence; - } - } - // TODO: Replace base ZContentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZContentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ZContentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZContentInfo - protected override object GetIdValue() - { - return _ContentID; - } - #endregion - #region Factory Methods - private static int _ZContentInfoUnique = 0; - private static int ZContentInfoUnique - { get { return ++_ZContentInfoUnique; } } - private int _MyZContentInfoUnique = ZContentInfoUnique; - public int MyZContentInfoUnique - { get { return _MyZContentInfoUnique; } } - protected ZContentInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; - List listZContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items - while (listZContentInfo.Contains(this)) listZContentInfo.Remove(this); // Remove the item from the list - if (listZContentInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list - } - public virtual ZContent Get() - { - return _Editable = ZContent.Get(_ContentID); - } - public static void Refresh(ZContent tmp) - { - string key = tmp.ContentID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ZContentInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ZContent tmp) - { - _OldStepSequence = tmp.OldStepSequence; - _ZContentInfoExtension.Refresh(this); - if(_MyContent != null) - { - _MyContent.Dispose();// Dispose related value - _MyContent = null;// Reset related value - } - OnChange();// raise an event - } - public static ZContentInfo Get(int contentID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ZContent"); - try - { - ZContentInfo tmp = GetCachedByPrimaryKey(contentID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(contentID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZContentInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZContentInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ZContentInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.Constructor", ex); - throw new DbCslaException("ZContentInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _ContentID; - public int ContentID - { get { return _ContentID; } } - public PKCriteria(int contentID) - { - _ContentID = contentID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.ReadData", GetHashCode()); - try - { - _ContentID = dr.GetInt32("ContentID"); - _OldStepSequence = dr.GetString("OldStepSequence"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContentInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZContent"; - cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZContentInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ZContentInfoExtension _ZContentInfoExtension = new ZContentInfoExtension(); - [Serializable()] - partial class ZContentInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ZContentInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ZContentInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZContentInfo) - { - // Return the ToString value - return ((ZContentInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ZContentInfoEvent(object sender); + /// + /// ZContentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZContentInfoConverter))] + public partial class ZContentInfo : ReadOnlyBase, IDisposable + { + public event ZContentInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZContentInfo zContentInfo) + { + if (!_CacheList.Contains(zContentInfo)) _CacheList.Add(zContentInfo); // In AddToCache + } + protected static void RemoveFromCache(ZContentInfo zContentInfo) + { + while (_CacheList.Contains(zContentInfo)) _CacheList.Remove(zContentInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZContentInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString())) + { + _CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ZContentInfo tmp in remove) + RemoveFromCache(tmp); + } + protected static ZContentInfo GetCachedByPrimaryKey(int contentID) + { + ConvertListToDictionary(); + string key = contentID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ZContent _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 + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent != null) _ContentID = _MyContent.ContentID; + return _ContentID; + } + } + private ContentInfo _MyContent; + [System.ComponentModel.DataObjectField(true, true)] + public ContentInfo MyContent + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyContent == null && _ContentID != 0) _MyContent = ContentInfo.Get(_ContentID); + return _MyContent; + } + } + private string _OldStepSequence = string.Empty; + public string OldStepSequence + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _OldStepSequence; + } + } + // TODO: Replace base ZContentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZContentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ZContentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZContentInfo + protected override object GetIdValue() + { + return _ContentID; + } + #endregion + #region Factory Methods + private static int _ZContentInfoUnique = 0; + private static int ZContentInfoUnique + { get { return ++_ZContentInfoUnique; } } + private int _MyZContentInfoUnique = ZContentInfoUnique; + public int MyZContentInfoUnique + { get { return _MyZContentInfoUnique; } } + protected ZContentInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(ContentID.ToString())) return; + List listZContentInfo = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items + while (listZContentInfo.Contains(this)) listZContentInfo.Remove(this); // Remove the item from the list + if (listZContentInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list + } + public virtual ZContent Get() + { + return _Editable = ZContent.Get(_ContentID); + } + public static void Refresh(ZContent tmp) + { + string key = tmp.ContentID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ZContentInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ZContent tmp) + { + _OldStepSequence = tmp.OldStepSequence; + _ZContentInfoExtension.Refresh(this); + if (_MyContent != null) + { + _MyContent.Dispose();// Dispose related value + _MyContent = null;// Reset related value + } + OnChange();// raise an event + } + public static ZContentInfo Get(int contentID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ZContent"); + try + { + ZContentInfo tmp = GetCachedByPrimaryKey(contentID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(contentID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZContentInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZContentInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ZContentInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.Constructor", ex); + throw new DbCslaException("ZContentInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _ContentID; + public int ContentID + { get { return _ContentID; } } + public PKCriteria(int contentID) + { + _ContentID = contentID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.ReadData", GetHashCode()); + try + { + _ContentID = dr.GetInt32("ContentID"); + _OldStepSequence = dr.GetString("OldStepSequence"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContentInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZContentInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZContent"; + cm.Parameters.AddWithValue("@ContentID", criteria.ContentID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZContentInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZContentInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ZContentInfoExtension _ZContentInfoExtension = new ZContentInfoExtension(); + [Serializable()] + partial class ZContentInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ZContentInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ZContentInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZContentInfo) + { + // Return the ToString value + return ((ZContentInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransition.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransition.cs index de463d67..df5ac8a6 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransition.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransition.cs @@ -20,808 +20,804 @@ using System.Collections.Generic; using Csla.Validation; namespace VEPROMS.CSLA.Library { - /// - /// ZTransition Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZTransitionConverter))] - public partial class ZTransition : BusinessBase, IDisposable, IVEHasBrokenRules - { - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Refresh - private List _RefreshZTransitions = new List(); - private void AddToRefreshList(List refreshZTransitions) - { - if (IsDirty) - refreshZTransitions.Add(this); - } - private void BuildRefreshList() - { - _RefreshZTransitions = new List(); - AddToRefreshList(_RefreshZTransitions); - } - private void ProcessRefreshList() - { - foreach (ZTransition tmp in _RefreshZTransitions) - { - ZTransitionInfo.Refresh(tmp); - } - } - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZTransition zTransition) - { - if (!_CacheList.Contains(zTransition)) _CacheList.Add(zTransition); // In AddToCache - } - protected static void RemoveFromCache(ZTransition zTransition) - { - while (_CacheList.Contains(zTransition)) _CacheList.Remove(zTransition); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ZTransition tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) - { - _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ZTransition tmp in remove) - RemoveFromCache(tmp); - } - protected static ZTransition GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private Transition _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public Transition MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); - return _MyTransition; - } - } - private string _Oldto = string.Empty; - public string Oldto - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Oldto", true); - return _Oldto; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty("Oldto", true); - if (value == null) value = string.Empty; - if (_Oldto != value) - { - _Oldto = value; - PropertyHasChanged(); - } - } - } - private byte[] _LastChanged = new byte[8];//timestamp - public override bool IsValid - { - get { return (IsNew && !IsDirty ? true : base.IsValid); } - } - // TODO: Replace base ZTransition.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZTransition - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ZTransition.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZTransition - protected override object GetIdValue() - { - return _TransitionID; - } - #endregion - #region ValidationRules - [NonSerialized] - private bool _CheckingBrokenRules = false; - public IVEHasBrokenRules HasBrokenRules - { - get - { - if (_CheckingBrokenRules) return null; - if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; - try - { - _CheckingBrokenRules = true; - IVEHasBrokenRules hasBrokenRules = null; - return hasBrokenRules; - } - finally - { - _CheckingBrokenRules = false; - } - } - } - public BrokenRulesCollection BrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = HasBrokenRules; - if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; - return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); - } - } - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Oldto"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Oldto", 32)); - //ValidationRules.AddDependantProperty("x", "y"); - _ZTransitionExtension.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - } - protected override void AddInstanceBusinessRules() - { - _ZTransitionExtension.AddInstanceValidationRules(ValidationRules); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(TransitionID, ""); - //AuthorizationRules.AllowRead(Oldto, ""); - //AuthorizationRules.AllowWrite(Oldto, ""); - _ZTransitionExtension.AddAuthorizationRules(AuthorizationRules); - } - protected override void AddInstanceAuthorizationRules() - { - //TODO: Who can read/write which fields - _ZTransitionExtension.AddInstanceAuthorizationRules(AuthorizationRules); - } - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - public int CurrentEditLevel - { get { return EditLevel; } } - private static int _ZTransitionUnique = 0; - protected static int ZTransitionUnique - { get { return ++_ZTransitionUnique; } } - private int _MyZTransitionUnique = ZTransitionUnique; - public int MyZTransitionUnique - { get { return _MyZTransitionUnique; } } - protected ZTransition() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromDictionaries(); - } - private void RemoveFromDictionaries() - { - RemoveFromCache(this); - if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) - { - List listZTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listZTransition.Contains(this)) listZTransition.Remove(this); // Remove the item from the list - if (listZTransition.Count == 0) //If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - } - public static ZTransition New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZTransition"); - try - { - return DataPortal.Create(); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.New", ex); - } - } - public static ZTransition New(Transition myTransition, string oldto) - { - ZTransition tmp = ZTransition.New(); - tmp._MyTransition = myTransition; - tmp.Oldto = oldto; - return tmp; - } - public static ZTransition MakeZTransition(Transition myTransition, string oldto) - { - ZTransition tmp = ZTransition.New(myTransition, oldto); - if (tmp.IsSavable) - { - ZTransition tmp2 = tmp; - tmp = tmp2.Save(); - tmp2.Dispose(); - } - else - { - Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); - tmp._ErrorMessage = "Failed Validation:"; - foreach (Csla.Validation.BrokenRule br in brc) - { - tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; - } - } - return tmp; - } - public static ZTransition New(Transition myTransition) - { - ZTransition tmp = ZTransition.New(); - tmp._MyTransition = myTransition; - tmp.MarkClean(); - tmp.MarkAsChild(); - return tmp; - } - public static ZTransition Get(int transitionID) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a ZTransition"); - try - { - ZTransition tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZTransition - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.Get", ex); - } - } - public static ZTransition Get(SafeDataReader dr) - { - if (dr.Read()) return new ZTransition(dr); - return null; - } - internal ZTransition(SafeDataReader dr) - { - ReadData(dr); - } - public static void Delete(int transitionID) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); - try - { - DataPortal.Delete(new PKCriteria(transitionID)); - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.Delete", ex); - } - } - public override ZTransition Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a ZTransition"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a ZTransition"); - try - { - BuildRefreshList(); - ZTransition zTransition = base.Save(); - RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache - AddToCache(zTransition);//Refresh the item in AllList - ProcessRefreshList(); - return zTransition; - } - catch (Exception ex) - { - throw new DbCslaException("Error on CSLA Save", ex); - } - } - #endregion - #region Data Access Portal - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - // TODO: If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create() - { + /// + /// ZTransition Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZTransitionConverter))] + public partial class ZTransition : BusinessBase, IDisposable, IVEHasBrokenRules + { + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Refresh + private List _RefreshZTransitions = new List(); + private void AddToRefreshList(List refreshZTransitions) + { + if (IsDirty) + refreshZTransitions.Add(this); + } + private void BuildRefreshList() + { + _RefreshZTransitions = new List(); + AddToRefreshList(_RefreshZTransitions); + } + private void ProcessRefreshList() + { + foreach (ZTransition tmp in _RefreshZTransitions) + { + ZTransitionInfo.Refresh(tmp); + } + } + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZTransition zTransition) + { + if (!_CacheList.Contains(zTransition)) _CacheList.Add(zTransition); // In AddToCache + } + protected static void RemoveFromCache(ZTransition zTransition) + { + while (_CacheList.Contains(zTransition)) _CacheList.Remove(zTransition); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZTransition tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) + { + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ZTransition tmp in remove) + RemoveFromCache(tmp); + } + protected static ZTransition GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private Transition _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public Transition MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = Transition.Get(_TransitionID); + return _MyTransition; + } + } + private string _Oldto = string.Empty; + public string Oldto + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Oldto; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_Oldto != value) + { + _Oldto = value; + PropertyHasChanged(); + } + } + } + private byte[] _LastChanged = new byte[8];//timestamp + public override bool IsValid + { + get { return (IsNew && !IsDirty ? true : base.IsValid); } + } + // TODO: Replace base ZTransition.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZTransition + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ZTransition.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZTransition + protected override object GetIdValue() + { + return _TransitionID; + } + #endregion + #region ValidationRules + [NonSerialized] + private bool _CheckingBrokenRules = false; + public IVEHasBrokenRules HasBrokenRules + { + get + { + if (_CheckingBrokenRules) return null; + if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this; + try + { + _CheckingBrokenRules = true; + IVEHasBrokenRules hasBrokenRules = null; + return hasBrokenRules; + } + finally + { + _CheckingBrokenRules = false; + } + } + } + public BrokenRulesCollection BrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = HasBrokenRules; + if (this.Equals(hasBrokenRules)) return BrokenRulesCollection; + return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null); + } + } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Oldto"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Oldto", 32)); + //ValidationRules.AddDependantProperty("x", "y"); + _ZTransitionExtension.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + } + protected override void AddInstanceBusinessRules() + { + _ZTransitionExtension.AddInstanceValidationRules(ValidationRules); + // TODO: 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() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(TransitionID, ""); + //AuthorizationRules.AllowRead(Oldto, ""); + //AuthorizationRules.AllowWrite(Oldto, ""); + _ZTransitionExtension.AddAuthorizationRules(AuthorizationRules); + } + protected override void AddInstanceAuthorizationRules() + { + //TODO: Who can read/write which fields + _ZTransitionExtension.AddInstanceAuthorizationRules(AuthorizationRules); + } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + public int CurrentEditLevel + { get { return EditLevel; } } + private static int _ZTransitionUnique = 0; + protected static int ZTransitionUnique + { get { return ++_ZTransitionUnique; } } + private int _MyZTransitionUnique = ZTransitionUnique; + public int MyZTransitionUnique + { get { return _MyZTransitionUnique; } } + protected ZTransition() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromDictionaries(); + } + private void RemoveFromDictionaries() + { + RemoveFromCache(this); + if (_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) + { + List listZTransition = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listZTransition.Contains(this)) listZTransition.Remove(this); // Remove the item from the list + if (listZTransition.Count == 0) //If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + } + public static ZTransition New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZTransition"); + try + { + return DataPortal.Create(); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.New", ex); + } + } + public static ZTransition New(Transition myTransition, string oldto) + { + ZTransition tmp = ZTransition.New(); + tmp._MyTransition = myTransition; + tmp.Oldto = oldto; + return tmp; + } + public static ZTransition MakeZTransition(Transition myTransition, string oldto) + { + ZTransition tmp = ZTransition.New(myTransition, oldto); + if (tmp.IsSavable) + { + ZTransition tmp2 = tmp; + tmp = tmp2.Save(); + tmp2.Dispose(); + } + else + { + Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules(); + tmp._ErrorMessage = "Failed Validation:"; + foreach (Csla.Validation.BrokenRule br in brc) + { + tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName; + } + } + return tmp; + } + public static ZTransition New(Transition myTransition) + { + ZTransition tmp = ZTransition.New(); + tmp._MyTransition = myTransition; + tmp.MarkClean(); + tmp.MarkAsChild(); + return tmp; + } + public static ZTransition Get(int transitionID) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a ZTransition"); + try + { + ZTransition tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZTransition + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.Get", ex); + } + } + public static ZTransition Get(SafeDataReader dr) + { + if (dr.Read()) return new ZTransition(dr); + return null; + } + internal ZTransition(SafeDataReader dr) + { + ReadData(dr); + } + public static void Delete(int transitionID) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); + try + { + DataPortal.Delete(new PKCriteria(transitionID)); + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.Delete", ex); + } + } + public override ZTransition Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a ZTransition"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a ZTransition"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a ZTransition"); + try + { + BuildRefreshList(); + ZTransition zTransition = base.Save(); + RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache + AddToCache(zTransition);//Refresh the item in AllList + ProcessRefreshList(); + return zTransition; + } + catch (Exception ex) + { + throw new DbCslaException("Error on CSLA Save", ex); + } + } + #endregion + #region Data Access Portal + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + // TODO: If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create() + { - // Database Defaults + // Database Defaults - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _Oldto = dr.GetString("oldto"); - dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); - MarkOld(); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.DataPortal_Fetch", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLInsert(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Insert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.DataPortal_Insert", ex); - } - finally - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Insert", GetHashCode()); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - internal void SQLInsert() - { - if (!this.IsDirty) return; - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addZTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", TransitionID); - cm.Parameters.AddWithValue("@Oldto", _Oldto); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: 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}] ZTransition.SQLInsert", GetHashCode()); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLInsert", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.SQLInsert", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, Transition myTransition, string oldto) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Add", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addZTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", myTransition.TransitionID); - cm.Parameters.AddWithValue("@Oldto", oldto); - // Output Calculated Columns - SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); - param_LastChanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_LastChanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Add", ex); - throw new DbCslaException("ZTransition.Add", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (!IsDirty) return; // If not dirty - nothing to do - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Update", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - SQLUpdate(); - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Update", ex); - _ErrorMessage = ex.Message; - 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}] ZTransition.SQLUpdate", GetHashCode()); - try - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateZTransition"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@TransitionID", TransitionID); - cm.Parameters.AddWithValue("@Oldto", _Oldto); - 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); - // TODO: 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 - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLUpdate", ex); - _ErrorMessage = ex.Message; - if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; - } - } - internal void Update(Transition transition) - { - if (!this.IsDirty) return; - if (base.IsDirty) - { - SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; - if (IsNew) - _LastChanged = ZTransition.Add(cn, transition, _Oldto); - else - _LastChanged = ZTransition.Update(cn, transition, _Oldto, ref _LastChanged); - MarkOld(); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, Transition myTransition, string oldto, ref byte[] lastChanged) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Update", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateZTransition"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@TransitionID", myTransition.TransitionID); - cm.Parameters.AddWithValue("@Oldto", oldto); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Update", ex); - throw new DbCslaException("ZTransition.Update", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_TransitionID)); - } - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Delete", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteZTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - cm.ExecuteNonQuery(); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Delete", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransition.DataPortal_Delete", ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn, int transitionID) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Remove", 0); - try - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteZTransition"; - // Input PK Fields - cm.Parameters.AddWithValue("@TransitionID", transitionID); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Remove", ex); - throw new DbCslaException("ZTransition.Remove", ex); - } - } - #endregion - #region Exists - public static bool Exists(int transitionID) - { - ExistsCommand result; - try - { - result = DataPortal.Execute(new ExistsCommand(transitionID)); - return result.Exists; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransition.Exists", ex); - } - } - [Serializable()] - private class ExistsCommand : CommandBase - { - private int _TransitionID; - private bool _exists; - public bool Exists - { - get { return _exists; } - } - public ExistsCommand(int transitionID) - { - _TransitionID = transitionID; - } - protected override void DataPortal_Execute() - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Execute", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsZTransition"; - cm.Parameters.AddWithValue("@TransitionID", _TransitionID); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Execute", ex); - throw new DbCslaException("ZTransition.DataPortal_Execute", ex); - } - } - } - #endregion - // Standard Default Code - #region extension - ZTransitionExtension _ZTransitionExtension = new ZTransitionExtension(); - [Serializable()] - partial class ZTransitionExtension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Instance Authorization Rules - public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - // InstanceValidation Rules - public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - #endregion - } // Class - #region Converter - internal class ZTransitionConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZTransition) - { - // Return the ToString value - return ((ZTransition)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _Oldto = dr.GetString("oldto"); + dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8); + MarkOld(); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.DataPortal_Fetch", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLInsert(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Insert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.DataPortal_Insert", ex); + } + finally + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Insert", GetHashCode()); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + internal void SQLInsert() + { + if (!this.IsDirty) return; + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addZTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", TransitionID); + cm.Parameters.AddWithValue("@Oldto", _Oldto); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: 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}] ZTransition.SQLInsert", GetHashCode()); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLInsert", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.SQLInsert", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, Transition myTransition, string oldto) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Add", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addZTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", myTransition.TransitionID); + cm.Parameters.AddWithValue("@Oldto", oldto); + // Output Calculated Columns + SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_LastChanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_LastChanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Add", ex); + throw new DbCslaException("ZTransition.Add", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (!IsDirty) return; // If not dirty - nothing to do + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Update", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + SQLUpdate(); + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Update", ex); + _ErrorMessage = ex.Message; + 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}] ZTransition.SQLUpdate", GetHashCode()); + try + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateZTransition"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@TransitionID", TransitionID); + cm.Parameters.AddWithValue("@Oldto", _Oldto); + 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); + // TODO: 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 + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.SQLUpdate", ex); + _ErrorMessage = ex.Message; + if (!ex.Message.EndsWith("has been edited by another user.")) throw ex; + } + } + internal void Update(Transition transition) + { + if (!this.IsDirty) return; + if (base.IsDirty) + { + SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; + if (IsNew) + _LastChanged = ZTransition.Add(cn, transition, _Oldto); + else + _LastChanged = ZTransition.Update(cn, transition, _Oldto, ref _LastChanged); + MarkOld(); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, Transition myTransition, string oldto, ref byte[] lastChanged) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Update", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateZTransition"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@TransitionID", myTransition.TransitionID); + cm.Parameters.AddWithValue("@Oldto", oldto); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Update", ex); + throw new DbCslaException("ZTransition.Update", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_TransitionID)); + } + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Delete", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteZTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Delete", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransition.DataPortal_Delete", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int transitionID) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.Remove", 0); + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteZTransition"; + // Input PK Fields + cm.Parameters.AddWithValue("@TransitionID", transitionID); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.Remove", ex); + throw new DbCslaException("ZTransition.Remove", ex); + } + } + #endregion + #region Exists + public static bool Exists(int transitionID) + { + ExistsCommand result; + try + { + result = DataPortal.Execute(new ExistsCommand(transitionID)); + return result.Exists; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransition.Exists", ex); + } + } + [Serializable()] + private class ExistsCommand : CommandBase + { + private int _TransitionID; + private bool _exists; + public bool Exists + { + get { return _exists; } + } + public ExistsCommand(int transitionID) + { + _TransitionID = transitionID; + } + protected override void DataPortal_Execute() + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransition.DataPortal_Execute", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsZTransition"; + cm.Parameters.AddWithValue("@TransitionID", _TransitionID); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransition.DataPortal_Execute", ex); + throw new DbCslaException("ZTransition.DataPortal_Execute", ex); + } + } + } + #endregion + // Standard Default Code + #region extension + ZTransitionExtension _ZTransitionExtension = new ZTransitionExtension(); + [Serializable()] + partial class ZTransitionExtension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Instance Authorization Rules + public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + // InstanceValidation Rules + public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + #endregion + } // Class + #region Converter + internal class ZTransitionConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZTransition) + { + // Return the ToString value + return ((ZTransition)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransitionInfo.cs b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransitionInfo.cs index 11a94d96..e00436b6 100644 --- a/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransitionInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/OldGenerated/ZTransitionInfo.cs @@ -19,295 +19,292 @@ using System.ComponentModel; using System.Collections.Generic; namespace VEPROMS.CSLA.Library { - public delegate void ZTransitionInfoEvent(object sender); - /// - /// ZTransitionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - [TypeConverter(typeof(ZTransitionInfoConverter))] - public partial class ZTransitionInfo : ReadOnlyBase, IDisposable - { - public event ZTransitionInfoEvent Changed; - private void OnChange() - { - if (Changed != null) Changed(this); - } - #region Log4Net - private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - #endregion - #region Collection - private static List _CacheList = new List(); - protected static void AddToCache(ZTransitionInfo zTransitionInfo) - { - if (!_CacheList.Contains(zTransitionInfo)) _CacheList.Add(zTransitionInfo); // In AddToCache - } - protected static void RemoveFromCache(ZTransitionInfo zTransitionInfo) - { - while (_CacheList.Contains(zTransitionInfo)) _CacheList.Remove(zTransitionInfo); // In RemoveFromCache - } - private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); - private static void ConvertListToDictionary() - { - List remove = new List(); - foreach (ZTransitionInfo tmp in _CacheList) - { - if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) - { - _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey - } - _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list - remove.Add(tmp); - } - foreach (ZTransitionInfo tmp in remove) - RemoveFromCache(tmp); - } - protected static ZTransitionInfo GetCachedByPrimaryKey(int transitionID) - { - ConvertListToDictionary(); - string key = transitionID.ToString(); - if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; - return null; - } - #endregion - #region Business Methods - private string _ErrorMessage = string.Empty; - public string ErrorMessage - { - get { return _ErrorMessage; } - } - protected ZTransition _Editable; - private IVEHasBrokenRules HasBrokenRules - { - get - { - IVEHasBrokenRules hasBrokenRules = null; - if (_Editable != null) - hasBrokenRules = _Editable.HasBrokenRules; - return hasBrokenRules; - } - } - private int _TransitionID; - [System.ComponentModel.DataObjectField(true, true)] - public int TransitionID - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("TransitionID", true); - if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; - return _TransitionID; - } - } - private TransitionInfo _MyTransition; - [System.ComponentModel.DataObjectField(true, true)] - public TransitionInfo MyTransition - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("MyTransition", true); - if (_MyTransition == null && _TransitionID != 0) _MyTransition = TransitionInfo.Get(_TransitionID); - return _MyTransition; - } - } - private string _Oldto = string.Empty; - public string Oldto - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty("Oldto", true); - return _Oldto; - } - } - // TODO: Replace base ZTransitionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ZTransitionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - // TODO: Check ZTransitionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ZTransitionInfo - protected override object GetIdValue() - { - return _TransitionID; - } - #endregion - #region Factory Methods - private static int _ZTransitionInfoUnique = 0; - private static int ZTransitionInfoUnique - { get { return ++_ZTransitionInfoUnique; } } - private int _MyZTransitionInfoUnique = ZTransitionInfoUnique; - public int MyZTransitionInfoUnique - { get { return _MyZTransitionInfoUnique; } } - protected ZTransitionInfo() - {/* require use of factory methods */ - AddToCache(this); - } - public void Dispose() - { - RemoveFromCache(this); - if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; - List listZTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items - while (listZTransitionInfo.Contains(this)) listZTransitionInfo.Remove(this); // Remove the item from the list - if (listZTransitionInfo.Count == 0) // If there are no items left in the list - _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list - } - public virtual ZTransition Get() - { - return _Editable = ZTransition.Get(_TransitionID); - } - public static void Refresh(ZTransition tmp) - { - string key = tmp.TransitionID.ToString(); - ConvertListToDictionary(); - if (_CacheByPrimaryKey.ContainsKey(key)) - foreach (ZTransitionInfo tmpInfo in _CacheByPrimaryKey[key]) - tmpInfo.RefreshFields(tmp); - } - protected virtual void RefreshFields(ZTransition tmp) - { - _Oldto = tmp.Oldto; - _ZTransitionInfoExtension.Refresh(this); - if(_MyTransition != null) - { - _MyTransition.Dispose();// Dispose related value - _MyTransition = null;// Reset related value - } - OnChange();// raise an event - } - public static ZTransitionInfo Get(int transitionID) - { - //if (!CanGetObject()) - // throw new System.Security.SecurityException("User not authorized to view a ZTransition"); - try - { - ZTransitionInfo tmp = GetCachedByPrimaryKey(transitionID); - if (tmp == null) - { - tmp = DataPortal.Fetch(new PKCriteria(transitionID)); - AddToCache(tmp); - } - if (tmp.ErrorMessage == "No Record Found") - { - tmp.Dispose(); // Clean-up ZTransitionInfo - tmp = null; - } - return tmp; - } - catch (Exception ex) - { - throw new DbCslaException("Error on ZTransitionInfo.Get", ex); - } - } - #endregion - #region Data Access Portal - internal ZTransitionInfo(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode()); - try - { - ReadData(dr); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.Constructor", ex); - throw new DbCslaException("ZTransitionInfo.Constructor", ex); - } - } - [Serializable()] - protected class PKCriteria - { - private int _TransitionID; - public int TransitionID - { get { return _TransitionID; } } - public PKCriteria(int transitionID) - { - _TransitionID = transitionID; - } - } - private void ReadData(SafeDataReader dr) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.ReadData", GetHashCode()); - try - { - _TransitionID = dr.GetInt32("TransitionID"); - _Oldto = dr.GetString("oldto"); - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.ReadData", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransitionInfo.ReadData", ex); - } - } - private void DataPortal_Fetch(PKCriteria criteria) - { - if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.DataPortal_Fetch", GetHashCode()); - try - { - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - ApplicationContext.LocalContext["cn"] = cn; - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getZTransition"; - cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - if (!dr.Read()) - { - _ErrorMessage = "No Record Found"; - return; - } - ReadData(dr); - } - } - // removing of item only needed for local data portal - if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) - ApplicationContext.LocalContext.Remove("cn"); - } - } - catch (Exception ex) - { - if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.DataPortal_Fetch", ex); - _ErrorMessage = ex.Message; - throw new DbCslaException("ZTransitionInfo.DataPortal_Fetch", ex); - } - } - #endregion - // Standard Refresh - #region extension - ZTransitionInfoExtension _ZTransitionInfoExtension = new ZTransitionInfoExtension(); - [Serializable()] - partial class ZTransitionInfoExtension : extensionBase { } - [Serializable()] - class extensionBase - { - // Default Refresh - public virtual void Refresh(ZTransitionInfo tmp) { } - } - #endregion - } // Class - #region Converter - internal class ZTransitionInfoConverter : ExpandableObjectConverter - { - public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) - { - if (destType == typeof(string) && value is ZTransitionInfo) - { - // Return the ToString value - return ((ZTransitionInfo)value).ToString(); - } - return base.ConvertTo(context, culture, value, destType); - } - } - #endregion + public delegate void ZTransitionInfoEvent(object sender); + /// + /// ZTransitionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + [TypeConverter(typeof(ZTransitionInfoConverter))] + public partial class ZTransitionInfo : ReadOnlyBase, IDisposable + { + public event ZTransitionInfoEvent Changed; + private void OnChange() + { + if (Changed != null) Changed(this); + } + #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion + #region Collection + private static List _CacheList = new List(); + protected static void AddToCache(ZTransitionInfo zTransitionInfo) + { + if (!_CacheList.Contains(zTransitionInfo)) _CacheList.Add(zTransitionInfo); // In AddToCache + } + protected static void RemoveFromCache(ZTransitionInfo zTransitionInfo) + { + while (_CacheList.Contains(zTransitionInfo)) _CacheList.Remove(zTransitionInfo); // In RemoveFromCache + } + private static Dictionary> _CacheByPrimaryKey = new Dictionary>(); + private static void ConvertListToDictionary() + { + List remove = new List(); + foreach (ZTransitionInfo tmp in _CacheList) + { + if (!_CacheByPrimaryKey.ContainsKey(tmp.TransitionID.ToString())) + { + _CacheByPrimaryKey[tmp.TransitionID.ToString()] = new List(); // Add new list for PrimaryKey + } + _CacheByPrimaryKey[tmp.TransitionID.ToString()].Add(tmp); // Add to Primary Key list + remove.Add(tmp); + } + foreach (ZTransitionInfo tmp in remove) + RemoveFromCache(tmp); + } + protected static ZTransitionInfo GetCachedByPrimaryKey(int transitionID) + { + ConvertListToDictionary(); + string key = transitionID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0]; + return null; + } + #endregion + #region Business Methods + private string _ErrorMessage = string.Empty; + public string ErrorMessage + { + get { return _ErrorMessage; } + } + protected ZTransition _Editable; + private IVEHasBrokenRules HasBrokenRules + { + get + { + IVEHasBrokenRules hasBrokenRules = null; + if (_Editable != null) + hasBrokenRules = _Editable.HasBrokenRules; + return hasBrokenRules; + } + } + private int _TransitionID; + [System.ComponentModel.DataObjectField(true, true)] + public int TransitionID + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition != null) _TransitionID = _MyTransition.TransitionID; + return _TransitionID; + } + } + private TransitionInfo _MyTransition; + [System.ComponentModel.DataObjectField(true, true)] + public TransitionInfo MyTransition + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + if (_MyTransition == null && _TransitionID != 0) _MyTransition = TransitionInfo.Get(_TransitionID); + return _MyTransition; + } + } + private string _Oldto = string.Empty; + public string Oldto + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _Oldto; + } + } + // TODO: Replace base ZTransitionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ZTransitionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + // TODO: Check ZTransitionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ZTransitionInfo + protected override object GetIdValue() + { + return _TransitionID; + } + #endregion + #region Factory Methods + private static int _ZTransitionInfoUnique = 0; + private static int ZTransitionInfoUnique + { get { return ++_ZTransitionInfoUnique; } } + private int _MyZTransitionInfoUnique = ZTransitionInfoUnique; + public int MyZTransitionInfoUnique + { get { return _MyZTransitionInfoUnique; } } + protected ZTransitionInfo() + {/* require use of factory methods */ + AddToCache(this); + } + public void Dispose() + { + RemoveFromCache(this); + if (!_CacheByPrimaryKey.ContainsKey(TransitionID.ToString())) return; + List listZTransitionInfo = _CacheByPrimaryKey[TransitionID.ToString()]; // Get the list of items + while (listZTransitionInfo.Contains(this)) listZTransitionInfo.Remove(this); // Remove the item from the list + if (listZTransitionInfo.Count == 0) // If there are no items left in the list + _CacheByPrimaryKey.Remove(TransitionID.ToString()); // remove the list + } + public virtual ZTransition Get() + { + return _Editable = ZTransition.Get(_TransitionID); + } + public static void Refresh(ZTransition tmp) + { + string key = tmp.TransitionID.ToString(); + ConvertListToDictionary(); + if (_CacheByPrimaryKey.ContainsKey(key)) + foreach (ZTransitionInfo tmpInfo in _CacheByPrimaryKey[key]) + tmpInfo.RefreshFields(tmp); + } + protected virtual void RefreshFields(ZTransition tmp) + { + _Oldto = tmp.Oldto; + _ZTransitionInfoExtension.Refresh(this); + if (_MyTransition != null) + { + _MyTransition.Dispose();// Dispose related value + _MyTransition = null;// Reset related value + } + OnChange();// raise an event + } + public static ZTransitionInfo Get(int transitionID) + { + //if (!CanGetObject()) + // throw new System.Security.SecurityException("User not authorized to view a ZTransition"); + try + { + ZTransitionInfo tmp = GetCachedByPrimaryKey(transitionID); + if (tmp == null) + { + tmp = DataPortal.Fetch(new PKCriteria(transitionID)); + AddToCache(tmp); + } + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up ZTransitionInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ZTransitionInfo.Get", ex); + } + } + #endregion + #region Data Access Portal + internal ZTransitionInfo(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.Constructor", GetHashCode()); + try + { + ReadData(dr); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.Constructor", ex); + throw new DbCslaException("ZTransitionInfo.Constructor", ex); + } + } + [Serializable()] + protected class PKCriteria + { + private int _TransitionID; + public int TransitionID + { get { return _TransitionID; } } + public PKCriteria(int transitionID) + { + _TransitionID = transitionID; + } + } + private void ReadData(SafeDataReader dr) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.ReadData", GetHashCode()); + try + { + _TransitionID = dr.GetInt32("TransitionID"); + _Oldto = dr.GetString("oldto"); + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.ReadData", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransitionInfo.ReadData", ex); + } + } + private void DataPortal_Fetch(PKCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ZTransitionInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getZTransition"; + cm.Parameters.AddWithValue("@TransitionID", criteria.TransitionID); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ZTransitionInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("ZTransitionInfo.DataPortal_Fetch", ex); + } + } + #endregion + // Standard Refresh + #region extension + ZTransitionInfoExtension _ZTransitionInfoExtension = new ZTransitionInfoExtension(); + [Serializable()] + partial class ZTransitionInfoExtension : extensionBase { } + [Serializable()] + class extensionBase + { + // Default Refresh + public virtual void Refresh(ZTransitionInfo tmp) { } + } + #endregion + } // Class + #region Converter + internal class ZTransitionInfoConverter : ExpandableObjectConverter + { + public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) + { + if (destType == typeof(string) && value is ZTransitionInfo) + { + // Return the ToString value + return ((ZTransitionInfo)value).ToString(); + } + return base.ConvertTo(context, culture, value, destType); + } + } + #endregion } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/Assignment.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/Assignment.cs index 1695cd2f..dbbdaf46 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/Assignment.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/Assignment.cs @@ -17,754 +17,748 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// Assignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class Assignment : BusinessBase - { - #region Business Methods - - private int _aid; - [System.ComponentModel.DataObjectField(true, true)] - public int Aid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _aid; - } - } - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_gid != value) - { - _gid = value; - PropertyHasChanged(); - } - } - } - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_rid != value) - { - _rid = value; - PropertyHasChanged(); - } - } - } - private int _folderid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folderid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_folderid != value) - { - _folderid = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - // TODO: Replace base Assignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Assignment - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check Assignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Assignment - protected override object GetIdValue() - { - return _aid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Aid, ""); - //AuthorizationRules.AllowRead(Gid, ""); - //AuthorizationRules.AllowRead(Rid, ""); - //AuthorizationRules.AllowRead(Folderid, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Gid, ""); - //AuthorizationRules.AllowWrite(Rid, ""); - //AuthorizationRules.AllowWrite(Folderid, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private Assignment() - {/* require use of factory methods */} - - public static Assignment New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Assignment"); - return DataPortal.Create(); - } - - public static Assignment Get(int _aid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Assignment"); - return DataPortal.Fetch(new PKCriteria(_aid)); - } - - public static void Delete(int _aid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Assignment"); - DataPortal.Delete(new PKCriteria(_aid)); - } - - public override Assignment Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Assignment"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Assignment"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Assignment"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _aid; - public int Aid - { get {return _aid;}} - public PKCriteria(int aid) - { - _aid=aid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getAssignment"; - cm.Parameters.AddWithValue("@aID", criteria.Aid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _aid = dr.GetInt32("AID"); - _gid = dr.GetInt32("GID"); - _rid = dr.GetInt32("RID"); - _folderid = dr.GetInt32("FolderID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - } - } - } - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAssignment"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@gID", _gid); - cm.Parameters.AddWithValue("@rID", _rid); - cm.Parameters.AddWithValue("@folderID", _folderid); - cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); - cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); - cm.Parameters.AddWithValue("@dTS", _dts); - cm.Parameters.AddWithValue("@usrID", _usrid); - // Output Calculated Columns - SqlParameter param_aid = new SqlParameter("@newAID",SqlDbType.Int); - param_aid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_aid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _aid = (int)cm.Parameters["@newAID"].Value; - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - // update child objects - } - - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - }} - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn,ref int aid, int gid, int rid, int folderid, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addAssignment"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@gID", gid); - cm.Parameters.AddWithValue("@rID", rid); - cm.Parameters.AddWithValue("@folderID", folderid); - cm.Parameters.AddWithValue("@startDate", startdate.DBValue); - cm.Parameters.AddWithValue("@endDate", enddate.DBValue); - cm.Parameters.AddWithValue("@dTS", dts); - cm.Parameters.AddWithValue("@usrID", usrid); - // Output Calculated Columns - SqlParameter param_aid = new SqlParameter("@newAID",SqlDbType.Int); - param_aid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_aid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - aid = (int)cm.Parameters["@newAID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAssignment"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@aID", _aid); - cm.Parameters.AddWithValue("@gID", _gid); - cm.Parameters.AddWithValue("@rID", _rid); - cm.Parameters.AddWithValue("@folderID", _folderid); - cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); - cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - } - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - } - - } - } - - - [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) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateAssignment"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@aID", aid); - cm.Parameters.AddWithValue("@gID", gid); - cm.Parameters.AddWithValue("@rID", rid); - cm.Parameters.AddWithValue("@folderID", folderid); - cm.Parameters.AddWithValue("@startDate", startdate.DBValue); - cm.Parameters.AddWithValue("@endDate", enddate.DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_aid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAssignment"; - cm.Parameters.AddWithValue("@aID", criteria.Aid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int aid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteAssignment"; - // Input PK Fields - - cm.Parameters.AddWithValue("@aID", aid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int aid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(aid)); - return result.Exists; - } - + /// + /// Assignment Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class Assignment : BusinessBase { + #region Business Methods - private int _aid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int aid) - { - _aid=aid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _aid; + [System.ComponentModel.DataObjectField(true, true)] + public int Aid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsAssignment"; - - cm.Parameters.AddWithValue("@aID", _aid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _aid; + } } - } - catch(Exception ex) - { - Database.LogException("Assignment",ex); - } - } - } + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_gid != value) + { + _gid = value; + PropertyHasChanged(); + } + } + } + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_rid != value) + { + _rid = value; + PropertyHasChanged(); + } + } + } + private int _folderid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folderid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_folderid != value) + { + _folderid = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + // TODO: Replace base Assignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Assignment + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check Assignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Assignment + protected override object GetIdValue() + { + return _aid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create AssignmentExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class Assignment -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Aid, ""); + //AuthorizationRules.AllowRead(Gid, ""); + //AuthorizationRules.AllowRead(Rid, ""); + //AuthorizationRules.AllowRead(Folderid, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Gid, ""); + //AuthorizationRules.AllowWrite(Rid, ""); + //AuthorizationRules.AllowWrite(Folderid, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private Assignment() + {/* require use of factory methods */} + + public static Assignment New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Assignment"); + return DataPortal.Create(); + } + + public static Assignment Get(int _aid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Assignment"); + return DataPortal.Fetch(new PKCriteria(_aid)); + } + + public static void Delete(int _aid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Assignment"); + DataPortal.Delete(new PKCriteria(_aid)); + } + + public override Assignment Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Assignment"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Assignment"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Assignment"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _aid; + public int Aid + { get { return _aid; } } + public PKCriteria(int aid) + { + _aid = aid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getAssignment"; + cm.Parameters.AddWithValue("@aID", criteria.Aid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _aid = dr.GetInt32("AID"); + _gid = dr.GetInt32("GID"); + _rid = dr.GetInt32("RID"); + _folderid = dr.GetInt32("FolderID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + } + } + } + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAssignment"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@gID", _gid); + cm.Parameters.AddWithValue("@rID", _rid); + cm.Parameters.AddWithValue("@folderID", _folderid); + cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); + cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); + cm.Parameters.AddWithValue("@dTS", _dts); + cm.Parameters.AddWithValue("@usrID", _usrid); + // Output Calculated Columns + SqlParameter param_aid = new SqlParameter("@newAID", SqlDbType.Int); + param_aid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_aid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _aid = (int)cm.Parameters["@newAID"].Value; + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + // update child objects + } + + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int aid, int gid, int rid, int folderid, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addAssignment"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@gID", gid); + cm.Parameters.AddWithValue("@rID", rid); + cm.Parameters.AddWithValue("@folderID", folderid); + cm.Parameters.AddWithValue("@startDate", startdate.DBValue); + cm.Parameters.AddWithValue("@endDate", enddate.DBValue); + cm.Parameters.AddWithValue("@dTS", dts); + cm.Parameters.AddWithValue("@usrID", usrid); + // Output Calculated Columns + SqlParameter param_aid = new SqlParameter("@newAID", SqlDbType.Int); + param_aid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_aid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + aid = (int)cm.Parameters["@newAID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAssignment"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@aID", _aid); + cm.Parameters.AddWithValue("@gID", _gid); + cm.Parameters.AddWithValue("@rID", _rid); + cm.Parameters.AddWithValue("@folderID", _folderid); + cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); + cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + } + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + } + + } + } + + + [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) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateAssignment"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@aID", aid); + cm.Parameters.AddWithValue("@gID", gid); + cm.Parameters.AddWithValue("@rID", rid); + cm.Parameters.AddWithValue("@folderID", folderid); + cm.Parameters.AddWithValue("@startDate", startdate.DBValue); + cm.Parameters.AddWithValue("@endDate", enddate.DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_aid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAssignment"; + cm.Parameters.AddWithValue("@aID", criteria.Aid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int aid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteAssignment"; + // Input PK Fields + + cm.Parameters.AddWithValue("@aID", aid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int aid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(aid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _aid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int aid) + { + _aid = aid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsAssignment"; + + cm.Parameters.AddWithValue("@aID", _aid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("Assignment", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create AssignmentExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class Assignment + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/AssignmentInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/AssignmentInfo.cs index d510784e..aff78fa9 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/AssignmentInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/AssignmentInfo.cs @@ -17,151 +17,143 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// AssignmentInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class AssignmentInfo : ReadOnlyBase - { - #region Business Methods - - - private int _aid; - [System.ComponentModel.DataObjectField(true, true)] - public int Aid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _aid; - } - } - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - } - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - } - private int _folderid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folderid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderid; - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base AssignmentInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current AssignmentInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check AssignmentInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current AssignmentInfo - protected override object GetIdValue() - { - return _aid; - } - - - #endregion - #region Factory Methods - private AssignmentInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal AssignmentInfo(SafeDataReader dr) + /// + /// AssignmentInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class AssignmentInfo : ReadOnlyBase { - try - { - _aid = dr.GetInt32("AID"); - _gid = dr.GetInt32("GID"); - _rid = dr.GetInt32("RID"); - _folderid = dr.GetInt32("FolderID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("AssignmentInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _aid; + [System.ComponentModel.DataObjectField(true, true)] + public int Aid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _aid; + } + } + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + } + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + } + private int _folderid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folderid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderid; + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base AssignmentInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current AssignmentInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check AssignmentInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current AssignmentInfo + protected override object GetIdValue() + { + return _aid; + } + + + #endregion + #region Factory Methods + private AssignmentInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal AssignmentInfo(SafeDataReader dr) + { + try + { + _aid = dr.GetInt32("AID"); + _gid = dr.GetInt32("GID"); + _rid = dr.GetInt32("RID"); + _folderid = dr.GetInt32("FolderID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("AssignmentInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/Connection.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/Connection.cs index 4e892e6d..992d4cda 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/Connection.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/Connection.cs @@ -17,755 +17,748 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// Connection Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class Connection : BusinessBase - { - #region Business Methods - - private int _dbid; - [System.ComponentModel.DataObjectField(true, true)] - public int Dbid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dbid; - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_name != value) - { - _name = value; - PropertyHasChanged(); - } - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_title != value) - { - _title = value; - PropertyHasChanged(); - } - } - } - private string _connectionstring=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _connectionstring; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_connectionstring != value) - { - _connectionstring = value; - PropertyHasChanged(); - } - } - } - private int _servertype; - /// - /// 0 SQL Server - /// - [System.ComponentModel.DataObjectField(true, true)] - public int ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _servertype; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_servertype != value) - { - _servertype = value; - PropertyHasChanged(); - } - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_config != value) - { - _config = value; - PropertyHasChanged(); - } - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private ConnectionFolders _connectionfolders = ConnectionFolders.New(); - /// - /// Related Field - /// - [System.ComponentModel.DataObjectField(true, true)] - public ConnectionFolders ConnectionFolders - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _connectionfolders; - } - } - public override bool IsDirty - { - get { return base.IsDirty || _connectionfolders.IsDirty ; } - } - public override bool IsValid - { - get { return base.IsValid && _connectionfolders.IsValid ; } - } - // TODO: Replace base Connection.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Connection - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check Connection.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Connection - protected override object GetIdValue() - { - return _dbid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConnectionString", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - // 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Dbid, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(ConnectionString, ""); - //AuthorizationRules.AllowRead(ServerType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(ConnectionString, ""); - //AuthorizationRules.AllowWrite(ServerType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private Connection() - {/* require use of factory methods */} - - public static Connection New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Connection"); - return DataPortal.Create(); - } - - public static Connection Get(int _dbid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Connection"); - return DataPortal.Fetch(new PKCriteria(_dbid)); - } - - public static void Delete(int _dbid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Connection"); - DataPortal.Delete(new PKCriteria(_dbid)); - } - - public override Connection Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Connection"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Connection"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Connection"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _dbid; - public int Dbid - { get {return _dbid;}} - public PKCriteria(int dbid) - { - _dbid=dbid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _servertype = ext.DefaultServerType; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getConnection"; - cm.Parameters.AddWithValue("@dBID", criteria.Dbid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _dbid = dr.GetInt32("DBID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _connectionstring = dr.GetString("ConnectionString"); - _servertype = dr.GetInt32("ServerType"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - // load child objects - dr.NextResult(); - _connectionfolders = ConnectionFolders.Get(dr); - - } - } - } - } - catch(Exception ex) - { - Database.LogException("Connection",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addConnection"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@name", _name); - cm.Parameters.AddWithValue("@title", _title); - cm.Parameters.AddWithValue("@connectionString", _connectionstring); - cm.Parameters.AddWithValue("@serverType", _servertype); - cm.Parameters.AddWithValue("@config", _config); - cm.Parameters.AddWithValue("@dTS", _dts); - cm.Parameters.AddWithValue("@usrID", _usrid); - // Output Calculated Columns - SqlParameter param_dbid = new SqlParameter("@newDBID",SqlDbType.Int); - param_dbid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_dbid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _dbid = (int)cm.Parameters["@newDBID"].Value; - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - // update child objects - _connectionfolders.Update(this,cn); - - } - - } - catch(Exception ex) - { - Database.LogException("Connection",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) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addConnection"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@name", name); - cm.Parameters.AddWithValue("@title", title); - cm.Parameters.AddWithValue("@connectionString", connectionstring); - cm.Parameters.AddWithValue("@serverType", servertype); - cm.Parameters.AddWithValue("@config", config); - cm.Parameters.AddWithValue("@dTS", dts); - cm.Parameters.AddWithValue("@usrID", usrid); - // Output Calculated Columns - SqlParameter param_dbid = new SqlParameter("@newDBID",SqlDbType.Int); - param_dbid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_dbid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - dbid = (int)cm.Parameters["@newDBID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Connection",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateConnection"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@dBID", _dbid); - cm.Parameters.AddWithValue("@name", _name); - cm.Parameters.AddWithValue("@title", _title); - cm.Parameters.AddWithValue("@connectionString", _connectionstring); - cm.Parameters.AddWithValue("@serverType", _servertype); - cm.Parameters.AddWithValue("@config", _config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - _connectionfolders.Update(this,cn); - - } - } - catch(Exception ex) - { - Database.LogException("Connection",ex); - } - - } - } - - - [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) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateConnection"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@dBID", dbid); - cm.Parameters.AddWithValue("@name", name); - cm.Parameters.AddWithValue("@title", title); - cm.Parameters.AddWithValue("@connectionString", connectionstring); - cm.Parameters.AddWithValue("@serverType", servertype); - cm.Parameters.AddWithValue("@config", config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Connection",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_dbid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteConnection"; - cm.Parameters.AddWithValue("@dBID", criteria.Dbid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("Connection",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int dbid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteConnection"; - // Input PK Fields - - cm.Parameters.AddWithValue("@dBID", dbid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("Connection",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int dbid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(dbid)); - return result.Exists; - } - + /// + /// Connection Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class Connection : BusinessBase { + #region Business Methods - private int _dbid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int dbid) - { - _dbid=dbid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _dbid; + [System.ComponentModel.DataObjectField(true, true)] + public int Dbid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsConnection"; - - cm.Parameters.AddWithValue("@dBID", _dbid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dbid; + } } - } - catch(Exception ex) - { - Database.LogException("Connection",ex); - } - } - } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_name != value) + { + _name = value; + PropertyHasChanged(); + } + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_title != value) + { + _title = value; + PropertyHasChanged(); + } + } + } + private string _connectionstring = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _connectionstring; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_connectionstring != value) + { + _connectionstring = value; + PropertyHasChanged(); + } + } + } + private int _servertype; + /// + /// 0 SQL Server + /// + [System.ComponentModel.DataObjectField(true, true)] + public int ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _servertype; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_servertype != value) + { + _servertype = value; + PropertyHasChanged(); + } + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_config != value) + { + _config = value; + PropertyHasChanged(); + } + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private ConnectionFolders _connectionfolders = ConnectionFolders.New(); + /// + /// Related Field + /// + [System.ComponentModel.DataObjectField(true, true)] + public ConnectionFolders ConnectionFolders + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _connectionfolders; + } + } + public override bool IsDirty + { + get { return base.IsDirty || _connectionfolders.IsDirty; } + } + public override bool IsValid + { + get { return base.IsValid && _connectionfolders.IsValid; } + } + // TODO: Replace base Connection.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Connection + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check Connection.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Connection + protected override object GetIdValue() + { + return _dbid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultServerType - { - get { return 1; } - } - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create ConnectionExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class Connection -// { -// partial class Extension : extensionBase -// { -// TODO: Override automatic defaults -// public virtual int DefaultServerType -// { -// 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConnectionString", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + // 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Dbid, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(ConnectionString, ""); + //AuthorizationRules.AllowRead(ServerType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(ConnectionString, ""); + //AuthorizationRules.AllowWrite(ServerType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private Connection() + {/* require use of factory methods */} + + public static Connection New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Connection"); + return DataPortal.Create(); + } + + public static Connection Get(int _dbid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Connection"); + return DataPortal.Fetch(new PKCriteria(_dbid)); + } + + public static void Delete(int _dbid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Connection"); + DataPortal.Delete(new PKCriteria(_dbid)); + } + + public override Connection Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Connection"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Connection"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Connection"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _dbid; + public int Dbid + { get { return _dbid; } } + public PKCriteria(int dbid) + { + _dbid = dbid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _servertype = ext.DefaultServerType; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getConnection"; + cm.Parameters.AddWithValue("@dBID", criteria.Dbid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _dbid = dr.GetInt32("DBID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _connectionstring = dr.GetString("ConnectionString"); + _servertype = dr.GetInt32("ServerType"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + // load child objects + dr.NextResult(); + _connectionfolders = ConnectionFolders.Get(dr); + + } + } + } + } + catch (Exception ex) + { + Database.LogException("Connection", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addConnection"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@name", _name); + cm.Parameters.AddWithValue("@title", _title); + cm.Parameters.AddWithValue("@connectionString", _connectionstring); + cm.Parameters.AddWithValue("@serverType", _servertype); + cm.Parameters.AddWithValue("@config", _config); + cm.Parameters.AddWithValue("@dTS", _dts); + cm.Parameters.AddWithValue("@usrID", _usrid); + // Output Calculated Columns + SqlParameter param_dbid = new SqlParameter("@newDBID", SqlDbType.Int); + param_dbid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_dbid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _dbid = (int)cm.Parameters["@newDBID"].Value; + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + // update child objects + _connectionfolders.Update(this, cn); + + } + + } + catch (Exception ex) + { + Database.LogException("Connection", 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) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addConnection"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@name", name); + cm.Parameters.AddWithValue("@title", title); + cm.Parameters.AddWithValue("@connectionString", connectionstring); + cm.Parameters.AddWithValue("@serverType", servertype); + cm.Parameters.AddWithValue("@config", config); + cm.Parameters.AddWithValue("@dTS", dts); + cm.Parameters.AddWithValue("@usrID", usrid); + // Output Calculated Columns + SqlParameter param_dbid = new SqlParameter("@newDBID", SqlDbType.Int); + param_dbid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_dbid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + dbid = (int)cm.Parameters["@newDBID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Connection", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateConnection"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@dBID", _dbid); + cm.Parameters.AddWithValue("@name", _name); + cm.Parameters.AddWithValue("@title", _title); + cm.Parameters.AddWithValue("@connectionString", _connectionstring); + cm.Parameters.AddWithValue("@serverType", _servertype); + cm.Parameters.AddWithValue("@config", _config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + _connectionfolders.Update(this, cn); + + } + } + catch (Exception ex) + { + Database.LogException("Connection", ex); + } + + } + } + + + [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) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateConnection"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@dBID", dbid); + cm.Parameters.AddWithValue("@name", name); + cm.Parameters.AddWithValue("@title", title); + cm.Parameters.AddWithValue("@connectionString", connectionstring); + cm.Parameters.AddWithValue("@serverType", servertype); + cm.Parameters.AddWithValue("@config", config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Connection", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_dbid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteConnection"; + cm.Parameters.AddWithValue("@dBID", criteria.Dbid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("Connection", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int dbid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteConnection"; + // Input PK Fields + + cm.Parameters.AddWithValue("@dBID", dbid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("Connection", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int dbid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(dbid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _dbid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int dbid) + { + _dbid = dbid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsConnection"; + + cm.Parameters.AddWithValue("@dBID", _dbid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("Connection", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultServerType + { + get { return 1; } + } + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create ConnectionExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class Connection + // { + // partial class Extension : extensionBase + // { + // TODO: Override automatic defaults + // public virtual int DefaultServerType + // { + // 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionFolder.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionFolder.cs index a514ee23..d6c4addb 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionFolder.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionFolder.cs @@ -17,428 +17,416 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// ConnectionFolder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class ConnectionFolder : BusinessBase - { - #region Business Methods - - - private int _folderid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folderid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderid; - } - } - private int _parentid; - [System.ComponentModel.DataObjectField(true, true)] - public int Parentid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _parentid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_parentid != value) - { - _parentid = value; - PropertyHasChanged(); - } - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_name != value) - { - _name = value; - PropertyHasChanged(); - } - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_title != value) - { - _title = value; - PropertyHasChanged(); - } - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_config != value) - { - _config = value; - PropertyHasChanged(); - } - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - // TODO: Check ConnectionFolder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ConnectionFolder - protected override object GetIdValue() - { - return _folderid; - } - // TODO: Replace base ConnectionFolder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ConnectionFolder - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Folderid, ""); - //AuthorizationRules.AllowRead(Parentid, ""); - //AuthorizationRules.AllowWrite(Parentid, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static ConnectionFolder New(string name) + /// + /// ConnectionFolder Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class ConnectionFolder : BusinessBase { - return new ConnectionFolder(name); - } + #region Business Methods - internal static ConnectionFolder Get(SafeDataReader dr) - { - return new ConnectionFolder(dr); - } - private ConnectionFolder() - { - MarkAsChild(); - _parentid = ext.DefaultParentid; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _folderid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folderid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderid; + } + } + private int _parentid; + [System.ComponentModel.DataObjectField(true, true)] + public int Parentid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _parentid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_parentid != value) + { + _parentid = value; + PropertyHasChanged(); + } + } + } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_name != value) + { + _name = value; + PropertyHasChanged(); + } + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_title != value) + { + _title = value; + PropertyHasChanged(); + } + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_config != value) + { + _config = value; + PropertyHasChanged(); + } + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + // TODO: Check ConnectionFolder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ConnectionFolder + protected override object GetIdValue() + { + return _folderid; + } + // TODO: Replace base ConnectionFolder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ConnectionFolder + //public override string ToString() + //{ + // return base.ToString(); + //} - private ConnectionFolder(string name) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _parentid = ext.DefaultParentid; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _name = name; - } + #endregion + #region ValidationRules - private ConnectionFolder(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } - - #endregion - #region Data Access Portal + // 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; + //} - private void Fetch(SafeDataReader dr) - { - try{ - _folderid = dr.GetInt32("FolderID"); - _parentid = dr.GetInt32("ParentID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - } - catch(Exception ex) - { - Database.LogException("ConnectionFolder",ex); - } - MarkOld(); - } + #endregion - internal void Insert(Connection connection,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Folder.Add(cn, ref _folderid, _parentid, connection.Dbid, _name, _title, _config, _dts, _usrid); - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Folderid, ""); + //AuthorizationRules.AllowRead(Parentid, ""); + //AuthorizationRules.AllowWrite(Parentid, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Update(Connection connection,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Folder.Update(cn, ref _folderid, _parentid, connection.Dbid, _name, _title, _config, _dts, _usrid, ref _lastchanged); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void DeleteSelf(Connection connection,SqlConnection cn) - { - // 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; - Folder.Remove(cn,_folderid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultParentid - { - get { return 0; } - } - public virtual int DefaultDbid - { - get { return 0; } - } - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } -// The follwing is a sample Extension File. You can use it to create ConnectionFolderExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanDeleteObject() + { + // TODO: 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; + } -//namespace PatrialClass -//{ -// public partial class ConnectionFolder -// { -// partial class Extension : extensionBase -// { -// TODO: Override automatic defaults -// public virtual int DefaultParentid -// { -// get { return 0; } -// } -// public virtual int DefaultDbid -// { -// get { return 0; } -// } -// 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods - } // Class + internal static ConnectionFolder New(string name) + { + return new ConnectionFolder(name); + } + + internal static ConnectionFolder Get(SafeDataReader dr) + { + return new ConnectionFolder(dr); + } + + private ConnectionFolder() + { + MarkAsChild(); + _parentid = ext.DefaultParentid; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private ConnectionFolder(string name) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _parentid = ext.DefaultParentid; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _name = name; + } + + private ConnectionFolder(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _folderid = dr.GetInt32("FolderID"); + _parentid = dr.GetInt32("ParentID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + } + catch (Exception ex) + { + Database.LogException("ConnectionFolder", ex); + } + MarkOld(); + } + + internal void Insert(Connection connection, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Folder.Add(cn, ref _folderid, _parentid, connection.Dbid, _name, _title, _config, _dts, _usrid); + MarkOld(); + } + + internal void Update(Connection connection, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Folder.Update(cn, ref _folderid, _parentid, connection.Dbid, _name, _title, _config, _dts, _usrid, ref _lastchanged); + } + + internal void DeleteSelf(Connection connection, SqlConnection cn) + { + // 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; + Folder.Remove(cn, _folderid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultParentid + { + get { return 0; } + } + public virtual int DefaultDbid + { + get { return 0; } + } + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create ConnectionFolderExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class ConnectionFolder + // { + // partial class Extension : extensionBase + // { + // TODO: Override automatic defaults + // public virtual int DefaultParentid + // { + // get { return 0; } + // } + // public virtual int DefaultDbid + // { + // get { return 0; } + // } + // 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionInfo.cs index 5facddcc..67dc3193 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/ConnectionInfo.cs @@ -17,154 +17,146 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// ConnectionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class ConnectionInfo : ReadOnlyBase - { - #region Business Methods - - - private int _dbid; - [System.ComponentModel.DataObjectField(true, true)] - public int Dbid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dbid; - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - } - private string _connectionstring=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string ConnectionString - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _connectionstring; - } - } - private int _servertype; - /// - /// 0 SQL Server - /// - [System.ComponentModel.DataObjectField(true, true)] - public int ServerType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _servertype; - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base ConnectionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current ConnectionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check ConnectionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current ConnectionInfo - protected override object GetIdValue() - { - return _dbid; - } - - - #endregion - #region Factory Methods - private ConnectionInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal ConnectionInfo(SafeDataReader dr) + /// + /// ConnectionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class ConnectionInfo : ReadOnlyBase { - try - { - _dbid = dr.GetInt32("DBID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _connectionstring = dr.GetString("ConnectionString"); - _servertype = dr.GetInt32("ServerType"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("ConnectionInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _dbid; + [System.ComponentModel.DataObjectField(true, true)] + public int Dbid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dbid; + } + } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + } + private string _connectionstring = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string ConnectionString + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _connectionstring; + } + } + private int _servertype; + /// + /// 0 SQL Server + /// + [System.ComponentModel.DataObjectField(true, true)] + public int ServerType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _servertype; + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base ConnectionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current ConnectionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check ConnectionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current ConnectionInfo + protected override object GetIdValue() + { + return _dbid; + } + + + #endregion + #region Factory Methods + private ConnectionInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal ConnectionInfo(SafeDataReader dr) + { + try + { + _dbid = dr.GetInt32("DBID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _connectionstring = dr.GetString("ConnectionString"); + _servertype = dr.GetInt32("ServerType"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("ConnectionInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/Folder.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/Folder.cs index d20ca973..a9487771 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/Folder.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/Folder.cs @@ -17,759 +17,752 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// Folder Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class Folder : BusinessBase - { - #region Business Methods - - private int _folderid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folderid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderid; - } - } - private int _parentid; - [System.ComponentModel.DataObjectField(true, true)] - public int Parentid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _parentid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_parentid != value) - { - _parentid = value; - PropertyHasChanged(); - } - } - } - private int _dbid; - [System.ComponentModel.DataObjectField(true, true)] - public int Dbid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dbid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dbid != value) - { - _dbid = value; - PropertyHasChanged(); - } - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_name != value) - { - _name = value; - PropertyHasChanged(); - } - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_title != value) - { - _title = value; - PropertyHasChanged(); - } - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_config != value) - { - _config = value; - PropertyHasChanged(); - } - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private FolderAssignments _folderassignments = FolderAssignments.New(); - /// - /// Related Field - /// - [System.ComponentModel.DataObjectField(true, true)] - public FolderAssignments FolderAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderassignments; - } - } - public override bool IsDirty - { - get { return base.IsDirty || _folderassignments.IsDirty ; } - } - public override bool IsValid - { - get { return base.IsValid && _folderassignments.IsValid ; } - } - // TODO: Replace base Folder.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Folder - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check Folder.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Folder - protected override object GetIdValue() - { - return _folderid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - // 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Folderid, ""); - //AuthorizationRules.AllowRead(Parentid, ""); - //AuthorizationRules.AllowRead(Dbid, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Parentid, ""); - //AuthorizationRules.AllowWrite(Dbid, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private Folder() - {/* require use of factory methods */} - - public static Folder New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Folder"); - return DataPortal.Create(); - } - - public static Folder Get(int _folderid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Folder"); - return DataPortal.Fetch(new PKCriteria(_folderid)); - } - - public static void Delete(int _folderid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Folder"); - DataPortal.Delete(new PKCriteria(_folderid)); - } - - 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"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _folderid; - public int Folderid - { get {return _folderid;}} - public PKCriteria(int folderid) - { - _folderid=folderid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _parentid = ext.DefaultParentid; - _dbid = ext.DefaultDbid; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getFolder"; - cm.Parameters.AddWithValue("@folderID", criteria.Folderid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _folderid = dr.GetInt32("FolderID"); - _parentid = dr.GetInt32("ParentID"); - _dbid = dr.GetInt32("DBID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - // load child objects - dr.NextResult(); - _folderassignments = FolderAssignments.Get(dr); - - } - } - } - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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("@config", _config); - 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); - // TODO: 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; - } - // update child objects - _folderassignments.Update(this,cn); - - } - - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - }} - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn,ref int folderid, int parentid, int dbid, string name, string title, string config, DateTime dts, string usrid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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("@config", config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - folderid = (int)cm.Parameters["@newFolderID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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("@config", _config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - _folderassignments.Update(this,cn); - - } - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - } - - } - } - - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn,ref int folderid, int parentid, int dbid, string name, string title, string config, DateTime dts, string usrid, ref byte[] lastchanged) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateFolder"; - // Input All Fields - Except Calculated Columns - - 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("@config", config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_folderid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteFolder"; - cm.Parameters.AddWithValue("@folderID", criteria.Folderid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int folderid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteFolder"; - // Input PK Fields - - cm.Parameters.AddWithValue("@folderID", folderid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int folderid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(folderid)); - return result.Exists; - } - + /// + /// Folder Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class Folder : BusinessBase { + #region Business Methods - private int _folderid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int folderid) - { - _folderid=folderid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _folderid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folderid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsFolder"; - - cm.Parameters.AddWithValue("@folderID", _folderid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderid; + } } - } - catch(Exception ex) - { - Database.LogException("Folder",ex); - } - } - } + private int _parentid; + [System.ComponentModel.DataObjectField(true, true)] + public int Parentid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _parentid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_parentid != value) + { + _parentid = value; + PropertyHasChanged(); + } + } + } + private int _dbid; + [System.ComponentModel.DataObjectField(true, true)] + public int Dbid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dbid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dbid != value) + { + _dbid = value; + PropertyHasChanged(); + } + } + } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_name != value) + { + _name = value; + PropertyHasChanged(); + } + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_title != value) + { + _title = value; + PropertyHasChanged(); + } + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_config != value) + { + _config = value; + PropertyHasChanged(); + } + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private FolderAssignments _folderassignments = FolderAssignments.New(); + /// + /// Related Field + /// + [System.ComponentModel.DataObjectField(true, true)] + public FolderAssignments FolderAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderassignments; + } + } + public override bool IsDirty + { + get { return base.IsDirty || _folderassignments.IsDirty; } + } + public override bool IsValid + { + get { return base.IsValid && _folderassignments.IsValid; } + } + // TODO: Replace base Folder.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Folder + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check Folder.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Folder + protected override object GetIdValue() + { + return _folderid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultParentid - { - get { return 0; } - } - public virtual int DefaultDbid - { - get { return 0; } - } - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create FolderExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class Folder -// { -// partial class Extension : extensionBase -// { -// TODO: Override automatic defaults -// public virtual int DefaultParentid -// { -// get { return 0; } -// } -// public virtual int DefaultDbid -// { -// get { return 0; } -// } -// 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 510)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + // 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Folderid, ""); + //AuthorizationRules.AllowRead(Parentid, ""); + //AuthorizationRules.AllowRead(Dbid, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Parentid, ""); + //AuthorizationRules.AllowWrite(Dbid, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private Folder() + {/* require use of factory methods */} + + public static Folder New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Folder"); + return DataPortal.Create(); + } + + public static Folder Get(int _folderid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Folder"); + return DataPortal.Fetch(new PKCriteria(_folderid)); + } + + public static void Delete(int _folderid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Folder"); + DataPortal.Delete(new PKCriteria(_folderid)); + } + + 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"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _folderid; + public int Folderid + { get { return _folderid; } } + public PKCriteria(int folderid) + { + _folderid = folderid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _parentid = ext.DefaultParentid; + _dbid = ext.DefaultDbid; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFolder"; + cm.Parameters.AddWithValue("@folderID", criteria.Folderid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _folderid = dr.GetInt32("FolderID"); + _parentid = dr.GetInt32("ParentID"); + _dbid = dr.GetInt32("DBID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + // load child objects + dr.NextResult(); + _folderassignments = FolderAssignments.Get(dr); + + } + } + } + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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("@config", _config); + 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); + // TODO: 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; + } + // update child objects + _folderassignments.Update(this, cn); + + } + + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int folderid, int parentid, int dbid, string name, string title, string config, DateTime dts, string usrid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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("@config", config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + folderid = (int)cm.Parameters["@newFolderID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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("@config", _config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + _folderassignments.Update(this, cn); + + } + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + } + + } + } + + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int folderid, int parentid, int dbid, string name, string title, string config, DateTime dts, string usrid, ref byte[] lastchanged) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateFolder"; + // Input All Fields - Except Calculated Columns + + 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("@config", config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_folderid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteFolder"; + cm.Parameters.AddWithValue("@folderID", criteria.Folderid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int folderid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteFolder"; + // Input PK Fields + + cm.Parameters.AddWithValue("@folderID", folderid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int folderid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(folderid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _folderid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int folderid) + { + _folderid = folderid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsFolder"; + + cm.Parameters.AddWithValue("@folderID", _folderid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("Folder", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultParentid + { + get { return 0; } + } + public virtual int DefaultDbid + { + get { return 0; } + } + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing 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 PatrialClass + //{ + // public partial class Folder + // { + // partial class Extension : extensionBase + // { + // TODO: Override automatic defaults + // public virtual int DefaultParentid + // { + // get { return 0; } + // } + // public virtual int DefaultDbid + // { + // get { return 0; } + // } + // 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/FolderAssignment.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/FolderAssignment.cs index 56f2ebe6..84cd0846 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/FolderAssignment.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/FolderAssignment.cs @@ -17,572 +17,551 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// FolderAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class FolderAssignment : BusinessBase - { - #region Business Methods - - - private int _aid; - [System.ComponentModel.DataObjectField(true, true)] - public int Aid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _aid; - } - } - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_gid != value) - { - _gid = value; - PropertyHasChanged(); - } - } - } - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_rid != value) - { - _rid = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private string _group_groupname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_groupname; - } - } - private int _group_grouptype; - [System.ComponentModel.DataObjectField(true, true)] - public int Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_grouptype; - } - } - private string _group_config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_config; - } - } - private DateTime _group_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Group_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_dts; - } - } - private string _group_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_usrid; - } - } - private string _role_name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Role_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_name; - } - } - private string _role_title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Role_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_title; - } - } - private DateTime _role_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Role_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_dts; - } - } - private string _role_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Role_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_usrid; - } - } - // TODO: Check FolderAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderAssignment - protected override object GetIdValue() - { - return _aid; - } - // TODO: Replace base FolderAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: Add other validation rules - } - - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Aid, ""); - //AuthorizationRules.AllowRead(Gid, ""); - //AuthorizationRules.AllowWrite(Gid, ""); - //AuthorizationRules.AllowRead(Rid, ""); - //AuthorizationRules.AllowWrite(Rid, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static FolderAssignment New(int gid, int rid) + /// + /// FolderAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class FolderAssignment : BusinessBase { - return new FolderAssignment(Volian.Object.Library.Group.Get(gid), Volian.Object.Library.Role.Get(rid)); - } + #region Business Methods - internal static FolderAssignment Get(SafeDataReader dr) - { - return new FolderAssignment(dr); - } - private FolderAssignment() - { - MarkAsChild(); - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _aid; + [System.ComponentModel.DataObjectField(true, true)] + public int Aid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _aid; + } + } + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_gid != value) + { + _gid = value; + PropertyHasChanged(); + } + } + } + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_rid != value) + { + _rid = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private string _group_groupname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_groupname; + } + } + private int _group_grouptype; + [System.ComponentModel.DataObjectField(true, true)] + public int Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_grouptype; + } + } + private string _group_config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_config; + } + } + private DateTime _group_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Group_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_dts; + } + } + private string _group_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_usrid; + } + } + private string _role_name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Role_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_name; + } + } + private string _role_title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Role_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_title; + } + } + private DateTime _role_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Role_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_dts; + } + } + private string _role_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Role_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_usrid; + } + } + // TODO: Check FolderAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderAssignment + protected override object GetIdValue() + { + return _aid; + } + // TODO: Replace base FolderAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} - private FolderAssignment(Group group, Role role) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _gid = group.Gid; - _group_groupname = group.GroupName; - _group_grouptype = group.GroupType; - _group_config = group.Config; - _group_dts = group.Dts; - _group_usrid = group.Usrid; - _rid = role.Rid; - _role_name = role.Name; - _role_title = role.Title; - _role_dts = role.Dts; - _role_usrid = role.Usrid; - } + #endregion + #region ValidationRules - private FolderAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } - - #endregion - #region Data Access Portal + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - private void Fetch(SafeDataReader dr) - { - try{ - _aid = dr.GetInt32("AID"); - _gid = dr.GetInt32("GID"); - _rid = dr.GetInt32("RID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - _group_groupname = dr.GetString("Groups_GroupName"); - _group_grouptype = dr.GetInt32("Groups_GroupType"); - _group_config = dr.GetString("Groups_Config"); - _group_dts = dr.GetDateTime("Groups_DTS"); - _group_usrid = dr.GetString("Groups_UsrID"); - _role_name = dr.GetString("Roles_Name"); - _role_title = dr.GetString("Roles_Title"); - _role_dts = dr.GetDateTime("Roles_DTS"); - _role_usrid = dr.GetString("Roles_UsrID"); - } - catch(Exception ex) - { - Database.LogException("FolderAssignment",ex); - } - MarkOld(); - } + #endregion - internal void Insert(Folder folder,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Assignment.Add(cn, ref _aid, _gid, _rid, folder.Folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Aid, ""); + //AuthorizationRules.AllowRead(Gid, ""); + //AuthorizationRules.AllowWrite(Gid, ""); + //AuthorizationRules.AllowRead(Rid, ""); + //AuthorizationRules.AllowWrite(Rid, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Update(Folder folder,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Assignment.Update(cn, ref _aid, _gid, _rid, folder.Folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void DeleteSelf(Folder folder,SqlConnection cn) - { - // 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; - Assignment.Remove(cn,_aid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } -// The follwing is a sample Extension File. You can use it to create FolderAssignmentExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanDeleteObject() + { + // TODO: 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; + } -//namespace PatrialClass -//{ -// public partial class FolderAssignment -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods - } // Class + internal static FolderAssignment New(int gid, int rid) + { + return new FolderAssignment(Volian.Object.Library.Group.Get(gid), Volian.Object.Library.Role.Get(rid)); + } + + internal static FolderAssignment Get(SafeDataReader dr) + { + return new FolderAssignment(dr); + } + + private FolderAssignment() + { + MarkAsChild(); + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private FolderAssignment(Group group, Role role) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _gid = group.Gid; + _group_groupname = group.GroupName; + _group_grouptype = group.GroupType; + _group_config = group.Config; + _group_dts = group.Dts; + _group_usrid = group.Usrid; + _rid = role.Rid; + _role_name = role.Name; + _role_title = role.Title; + _role_dts = role.Dts; + _role_usrid = role.Usrid; + } + + private FolderAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _aid = dr.GetInt32("AID"); + _gid = dr.GetInt32("GID"); + _rid = dr.GetInt32("RID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + _group_groupname = dr.GetString("Groups_GroupName"); + _group_grouptype = dr.GetInt32("Groups_GroupType"); + _group_config = dr.GetString("Groups_Config"); + _group_dts = dr.GetDateTime("Groups_DTS"); + _group_usrid = dr.GetString("Groups_UsrID"); + _role_name = dr.GetString("Roles_Name"); + _role_title = dr.GetString("Roles_Title"); + _role_dts = dr.GetDateTime("Roles_DTS"); + _role_usrid = dr.GetString("Roles_UsrID"); + } + catch (Exception ex) + { + Database.LogException("FolderAssignment", ex); + } + MarkOld(); + } + + internal void Insert(Folder folder, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Assignment.Add(cn, ref _aid, _gid, _rid, folder.Folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); + MarkOld(); + } + + internal void Update(Folder folder, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Assignment.Update(cn, ref _aid, _gid, _rid, folder.Folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); + } + + internal void DeleteSelf(Folder folder, SqlConnection cn) + { + // 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; + Assignment.Remove(cn, _aid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing 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 PatrialClass + //{ + // public partial class FolderAssignment + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/FolderInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/FolderInfo.cs index 20399695..650a2fd3 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/FolderInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/FolderInfo.cs @@ -17,151 +17,143 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class FolderInfo : ReadOnlyBase - { - #region Business Methods - - - private int _folderid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folderid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderid; - } - } - private int _parentid; - [System.ComponentModel.DataObjectField(true, true)] - public int Parentid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _parentid; - } - } - private int _dbid; - [System.ComponentModel.DataObjectField(true, true)] - public int Dbid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dbid; - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base FolderInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current FolderInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current FolderInfo - protected override object GetIdValue() - { - return _folderid; - } - - - #endregion - #region Factory Methods - private FolderInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal FolderInfo(SafeDataReader dr) + /// + /// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class FolderInfo : ReadOnlyBase { - try - { - _folderid = dr.GetInt32("FolderID"); - _parentid = dr.GetInt32("ParentID"); - _dbid = dr.GetInt32("DBID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("FolderInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _folderid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folderid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderid; + } + } + private int _parentid; + [System.ComponentModel.DataObjectField(true, true)] + public int Parentid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _parentid; + } + } + private int _dbid; + [System.ComponentModel.DataObjectField(true, true)] + public int Dbid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dbid; + } + } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base FolderInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current FolderInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current FolderInfo + protected override object GetIdValue() + { + return _folderid; + } + + + #endregion + #region Factory Methods + private FolderInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal FolderInfo(SafeDataReader dr) + { + try + { + _folderid = dr.GetInt32("FolderID"); + _parentid = dr.GetInt32("ParentID"); + _dbid = dr.GetInt32("DBID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("FolderInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/Group.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/Group.cs index 843c2c41..b7fa129a 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/Group.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/Group.cs @@ -17,703 +17,699 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// Group Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class Group : BusinessBase - { - #region Business Methods - - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - } - private string _groupname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _groupname; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_groupname != value) - { - _groupname = value; - PropertyHasChanged(); - } - } - } - private int _grouptype; - [System.ComponentModel.DataObjectField(true, true)] - public int GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _grouptype; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_grouptype != value) - { - _grouptype = value; - PropertyHasChanged(); - } - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_config != value) - { - _config = value; - PropertyHasChanged(); - } - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private GroupAssignments _groupassignments = GroupAssignments.New(); - /// - /// Related Field - /// - [System.ComponentModel.DataObjectField(true, true)] - public GroupAssignments GroupAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _groupassignments; - } - } - private GroupMemberships _groupmemberships = GroupMemberships.New(); - /// - /// Related Field - /// - [System.ComponentModel.DataObjectField(true, true)] - public GroupMemberships GroupMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _groupmemberships; - } - } - public override bool IsDirty - { - get { return base.IsDirty || _groupassignments.IsDirty || _groupmemberships.IsDirty ; } - } - public override bool IsValid - { - get { return base.IsValid && _groupassignments.IsValid && _groupmemberships.IsValid ; } - } - // TODO: Replace base Group.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Group - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check Group.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Group - protected override object GetIdValue() - { - return _gid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "GroupName"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("GroupName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - // 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Gid, ""); - //AuthorizationRules.AllowRead(GroupName, ""); - //AuthorizationRules.AllowRead(GroupType, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(GroupName, ""); - //AuthorizationRules.AllowWrite(GroupType, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private Group() - {/* require use of factory methods */} - - public static Group New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Group"); - return DataPortal.Create(); - } - - public static Group Get(int _gid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Group"); - return DataPortal.Fetch(new PKCriteria(_gid)); - } - - public static void Delete(int _gid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Group"); - DataPortal.Delete(new PKCriteria(_gid)); - } - - 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"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _gid; - public int Gid - { get {return _gid;}} - public PKCriteria(int gid) - { - _gid=gid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getGroup"; - cm.Parameters.AddWithValue("@gID", criteria.Gid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _gid = dr.GetInt32("GID"); - _groupname = dr.GetString("GroupName"); - _grouptype = dr.GetInt32("GroupType"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - // load child objects - dr.NextResult(); - _groupassignments = GroupAssignments.Get(dr); - - // load child objects - dr.NextResult(); - _groupmemberships = GroupMemberships.Get(dr); - - } - } - } - } - catch(Exception ex) - { - Database.LogException("Group",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addGroup"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@groupName", _groupname); - cm.Parameters.AddWithValue("@groupType", _grouptype); - cm.Parameters.AddWithValue("@config", _config); - 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); - // TODO: 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; - } - // update child objects - _groupassignments.Update(this,cn); - - _groupmemberships.Update(this,cn); - - } - - } - catch(Exception ex) - { - Database.LogException("Group",ex); - }} - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn,ref int gid, string groupname, int grouptype, string config, DateTime dts, string usrid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addGroup"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@groupName", groupname); - cm.Parameters.AddWithValue("@groupType", grouptype); - cm.Parameters.AddWithValue("@config", config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - gid = (int)cm.Parameters["@newGID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Group",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - 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); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - _groupassignments.Update(this,cn); - - _groupmemberships.Update(this,cn); - - } - } - catch(Exception ex) - { - Database.LogException("Group",ex); - } - - } - } - - - [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) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateGroup"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@gID", gid); - cm.Parameters.AddWithValue("@groupName", groupname); - cm.Parameters.AddWithValue("@groupType", grouptype); - cm.Parameters.AddWithValue("@config", config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Group",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_gid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteGroup"; - cm.Parameters.AddWithValue("@gID", criteria.Gid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("Group",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int gid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteGroup"; - // Input PK Fields - - cm.Parameters.AddWithValue("@gID", gid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("Group",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int gid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(gid)); - return result.Exists; - } - + /// + /// Group Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class Group : BusinessBase { + #region Business Methods - private int _gid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int gid) - { - _gid=gid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsGroup"; - - cm.Parameters.AddWithValue("@gID", _gid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } } - } - catch(Exception ex) - { - Database.LogException("Group",ex); - } - } - } + private string _groupname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _groupname; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_groupname != value) + { + _groupname = value; + PropertyHasChanged(); + } + } + } + private int _grouptype; + [System.ComponentModel.DataObjectField(true, true)] + public int GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _grouptype; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_grouptype != value) + { + _grouptype = value; + PropertyHasChanged(); + } + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_config != value) + { + _config = value; + PropertyHasChanged(); + } + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private GroupAssignments _groupassignments = GroupAssignments.New(); + /// + /// Related Field + /// + [System.ComponentModel.DataObjectField(true, true)] + public GroupAssignments GroupAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _groupassignments; + } + } + private GroupMemberships _groupmemberships = GroupMemberships.New(); + /// + /// Related Field + /// + [System.ComponentModel.DataObjectField(true, true)] + public GroupMemberships GroupMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _groupmemberships; + } + } + public override bool IsDirty + { + get { return base.IsDirty || _groupassignments.IsDirty || _groupmemberships.IsDirty; } + } + public override bool IsValid + { + get { return base.IsValid && _groupassignments.IsValid && _groupmemberships.IsValid; } + } + // TODO: Replace base Group.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Group + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check Group.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Group + protected override object GetIdValue() + { + return _gid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create GroupExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class Group -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "GroupName"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("GroupName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + // 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Gid, ""); + //AuthorizationRules.AllowRead(GroupName, ""); + //AuthorizationRules.AllowRead(GroupType, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(GroupName, ""); + //AuthorizationRules.AllowWrite(GroupType, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private Group() + {/* require use of factory methods */} + + public static Group New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Group"); + return DataPortal.Create(); + } + + public static Group Get(int _gid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Group"); + return DataPortal.Fetch(new PKCriteria(_gid)); + } + + public static void Delete(int _gid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Group"); + DataPortal.Delete(new PKCriteria(_gid)); + } + + 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"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _gid; + public int Gid + { get { return _gid; } } + public PKCriteria(int gid) + { + _gid = gid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getGroup"; + cm.Parameters.AddWithValue("@gID", criteria.Gid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _gid = dr.GetInt32("GID"); + _groupname = dr.GetString("GroupName"); + _grouptype = dr.GetInt32("GroupType"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + // load child objects + dr.NextResult(); + _groupassignments = GroupAssignments.Get(dr); + + // load child objects + dr.NextResult(); + _groupmemberships = GroupMemberships.Get(dr); + + } + } + } + } + catch (Exception ex) + { + Database.LogException("Group", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addGroup"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@groupName", _groupname); + cm.Parameters.AddWithValue("@groupType", _grouptype); + cm.Parameters.AddWithValue("@config", _config); + 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); + // TODO: 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; + } + // update child objects + _groupassignments.Update(this, cn); + + _groupmemberships.Update(this, cn); + + } + + } + catch (Exception ex) + { + Database.LogException("Group", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int gid, string groupname, int grouptype, string config, DateTime dts, string usrid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addGroup"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@groupName", groupname); + cm.Parameters.AddWithValue("@groupType", grouptype); + cm.Parameters.AddWithValue("@config", config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + gid = (int)cm.Parameters["@newGID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Group", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + 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); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + _groupassignments.Update(this, cn); + + _groupmemberships.Update(this, cn); + + } + } + catch (Exception ex) + { + Database.LogException("Group", ex); + } + + } + } + + + [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) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateGroup"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@gID", gid); + cm.Parameters.AddWithValue("@groupName", groupname); + cm.Parameters.AddWithValue("@groupType", grouptype); + cm.Parameters.AddWithValue("@config", config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Group", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_gid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteGroup"; + cm.Parameters.AddWithValue("@gID", criteria.Gid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("Group", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int gid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteGroup"; + // Input PK Fields + + cm.Parameters.AddWithValue("@gID", gid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("Group", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int gid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(gid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _gid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int gid) + { + _gid = gid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsGroup"; + + cm.Parameters.AddWithValue("@gID", _gid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("Group", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing 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 PatrialClass + //{ + // public partial class Group + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/GroupAssignment.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/GroupAssignment.cs index 17472ca3..1df07b69 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/GroupAssignment.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/GroupAssignment.cs @@ -17,598 +17,575 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// GroupAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class GroupAssignment : BusinessBase - { - #region Business Methods - - - private int _aid; - [System.ComponentModel.DataObjectField(true, true)] - public int Aid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _aid; - } - } - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_rid != value) - { - _rid = value; - PropertyHasChanged(); - } - } - } - private int _folderid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folderid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_folderid != value) - { - _folderid = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private int _folder_parentid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folder_Parentid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_parentid; - } - } - private int _folder_dbid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folder_Dbid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_dbid; - } - } - private string _folder_name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_name; - } - } - private string _folder_title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_title; - } - } - private string _folder_config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_config; - } - } - private DateTime _folder_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Folder_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_dts; - } - } - private string _folder_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_usrid; - } - } - private string _role_name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Role_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_name; - } - } - private string _role_title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Role_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_title; - } - } - private DateTime _role_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Role_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_dts; - } - } - private string _role_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Role_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _role_usrid; - } - } - // TODO: Check GroupAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupAssignment - protected override object GetIdValue() - { - return _aid; - } - // TODO: Replace base GroupAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: Add other validation rules - } - - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Aid, ""); - //AuthorizationRules.AllowRead(Rid, ""); - //AuthorizationRules.AllowWrite(Rid, ""); - //AuthorizationRules.AllowRead(Folderid, ""); - //AuthorizationRules.AllowWrite(Folderid, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static GroupAssignment New(int rid, int folderid) + /// + /// GroupAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class GroupAssignment : BusinessBase { - return new GroupAssignment(Volian.Object.Library.Role.Get(rid), Volian.Object.Library.Folder.Get(folderid)); - } + #region Business Methods - internal static GroupAssignment Get(SafeDataReader dr) - { - return new GroupAssignment(dr); - } - private GroupAssignment() - { - MarkAsChild(); - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _aid; + [System.ComponentModel.DataObjectField(true, true)] + public int Aid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _aid; + } + } + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_rid != value) + { + _rid = value; + PropertyHasChanged(); + } + } + } + private int _folderid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folderid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_folderid != value) + { + _folderid = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private int _folder_parentid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folder_Parentid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_parentid; + } + } + private int _folder_dbid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folder_Dbid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_dbid; + } + } + private string _folder_name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_name; + } + } + private string _folder_title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_title; + } + } + private string _folder_config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_config; + } + } + private DateTime _folder_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Folder_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_dts; + } + } + private string _folder_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_usrid; + } + } + private string _role_name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Role_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_name; + } + } + private string _role_title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Role_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_title; + } + } + private DateTime _role_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Role_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_dts; + } + } + private string _role_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Role_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _role_usrid; + } + } + // TODO: Check GroupAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupAssignment + protected override object GetIdValue() + { + return _aid; + } + // TODO: Replace base GroupAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} - private GroupAssignment(Role role, Folder folder) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _folderid = folder.Folderid; - _folder_parentid = folder.Parentid; - _folder_dbid = folder.Dbid; - _folder_name = folder.Name; - _folder_title = folder.Title; - _folder_config = folder.Config; - _folder_dts = folder.Dts; - _folder_usrid = folder.Usrid; - _rid = role.Rid; - _role_name = role.Name; - _role_title = role.Title; - _role_dts = role.Dts; - _role_usrid = role.Usrid; - } + #endregion + #region ValidationRules - private GroupAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } - - #endregion - #region Data Access Portal + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - private void Fetch(SafeDataReader dr) - { - try{ - _aid = dr.GetInt32("AID"); - _rid = dr.GetInt32("RID"); - _folderid = dr.GetInt32("FolderID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - _folder_parentid = dr.GetInt32("Folders_ParentID"); - _folder_dbid = dr.GetInt32("Folders_DBID"); - _folder_name = dr.GetString("Folders_Name"); - _folder_title = dr.GetString("Folders_Title"); - _folder_config = dr.GetString("Folders_Config"); - _folder_dts = dr.GetDateTime("Folders_DTS"); - _folder_usrid = dr.GetString("Folders_UsrID"); - _role_name = dr.GetString("Roles_Name"); - _role_title = dr.GetString("Roles_Title"); - _role_dts = dr.GetDateTime("Roles_DTS"); - _role_usrid = dr.GetString("Roles_UsrID"); - } - catch(Exception ex) - { - Database.LogException("GroupAssignment",ex); - } - MarkOld(); - } + #endregion - internal void Insert(Group group,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Assignment.Add(cn, ref _aid, group.Gid, _rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Aid, ""); + //AuthorizationRules.AllowRead(Rid, ""); + //AuthorizationRules.AllowWrite(Rid, ""); + //AuthorizationRules.AllowRead(Folderid, ""); + //AuthorizationRules.AllowWrite(Folderid, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Update(Group group,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Assignment.Update(cn, ref _aid, group.Gid, _rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void DeleteSelf(Group group,SqlConnection cn) - { - // 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; - Assignment.Remove(cn,_aid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } -// The follwing is a sample Extension File. You can use it to create GroupAssignmentExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanDeleteObject() + { + // TODO: 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; + } -//namespace PatrialClass -//{ -// public partial class GroupAssignment -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods - } // Class + internal static GroupAssignment New(int rid, int folderid) + { + return new GroupAssignment(Volian.Object.Library.Role.Get(rid), Volian.Object.Library.Folder.Get(folderid)); + } + + internal static GroupAssignment Get(SafeDataReader dr) + { + return new GroupAssignment(dr); + } + + private GroupAssignment() + { + MarkAsChild(); + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private GroupAssignment(Role role, Folder folder) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _folderid = folder.Folderid; + _folder_parentid = folder.Parentid; + _folder_dbid = folder.Dbid; + _folder_name = folder.Name; + _folder_title = folder.Title; + _folder_config = folder.Config; + _folder_dts = folder.Dts; + _folder_usrid = folder.Usrid; + _rid = role.Rid; + _role_name = role.Name; + _role_title = role.Title; + _role_dts = role.Dts; + _role_usrid = role.Usrid; + } + + private GroupAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _aid = dr.GetInt32("AID"); + _rid = dr.GetInt32("RID"); + _folderid = dr.GetInt32("FolderID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + _folder_parentid = dr.GetInt32("Folders_ParentID"); + _folder_dbid = dr.GetInt32("Folders_DBID"); + _folder_name = dr.GetString("Folders_Name"); + _folder_title = dr.GetString("Folders_Title"); + _folder_config = dr.GetString("Folders_Config"); + _folder_dts = dr.GetDateTime("Folders_DTS"); + _folder_usrid = dr.GetString("Folders_UsrID"); + _role_name = dr.GetString("Roles_Name"); + _role_title = dr.GetString("Roles_Title"); + _role_dts = dr.GetDateTime("Roles_DTS"); + _role_usrid = dr.GetString("Roles_UsrID"); + } + catch (Exception ex) + { + Database.LogException("GroupAssignment", ex); + } + MarkOld(); + } + + internal void Insert(Group group, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Assignment.Add(cn, ref _aid, group.Gid, _rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); + MarkOld(); + } + + internal void Update(Group group, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Assignment.Update(cn, ref _aid, group.Gid, _rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); + } + + internal void DeleteSelf(Group group, SqlConnection cn) + { + // 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; + Assignment.Remove(cn, _aid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing 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 PatrialClass + //{ + // public partial class GroupAssignment + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/GroupInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/GroupInfo.cs index 1f8b1a0f..ff6c28b3 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/GroupInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/GroupInfo.cs @@ -17,127 +17,121 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// GroupInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class GroupInfo : ReadOnlyBase - { - #region Business Methods - - - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - } - private string _groupname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _groupname; - } - } - private int _grouptype; - [System.ComponentModel.DataObjectField(true, true)] - public int GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _grouptype; - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base GroupInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check GroupInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupInfo - protected override object GetIdValue() - { - return _gid; - } - - - #endregion - #region Factory Methods - private GroupInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal GroupInfo(SafeDataReader dr) + /// + /// GroupInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class GroupInfo : ReadOnlyBase { - try - { - _gid = dr.GetInt32("GID"); - _groupname = dr.GetString("GroupName"); - _grouptype = dr.GetInt32("GroupType"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("GroupInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + } + private string _groupname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _groupname; + } + } + private int _grouptype; + [System.ComponentModel.DataObjectField(true, true)] + public int GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _grouptype; + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base GroupInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check GroupInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupInfo + protected override object GetIdValue() + { + return _gid; + } + + + #endregion + #region Factory Methods + private GroupInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal GroupInfo(SafeDataReader dr) + { + try + { + _gid = dr.GetInt32("GID"); + _groupname = dr.GetString("GroupName"); + _grouptype = dr.GetInt32("GroupType"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("GroupInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/GroupMembership.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/GroupMembership.cs index 58fc3716..dcbada3e 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/GroupMembership.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/GroupMembership.cs @@ -17,599 +17,576 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// GroupMembership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class GroupMembership : BusinessBase - { - #region Business Methods - - - private int _ugid; - [System.ComponentModel.DataObjectField(true, true)] - public int Ugid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _ugid; - } - } - private int _uid; - [System.ComponentModel.DataObjectField(true, true)] - public int Uid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _uid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_uid != value) - { - _uid = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private string _user_userid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_Userid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_userid; - } - } - private string _user_firstname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_firstname; - } - } - private string _user_middlename=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_middlename; - } - } - private string _user_lastname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_lastname; - } - } - private string _user_suffix=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_suffix; - } - } - private string _user_courtesytitle=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_courtesytitle; - } - } - private string _user_phonenumber=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_phonenumber; - } - } - private string _user_cfgname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_CfgName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_cfgname; - } - } - private string _user_userlogin=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_userlogin; - } - } - private string _user_username=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_username; - } - } - private string _user_config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_config; - } - } - private DateTime _user_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime User_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_dts; - } - } - private string _user_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string User_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _user_usrid; - } - } - // TODO: Check GroupMembership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current GroupMembership - protected override object GetIdValue() - { - return _ugid; - } - // TODO: Replace base GroupMembership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current GroupMembership - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: Add other validation rules - } - - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Ugid, ""); - //AuthorizationRules.AllowRead(Uid, ""); - //AuthorizationRules.AllowWrite(Uid, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static GroupMembership New(int uid) + /// + /// GroupMembership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class GroupMembership : BusinessBase { - return new GroupMembership(Volian.Object.Library.User.Get(uid)); - } + #region Business Methods - internal static GroupMembership Get(SafeDataReader dr) - { - return new GroupMembership(dr); - } - private GroupMembership() - { - MarkAsChild(); - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _ugid; + [System.ComponentModel.DataObjectField(true, true)] + public int Ugid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ugid; + } + } + private int _uid; + [System.ComponentModel.DataObjectField(true, true)] + public int Uid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _uid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_uid != value) + { + _uid = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private string _user_userid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_Userid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_userid; + } + } + private string _user_firstname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_firstname; + } + } + private string _user_middlename = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_middlename; + } + } + private string _user_lastname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_lastname; + } + } + private string _user_suffix = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_suffix; + } + } + private string _user_courtesytitle = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_courtesytitle; + } + } + private string _user_phonenumber = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_phonenumber; + } + } + private string _user_cfgname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_CfgName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_cfgname; + } + } + private string _user_userlogin = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_userlogin; + } + } + private string _user_username = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_username; + } + } + private string _user_config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_config; + } + } + private DateTime _user_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime User_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_dts; + } + } + private string _user_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string User_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _user_usrid; + } + } + // TODO: Check GroupMembership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current GroupMembership + protected override object GetIdValue() + { + return _ugid; + } + // TODO: Replace base GroupMembership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current GroupMembership + //public override string ToString() + //{ + // return base.ToString(); + //} - private GroupMembership(User user) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _uid = user.Uid; - _user_userid = user.Userid; - _user_firstname = user.FirstName; - _user_middlename = user.MiddleName; - _user_lastname = user.LastName; - _user_suffix = user.Suffix; - _user_courtesytitle = user.CourtesyTitle; - _user_phonenumber = user.PhoneNumber; - _user_cfgname = user.CfgName; - _user_userlogin = user.UserLogin; - _user_username = user.UserName; - _user_config = user.Config; - _user_dts = user.Dts; - _user_usrid = user.Usrid; - } + #endregion + #region ValidationRules - private GroupMembership(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } - - #endregion - #region Data Access Portal + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - private void Fetch(SafeDataReader dr) - { - try{ - _ugid = dr.GetInt32("UGID"); - _uid = dr.GetInt32("UID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - _user_userid = dr.GetString("Users_UserID"); - _user_firstname = dr.GetString("Users_FirstName"); - _user_middlename = dr.GetString("Users_MiddleName"); - _user_lastname = dr.GetString("Users_LastName"); - _user_suffix = dr.GetString("Users_Suffix"); - _user_courtesytitle = dr.GetString("Users_CourtesyTitle"); - _user_phonenumber = dr.GetString("Users_PhoneNumber"); - _user_cfgname = dr.GetString("Users_CFGName"); - _user_userlogin = dr.GetString("Users_UserLogin"); - _user_username = dr.GetString("Users_UserName"); - _user_config = dr.GetString("Users_Config"); - _user_dts = dr.GetDateTime("Users_DTS"); - _user_usrid = dr.GetString("Users_UsrID"); - } - catch(Exception ex) - { - Database.LogException("GroupMembership",ex); - } - MarkOld(); - } + #endregion - internal void Insert(Group group,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Membership.Add(cn, ref _ugid, _uid, group.Gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Ugid, ""); + //AuthorizationRules.AllowRead(Uid, ""); + //AuthorizationRules.AllowWrite(Uid, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Update(Group group,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Membership.Update(cn, ref _ugid, _uid, group.Gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void DeleteSelf(Group group,SqlConnection cn) - { - // 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; - Membership.Remove(cn,_ugid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } -// The follwing is a sample Extension File. You can use it to create GroupMembershipExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanDeleteObject() + { + // TODO: 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; + } -//namespace PatrialClass -//{ -// public partial class GroupMembership -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods - } // Class + internal static GroupMembership New(int uid) + { + return new GroupMembership(Volian.Object.Library.User.Get(uid)); + } + + internal static GroupMembership Get(SafeDataReader dr) + { + return new GroupMembership(dr); + } + + private GroupMembership() + { + MarkAsChild(); + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private GroupMembership(User user) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _uid = user.Uid; + _user_userid = user.Userid; + _user_firstname = user.FirstName; + _user_middlename = user.MiddleName; + _user_lastname = user.LastName; + _user_suffix = user.Suffix; + _user_courtesytitle = user.CourtesyTitle; + _user_phonenumber = user.PhoneNumber; + _user_cfgname = user.CfgName; + _user_userlogin = user.UserLogin; + _user_username = user.UserName; + _user_config = user.Config; + _user_dts = user.Dts; + _user_usrid = user.Usrid; + } + + private GroupMembership(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _ugid = dr.GetInt32("UGID"); + _uid = dr.GetInt32("UID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + _user_userid = dr.GetString("Users_UserID"); + _user_firstname = dr.GetString("Users_FirstName"); + _user_middlename = dr.GetString("Users_MiddleName"); + _user_lastname = dr.GetString("Users_LastName"); + _user_suffix = dr.GetString("Users_Suffix"); + _user_courtesytitle = dr.GetString("Users_CourtesyTitle"); + _user_phonenumber = dr.GetString("Users_PhoneNumber"); + _user_cfgname = dr.GetString("Users_CFGName"); + _user_userlogin = dr.GetString("Users_UserLogin"); + _user_username = dr.GetString("Users_UserName"); + _user_config = dr.GetString("Users_Config"); + _user_dts = dr.GetDateTime("Users_DTS"); + _user_usrid = dr.GetString("Users_UsrID"); + } + catch (Exception ex) + { + Database.LogException("GroupMembership", ex); + } + MarkOld(); + } + + internal void Insert(Group group, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Membership.Add(cn, ref _ugid, _uid, group.Gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); + MarkOld(); + } + + internal void Update(Group group, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Membership.Update(cn, ref _ugid, _uid, group.Gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); + } + + internal void DeleteSelf(Group group, SqlConnection cn) + { + // 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; + Membership.Remove(cn, _ugid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing 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 PatrialClass + //{ + // public partial class GroupMembership + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/Membership.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/Membership.cs index 072a995f..a437ce11 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/Membership.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/Membership.cs @@ -17,726 +17,722 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// Membership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class Membership : BusinessBase - { - #region Business Methods - - private int _ugid; - [System.ComponentModel.DataObjectField(true, true)] - public int Ugid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _ugid; - } - } - private int _uid; - [System.ComponentModel.DataObjectField(true, true)] - public int Uid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _uid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_uid != value) - { - _uid = value; - PropertyHasChanged(); - } - } - } - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_gid != value) - { - _gid = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - // TODO: Replace base Membership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Membership - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check Membership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Membership - protected override object GetIdValue() - { - return _ugid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Ugid, ""); - //AuthorizationRules.AllowRead(Uid, ""); - //AuthorizationRules.AllowRead(Gid, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Uid, ""); - //AuthorizationRules.AllowWrite(Gid, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private Membership() - {/* require use of factory methods */} - - public static Membership New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Membership"); - return DataPortal.Create(); - } - - public static Membership Get(int _ugid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Membership"); - return DataPortal.Fetch(new PKCriteria(_ugid)); - } - - public static void Delete(int _ugid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Membership"); - DataPortal.Delete(new PKCriteria(_ugid)); - } - - public override Membership Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Membership"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Membership"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Membership"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _ugid; - public int Ugid - { get {return _ugid;}} - public PKCriteria(int ugid) - { - _ugid=ugid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getMembership"; - cm.Parameters.AddWithValue("@uGID", criteria.Ugid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _ugid = dr.GetInt32("UGID"); - _uid = dr.GetInt32("UID"); - _gid = dr.GetInt32("GID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - } - } - } - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addMembership"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@uID", _uid); - cm.Parameters.AddWithValue("@gID", _gid); - cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); - cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); - cm.Parameters.AddWithValue("@dTS", _dts); - cm.Parameters.AddWithValue("@usrID", _usrid); - // Output Calculated Columns - SqlParameter param_ugid = new SqlParameter("@newUGID",SqlDbType.Int); - param_ugid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ugid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _ugid = (int)cm.Parameters["@newUGID"].Value; - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - // update child objects - } - - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - }} - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn,ref int ugid, int uid, int gid, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addMembership"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@uID", uid); - cm.Parameters.AddWithValue("@gID", gid); - cm.Parameters.AddWithValue("@startDate", startdate.DBValue); - cm.Parameters.AddWithValue("@endDate", enddate.DBValue); - cm.Parameters.AddWithValue("@dTS", dts); - cm.Parameters.AddWithValue("@usrID", usrid); - // Output Calculated Columns - SqlParameter param_ugid = new SqlParameter("@newUGID",SqlDbType.Int); - param_ugid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_ugid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - ugid = (int)cm.Parameters["@newUGID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateMembership"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@uGID", _ugid); - cm.Parameters.AddWithValue("@uID", _uid); - cm.Parameters.AddWithValue("@gID", _gid); - cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); - cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - } - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - } - - } - } - - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn,ref int ugid, int uid, int gid, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid, ref byte[] lastchanged) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateMembership"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@uGID", ugid); - cm.Parameters.AddWithValue("@uID", uid); - cm.Parameters.AddWithValue("@gID", gid); - cm.Parameters.AddWithValue("@startDate", startdate.DBValue); - cm.Parameters.AddWithValue("@endDate", enddate.DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_ugid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteMembership"; - cm.Parameters.AddWithValue("@uGID", criteria.Ugid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int ugid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteMembership"; - // Input PK Fields - - cm.Parameters.AddWithValue("@uGID", ugid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int ugid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(ugid)); - return result.Exists; - } - + /// + /// Membership Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class Membership : BusinessBase { + #region Business Methods - private int _ugid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int ugid) - { - _ugid=ugid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _ugid; + [System.ComponentModel.DataObjectField(true, true)] + public int Ugid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsMembership"; - - cm.Parameters.AddWithValue("@uGID", _ugid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ugid; + } } - } - catch(Exception ex) - { - Database.LogException("Membership",ex); - } - } - } + private int _uid; + [System.ComponentModel.DataObjectField(true, true)] + public int Uid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _uid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_uid != value) + { + _uid = value; + PropertyHasChanged(); + } + } + } + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_gid != value) + { + _gid = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + // TODO: Replace base Membership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Membership + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check Membership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Membership + protected override object GetIdValue() + { + return _ugid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create MembershipExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class Membership -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Ugid, ""); + //AuthorizationRules.AllowRead(Uid, ""); + //AuthorizationRules.AllowRead(Gid, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Uid, ""); + //AuthorizationRules.AllowWrite(Gid, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private Membership() + {/* require use of factory methods */} + + public static Membership New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Membership"); + return DataPortal.Create(); + } + + public static Membership Get(int _ugid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Membership"); + return DataPortal.Fetch(new PKCriteria(_ugid)); + } + + public static void Delete(int _ugid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Membership"); + DataPortal.Delete(new PKCriteria(_ugid)); + } + + public override Membership Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Membership"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Membership"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Membership"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _ugid; + public int Ugid + { get { return _ugid; } } + public PKCriteria(int ugid) + { + _ugid = ugid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getMembership"; + cm.Parameters.AddWithValue("@uGID", criteria.Ugid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _ugid = dr.GetInt32("UGID"); + _uid = dr.GetInt32("UID"); + _gid = dr.GetInt32("GID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + } + } + } + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addMembership"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@uID", _uid); + cm.Parameters.AddWithValue("@gID", _gid); + cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); + cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); + cm.Parameters.AddWithValue("@dTS", _dts); + cm.Parameters.AddWithValue("@usrID", _usrid); + // Output Calculated Columns + SqlParameter param_ugid = new SqlParameter("@newUGID", SqlDbType.Int); + param_ugid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ugid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _ugid = (int)cm.Parameters["@newUGID"].Value; + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + // update child objects + } + + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int ugid, int uid, int gid, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addMembership"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@uID", uid); + cm.Parameters.AddWithValue("@gID", gid); + cm.Parameters.AddWithValue("@startDate", startdate.DBValue); + cm.Parameters.AddWithValue("@endDate", enddate.DBValue); + cm.Parameters.AddWithValue("@dTS", dts); + cm.Parameters.AddWithValue("@usrID", usrid); + // Output Calculated Columns + SqlParameter param_ugid = new SqlParameter("@newUGID", SqlDbType.Int); + param_ugid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_ugid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + ugid = (int)cm.Parameters["@newUGID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateMembership"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@uGID", _ugid); + cm.Parameters.AddWithValue("@uID", _uid); + cm.Parameters.AddWithValue("@gID", _gid); + cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); + cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + } + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + } + + } + } + + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int ugid, int uid, int gid, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid, ref byte[] lastchanged) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateMembership"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@uGID", ugid); + cm.Parameters.AddWithValue("@uID", uid); + cm.Parameters.AddWithValue("@gID", gid); + cm.Parameters.AddWithValue("@startDate", startdate.DBValue); + cm.Parameters.AddWithValue("@endDate", enddate.DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_ugid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteMembership"; + cm.Parameters.AddWithValue("@uGID", criteria.Ugid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int ugid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteMembership"; + // Input PK Fields + + cm.Parameters.AddWithValue("@uGID", ugid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int ugid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(ugid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _ugid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int ugid) + { + _ugid = ugid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsMembership"; + + cm.Parameters.AddWithValue("@uGID", _ugid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("Membership", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create MembershipExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class Membership + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/MembershipInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/MembershipInfo.cs index c082a45a..e3d52e28 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/MembershipInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/MembershipInfo.cs @@ -17,139 +17,132 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// MembershipInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class MembershipInfo : ReadOnlyBase - { - #region Business Methods - - - private int _ugid; - [System.ComponentModel.DataObjectField(true, true)] - public int Ugid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _ugid; - } - } - private int _uid; - [System.ComponentModel.DataObjectField(true, true)] - public int Uid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _uid; - } - } - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base MembershipInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current MembershipInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check MembershipInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current MembershipInfo - protected override object GetIdValue() - { - return _ugid; - } - - - #endregion - #region Factory Methods - private MembershipInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal MembershipInfo(SafeDataReader dr) + /// + /// MembershipInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class MembershipInfo : ReadOnlyBase { - try - { - _ugid = dr.GetInt32("UGID"); - _uid = dr.GetInt32("UID"); - _gid = dr.GetInt32("GID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("MembershipInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _ugid; + [System.ComponentModel.DataObjectField(true, true)] + public int Ugid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ugid; + } + } + private int _uid; + [System.ComponentModel.DataObjectField(true, true)] + public int Uid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _uid; + } + } + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base MembershipInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current MembershipInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check MembershipInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current MembershipInfo + protected override object GetIdValue() + { + return _ugid; + } + + + #endregion + #region Factory Methods + private MembershipInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal MembershipInfo(SafeDataReader dr) + { + try + { + _ugid = dr.GetInt32("UGID"); + _uid = dr.GetInt32("UID"); + _gid = dr.GetInt32("GID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("MembershipInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/Permission.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/Permission.cs index a7d20e24..99a98447 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/Permission.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/Permission.cs @@ -17,831 +17,821 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// Permission Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class Permission : BusinessBase - { - #region Business Methods - - private int _pid; - [System.ComponentModel.DataObjectField(true, true)] - public int Pid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _pid; - } - } - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_rid != value) - { - _rid = value; - PropertyHasChanged(); - } - } - } - private int _permlevel; - /// - /// 0 - Security, 1 - System, 2 - RO, 3 - Procdures, 4 - Sections, 5 - Steps, 6 - Comments - /// - [System.ComponentModel.DataObjectField(true, true)] - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permlevel; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_permlevel != value) - { - _permlevel = value; - PropertyHasChanged(); - } - } - } - private int _versiontype; - /// - /// 0 - Working Draft, 1 - Temporary Change, 2 Approved - /// - [System.ComponentModel.DataObjectField(true, true)] - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _versiontype; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_versiontype != value) - { - _versiontype = value; - PropertyHasChanged(); - } - } - } - private int _permvalue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - [System.ComponentModel.DataObjectField(true, true)] - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permvalue; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_permvalue != value) - { - _permvalue = value; - PropertyHasChanged(); - } - } - } - private int _permad; - /// - /// 0 - Allow, 1 - Deny - /// - [System.ComponentModel.DataObjectField(true, true)] - public int Permad - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permad; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_permad != value) - { - _permad = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - // TODO: Replace base Permission.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Permission - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check Permission.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Permission - protected override object GetIdValue() - { - return _pid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Pid, ""); - //AuthorizationRules.AllowRead(Rid, ""); - //AuthorizationRules.AllowRead(PermLevel, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowRead(PermValue, ""); - //AuthorizationRules.AllowRead(Permad, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Rid, ""); - //AuthorizationRules.AllowWrite(PermLevel, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowWrite(PermValue, ""); - //AuthorizationRules.AllowWrite(Permad, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private Permission() - {/* require use of factory methods */} - - public static Permission New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Permission"); - return DataPortal.Create(); - } - - public static Permission Get(int _pid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Permission"); - return DataPortal.Fetch(new PKCriteria(_pid)); - } - - public static void Delete(int _pid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Permission"); - DataPortal.Delete(new PKCriteria(_pid)); - } - - public override Permission Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Permission"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Permission"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Permission"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _pid; - public int Pid - { get {return _pid;}} - public PKCriteria(int pid) - { - _pid=pid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _permad = ext.DefaultPermad; - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getPermission"; - cm.Parameters.AddWithValue("@pID", criteria.Pid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _pid = dr.GetInt32("PID"); - _rid = dr.GetInt32("RID"); - _permlevel = dr.GetInt32("PermLevel"); - _versiontype = dr.GetInt32("VersionType"); - _permvalue = dr.GetInt32("PermValue"); - _permad = dr.GetInt32("PermAD"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - } - } - } - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addPermission"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@rID", _rid); - cm.Parameters.AddWithValue("@permLevel", _permlevel); - cm.Parameters.AddWithValue("@versionType", _versiontype); - cm.Parameters.AddWithValue("@permValue", _permvalue); - cm.Parameters.AddWithValue("@permAD", _permad); - cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); - cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); - cm.Parameters.AddWithValue("@dTS", _dts); - cm.Parameters.AddWithValue("@usrID", _usrid); - // Output Calculated Columns - SqlParameter param_pid = new SqlParameter("@newPID",SqlDbType.Int); - param_pid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_pid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _pid = (int)cm.Parameters["@newPID"].Value; - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - // update child objects - } - - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - }} - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn,ref int pid, int rid, int permlevel, int versiontype, int permvalue, int permad, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addPermission"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@rID", rid); - cm.Parameters.AddWithValue("@permLevel", permlevel); - cm.Parameters.AddWithValue("@versionType", versiontype); - cm.Parameters.AddWithValue("@permValue", permvalue); - cm.Parameters.AddWithValue("@permAD", permad); - cm.Parameters.AddWithValue("@startDate", startdate.DBValue); - cm.Parameters.AddWithValue("@endDate", enddate.DBValue); - cm.Parameters.AddWithValue("@dTS", dts); - cm.Parameters.AddWithValue("@usrID", usrid); - // Output Calculated Columns - SqlParameter param_pid = new SqlParameter("@newPID",SqlDbType.Int); - param_pid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_pid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - pid = (int)cm.Parameters["@newPID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updatePermission"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@pID", _pid); - cm.Parameters.AddWithValue("@rID", _rid); - cm.Parameters.AddWithValue("@permLevel", _permlevel); - cm.Parameters.AddWithValue("@versionType", _versiontype); - cm.Parameters.AddWithValue("@permValue", _permvalue); - cm.Parameters.AddWithValue("@permAD", _permad); - cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); - cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - } - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - } - - } - } - - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn,ref int pid, int rid, int permlevel, int versiontype, int permvalue, int permad, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid, ref byte[] lastchanged) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updatePermission"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@pID", pid); - cm.Parameters.AddWithValue("@rID", rid); - cm.Parameters.AddWithValue("@permLevel", permlevel); - cm.Parameters.AddWithValue("@versionType", versiontype); - cm.Parameters.AddWithValue("@permValue", permvalue); - cm.Parameters.AddWithValue("@permAD", permad); - cm.Parameters.AddWithValue("@startDate", startdate.DBValue); - cm.Parameters.AddWithValue("@endDate", enddate.DBValue); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_pid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deletePermission"; - cm.Parameters.AddWithValue("@pID", criteria.Pid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int pid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deletePermission"; - // Input PK Fields - - cm.Parameters.AddWithValue("@pID", pid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int pid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(pid)); - return result.Exists; - } - + /// + /// Permission Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class Permission : BusinessBase { + #region Business Methods - private int _pid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int pid) - { - _pid=pid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _pid; + [System.ComponentModel.DataObjectField(true, true)] + public int Pid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsPermission"; - - cm.Parameters.AddWithValue("@pID", _pid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _pid; + } } - } - catch(Exception ex) - { - Database.LogException("Permission",ex); - } - } - } + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_rid != value) + { + _rid = value; + PropertyHasChanged(); + } + } + } + private int _permlevel; + /// + /// 0 - Security, 1 - System, 2 - RO, 3 - Procdures, 4 - Sections, 5 - Steps, 6 - Comments + /// + [System.ComponentModel.DataObjectField(true, true)] + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permlevel; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_permlevel != value) + { + _permlevel = value; + PropertyHasChanged(); + } + } + } + private int _versiontype; + /// + /// 0 - Working Draft, 1 - Temporary Change, 2 Approved + /// + [System.ComponentModel.DataObjectField(true, true)] + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _versiontype; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_versiontype != value) + { + _versiontype = value; + PropertyHasChanged(); + } + } + } + private int _permvalue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + [System.ComponentModel.DataObjectField(true, true)] + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permvalue; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_permvalue != value) + { + _permvalue = value; + PropertyHasChanged(); + } + } + } + private int _permad; + /// + /// 0 - Allow, 1 - Deny + /// + [System.ComponentModel.DataObjectField(true, true)] + public int Permad + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permad; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_permad != value) + { + _permad = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + // TODO: Replace base Permission.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Permission + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check Permission.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Permission + protected override object GetIdValue() + { + return _pid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultPermad - { - get { return 0; } - } - public virtual string DefaultStartDate - { - get { return DateTime.Now.ToShortDateString(); } - } - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create PermissionExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class Permission -// { -// partial class Extension : extensionBase -// { -// TODO: Override automatic defaults -// public virtual int DefaultPermad -// { -// get { return 0; } -// } -// 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Pid, ""); + //AuthorizationRules.AllowRead(Rid, ""); + //AuthorizationRules.AllowRead(PermLevel, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowRead(PermValue, ""); + //AuthorizationRules.AllowRead(Permad, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Rid, ""); + //AuthorizationRules.AllowWrite(PermLevel, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowWrite(PermValue, ""); + //AuthorizationRules.AllowWrite(Permad, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private Permission() + {/* require use of factory methods */} + + public static Permission New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Permission"); + return DataPortal.Create(); + } + + public static Permission Get(int _pid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Permission"); + return DataPortal.Fetch(new PKCriteria(_pid)); + } + + public static void Delete(int _pid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Permission"); + DataPortal.Delete(new PKCriteria(_pid)); + } + + public override Permission Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Permission"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Permission"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Permission"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _pid; + public int Pid + { get { return _pid; } } + public PKCriteria(int pid) + { + _pid = pid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _permad = ext.DefaultPermad; + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getPermission"; + cm.Parameters.AddWithValue("@pID", criteria.Pid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _pid = dr.GetInt32("PID"); + _rid = dr.GetInt32("RID"); + _permlevel = dr.GetInt32("PermLevel"); + _versiontype = dr.GetInt32("VersionType"); + _permvalue = dr.GetInt32("PermValue"); + _permad = dr.GetInt32("PermAD"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + } + } + } + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addPermission"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@rID", _rid); + cm.Parameters.AddWithValue("@permLevel", _permlevel); + cm.Parameters.AddWithValue("@versionType", _versiontype); + cm.Parameters.AddWithValue("@permValue", _permvalue); + cm.Parameters.AddWithValue("@permAD", _permad); + cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); + cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); + cm.Parameters.AddWithValue("@dTS", _dts); + cm.Parameters.AddWithValue("@usrID", _usrid); + // Output Calculated Columns + SqlParameter param_pid = new SqlParameter("@newPID", SqlDbType.Int); + param_pid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_pid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _pid = (int)cm.Parameters["@newPID"].Value; + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + // update child objects + } + + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int pid, int rid, int permlevel, int versiontype, int permvalue, int permad, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addPermission"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@rID", rid); + cm.Parameters.AddWithValue("@permLevel", permlevel); + cm.Parameters.AddWithValue("@versionType", versiontype); + cm.Parameters.AddWithValue("@permValue", permvalue); + cm.Parameters.AddWithValue("@permAD", permad); + cm.Parameters.AddWithValue("@startDate", startdate.DBValue); + cm.Parameters.AddWithValue("@endDate", enddate.DBValue); + cm.Parameters.AddWithValue("@dTS", dts); + cm.Parameters.AddWithValue("@usrID", usrid); + // Output Calculated Columns + SqlParameter param_pid = new SqlParameter("@newPID", SqlDbType.Int); + param_pid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_pid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + pid = (int)cm.Parameters["@newPID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePermission"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@pID", _pid); + cm.Parameters.AddWithValue("@rID", _rid); + cm.Parameters.AddWithValue("@permLevel", _permlevel); + cm.Parameters.AddWithValue("@versionType", _versiontype); + cm.Parameters.AddWithValue("@permValue", _permvalue); + cm.Parameters.AddWithValue("@permAD", _permad); + cm.Parameters.AddWithValue("@startDate", new SmartDate(_startdate).DBValue); + cm.Parameters.AddWithValue("@endDate", new SmartDate(_enddate).DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + } + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + } + + } + } + + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int pid, int rid, int permlevel, int versiontype, int permvalue, int permad, SmartDate startdate, SmartDate enddate, DateTime dts, string usrid, ref byte[] lastchanged) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updatePermission"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@pID", pid); + cm.Parameters.AddWithValue("@rID", rid); + cm.Parameters.AddWithValue("@permLevel", permlevel); + cm.Parameters.AddWithValue("@versionType", versiontype); + cm.Parameters.AddWithValue("@permValue", permvalue); + cm.Parameters.AddWithValue("@permAD", permad); + cm.Parameters.AddWithValue("@startDate", startdate.DBValue); + cm.Parameters.AddWithValue("@endDate", enddate.DBValue); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_pid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePermission"; + cm.Parameters.AddWithValue("@pID", criteria.Pid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int pid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deletePermission"; + // Input PK Fields + + cm.Parameters.AddWithValue("@pID", pid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int pid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(pid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _pid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int pid) + { + _pid = pid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsPermission"; + + cm.Parameters.AddWithValue("@pID", _pid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("Permission", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultPermad + { + get { return 0; } + } + public virtual string DefaultStartDate + { + get { return DateTime.Now.ToShortDateString(); } + } + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create PermissionExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class Permission + // { + // partial class Extension : extensionBase + // { + // TODO: Override automatic defaults + // public virtual int DefaultPermad + // { + // get { return 0; } + // } + // 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionInfo.cs index fd6e4777..45ea6159 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionInfo.cs @@ -17,187 +17,177 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// PermissionInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class PermissionInfo : ReadOnlyBase - { - #region Business Methods - - - private int _pid; - [System.ComponentModel.DataObjectField(true, true)] - public int Pid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _pid; - } - } - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - } - private int _permlevel; - /// - /// 0 - Security, 1 - System, 2 - RO, 3 - Procdures, 4 - Sections, 5 - Steps, 6 - Comments - /// - [System.ComponentModel.DataObjectField(true, true)] - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permlevel; - } - } - private int _versiontype; - /// - /// 0 - Working Draft, 1 - Temporary Change, 2 Approved - /// - [System.ComponentModel.DataObjectField(true, true)] - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _versiontype; - } - } - private int _permvalue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - [System.ComponentModel.DataObjectField(true, true)] - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permvalue; - } - } - private int _permad; - /// - /// 0 - Allow, 1 - Deny - /// - [System.ComponentModel.DataObjectField(true, true)] - public int Permad - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permad; - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base PermissionInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PermissionInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check PermissionInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PermissionInfo - protected override object GetIdValue() - { - return _pid; - } - - - #endregion - #region Factory Methods - private PermissionInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal PermissionInfo(SafeDataReader dr) + /// + /// PermissionInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class PermissionInfo : ReadOnlyBase { - try - { - _pid = dr.GetInt32("PID"); - _rid = dr.GetInt32("RID"); - _permlevel = dr.GetInt32("PermLevel"); - _versiontype = dr.GetInt32("VersionType"); - _permvalue = dr.GetInt32("PermValue"); - _permad = dr.GetInt32("PermAD"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("PermissionInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _pid; + [System.ComponentModel.DataObjectField(true, true)] + public int Pid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _pid; + } + } + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + } + private int _permlevel; + /// + /// 0 - Security, 1 - System, 2 - RO, 3 - Procdures, 4 - Sections, 5 - Steps, 6 - Comments + /// + [System.ComponentModel.DataObjectField(true, true)] + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permlevel; + } + } + private int _versiontype; + /// + /// 0 - Working Draft, 1 - Temporary Change, 2 Approved + /// + [System.ComponentModel.DataObjectField(true, true)] + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _versiontype; + } + } + private int _permvalue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + [System.ComponentModel.DataObjectField(true, true)] + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permvalue; + } + } + private int _permad; + /// + /// 0 - Allow, 1 - Deny + /// + [System.ComponentModel.DataObjectField(true, true)] + public int Permad + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permad; + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base PermissionInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PermissionInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check PermissionInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PermissionInfo + protected override object GetIdValue() + { + return _pid; + } + + + #endregion + #region Factory Methods + private PermissionInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal PermissionInfo(SafeDataReader dr) + { + try + { + _pid = dr.GetInt32("PID"); + _rid = dr.GetInt32("RID"); + _permlevel = dr.GetInt32("PermLevel"); + _versiontype = dr.GetInt32("VersionType"); + _permvalue = dr.GetInt32("PermValue"); + _permad = dr.GetInt32("PermAD"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("PermissionInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionRole.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionRole.cs index 528312a8..b3fd14bd 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionRole.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/PermissionRole.cs @@ -17,361 +17,353 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// PermissionRole Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class PermissionRole : BusinessBase - { - #region Business Methods - - - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_name != value) - { - _name = value; - PropertyHasChanged(); - } - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_title != value) - { - _title = value; - PropertyHasChanged(); - } - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - // TODO: Check PermissionRole.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current PermissionRole - protected override object GetIdValue() - { - return _rid; - } - // TODO: Replace base PermissionRole.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current PermissionRole - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Title"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Rid, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static PermissionRole New(string name, string title) + /// + /// PermissionRole Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class PermissionRole : BusinessBase { - return new PermissionRole(name, title); - } + #region Business Methods - internal static PermissionRole Get(SafeDataReader dr) - { - return new PermissionRole(dr); - } - private PermissionRole() - { - MarkAsChild(); - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_name != value) + { + _name = value; + PropertyHasChanged(); + } + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_title != value) + { + _title = value; + PropertyHasChanged(); + } + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + // TODO: Check PermissionRole.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current PermissionRole + protected override object GetIdValue() + { + return _rid; + } + // TODO: Replace base PermissionRole.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current PermissionRole + //public override string ToString() + //{ + // return base.ToString(); + //} - private PermissionRole(string name, string title) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _name = name; - _title = title; - } + #endregion + #region ValidationRules - private PermissionRole(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Title"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } - - #endregion - #region Data Access Portal + // 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; + //} - private void Fetch(SafeDataReader dr) - { - try{ - _rid = dr.GetInt32("RID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - } - catch(Exception ex) - { - Database.LogException("PermissionRole",ex); - } - MarkOld(); - } + #endregion - internal void Insert(Permission permission,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Role.Add(cn, ref _rid, _name, _title, _dts, _usrid); - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Rid, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Update(Permission permission,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Role.Update(cn, ref _rid, _name, _title, _dts, _usrid, ref _lastchanged); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void DeleteSelf(Permission permission,SqlConnection cn) - { - // 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; - Role.Remove(cn,_rid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } -// The follwing is a sample Extension File. You can use it to create PermissionRoleExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanDeleteObject() + { + // TODO: 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; + } -//namespace PatrialClass -//{ -// public partial class PermissionRole -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods - } // Class + internal static PermissionRole New(string name, string title) + { + return new PermissionRole(name, title); + } + + internal static PermissionRole Get(SafeDataReader dr) + { + return new PermissionRole(dr); + } + + private PermissionRole() + { + MarkAsChild(); + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private PermissionRole(string name, string title) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _name = name; + _title = title; + } + + private PermissionRole(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _rid = dr.GetInt32("RID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + } + catch (Exception ex) + { + Database.LogException("PermissionRole", ex); + } + MarkOld(); + } + + internal void Insert(Permission permission, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Role.Add(cn, ref _rid, _name, _title, _dts, _usrid); + MarkOld(); + } + + internal void Update(Permission permission, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Role.Update(cn, ref _rid, _name, _title, _dts, _usrid, ref _lastchanged); + } + + internal void DeleteSelf(Permission permission, SqlConnection cn) + { + // 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; + Role.Remove(cn, _rid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create PermissionRoleExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class PermissionRole + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/Role.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/Role.cs index 74fa916f..e36e8860 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/Role.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/Role.cs @@ -17,677 +17,675 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// Role Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class Role : BusinessBase - { - #region Business Methods - - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_name != value) - { - _name = value; - PropertyHasChanged(); - } - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_title != value) - { - _title = value; - PropertyHasChanged(); - } - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private RoleAssignments _roleassignments = RoleAssignments.New(); - /// - /// Related Field - /// - [System.ComponentModel.DataObjectField(true, true)] - public RoleAssignments RoleAssignments - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _roleassignments; - } - } - private RolePermissions _rolepermissions = RolePermissions.New(); - /// - /// Related Field - /// - [System.ComponentModel.DataObjectField(true, true)] - public RolePermissions RolePermissions - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rolepermissions; - } - } - public override bool IsDirty - { - get { return base.IsDirty || _roleassignments.IsDirty || _rolepermissions.IsDirty ; } - } - public override bool IsValid - { - get { return base.IsValid && _roleassignments.IsValid && _rolepermissions.IsValid ; } - } - // TODO: Replace base Role.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current Role - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check Role.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current Role - protected override object GetIdValue() - { - return _rid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Name"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Title"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - // 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Rid, ""); - //AuthorizationRules.AllowRead(Name, ""); - //AuthorizationRules.AllowRead(Title, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Name, ""); - //AuthorizationRules.AllowWrite(Title, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private Role() - {/* require use of factory methods */} - - public static Role New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); - return DataPortal.Create(); - } - - public static Role Get(int _rid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a Role"); - return DataPortal.Fetch(new PKCriteria(_rid)); - } - - public static void Delete(int _rid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); - DataPortal.Delete(new PKCriteria(_rid)); - } - - public override Role Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a Role"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a Role"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a Role"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _rid; - public int Rid - { get {return _rid;}} - public PKCriteria(int rid) - { - _rid=rid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getRole"; - cm.Parameters.AddWithValue("@rID", criteria.Rid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _rid = dr.GetInt32("RID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - // load child objects - dr.NextResult(); - _roleassignments = RoleAssignments.Get(dr); - - // load child objects - dr.NextResult(); - _rolepermissions = RolePermissions.Get(dr); - - } - } - } - } - catch(Exception ex) - { - Database.LogException("Role",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRole"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@name", _name); - cm.Parameters.AddWithValue("@title", _title); - cm.Parameters.AddWithValue("@dTS", _dts); - cm.Parameters.AddWithValue("@usrID", _usrid); - // Output Calculated Columns - SqlParameter param_rid = new SqlParameter("@newRID",SqlDbType.Int); - param_rid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_rid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _rid = (int)cm.Parameters["@newRID"].Value; - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - // update child objects - _roleassignments.Update(this,cn); - - _rolepermissions.Update(this,cn); - - } - - } - catch(Exception ex) - { - Database.LogException("Role",ex); - }} - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn,ref int rid, string name, string title, DateTime dts, string usrid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addRole"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@name", name); - cm.Parameters.AddWithValue("@title", title); - cm.Parameters.AddWithValue("@dTS", dts); - cm.Parameters.AddWithValue("@usrID", usrid); - // Output Calculated Columns - SqlParameter param_rid = new SqlParameter("@newRID",SqlDbType.Int); - param_rid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_rid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - rid = (int)cm.Parameters["@newRID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Role",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRole"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@rID", _rid); - cm.Parameters.AddWithValue("@name", _name); - cm.Parameters.AddWithValue("@title", _title); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - _roleassignments.Update(this,cn); - - _rolepermissions.Update(this,cn); - - } - } - catch(Exception ex) - { - Database.LogException("Role",ex); - } - - } - } - - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn,ref int rid, string name, string title, DateTime dts, string usrid, ref byte[] lastchanged) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateRole"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@rID", rid); - cm.Parameters.AddWithValue("@name", name); - cm.Parameters.AddWithValue("@title", title); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("Role",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_rid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRole"; - cm.Parameters.AddWithValue("@rID", criteria.Rid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("Role",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int rid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteRole"; - // Input PK Fields - - cm.Parameters.AddWithValue("@rID", rid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("Role",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int rid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(rid)); - return result.Exists; - } - + /// + /// Role Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class Role : BusinessBase { + #region Business Methods - private int _rid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int rid) - { - _rid=rid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsRole"; - - cm.Parameters.AddWithValue("@rID", _rid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } } - } - catch(Exception ex) - { - Database.LogException("Role",ex); - } - } - } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_name != value) + { + _name = value; + PropertyHasChanged(); + } + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_title != value) + { + _title = value; + PropertyHasChanged(); + } + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private RoleAssignments _roleassignments = RoleAssignments.New(); + /// + /// Related Field + /// + [System.ComponentModel.DataObjectField(true, true)] + public RoleAssignments RoleAssignments + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _roleassignments; + } + } + private RolePermissions _rolepermissions = RolePermissions.New(); + /// + /// Related Field + /// + [System.ComponentModel.DataObjectField(true, true)] + public RolePermissions RolePermissions + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rolepermissions; + } + } + public override bool IsDirty + { + get { return base.IsDirty || _roleassignments.IsDirty || _rolepermissions.IsDirty; } + } + public override bool IsValid + { + get { return base.IsValid && _roleassignments.IsValid && _rolepermissions.IsValid; } + } + // TODO: Replace base Role.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current Role + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check Role.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current Role + protected override object GetIdValue() + { + return _rid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create RoleExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class Role -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Name"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringRequired, "Title"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + // 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Rid, ""); + //AuthorizationRules.AllowRead(Name, ""); + //AuthorizationRules.AllowRead(Title, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Name, ""); + //AuthorizationRules.AllowWrite(Title, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private Role() + {/* require use of factory methods */} + + public static Role New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Role"); + return DataPortal.Create(); + } + + public static Role Get(int _rid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a Role"); + return DataPortal.Fetch(new PKCriteria(_rid)); + } + + public static void Delete(int _rid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Role"); + DataPortal.Delete(new PKCriteria(_rid)); + } + + public override Role Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a Role"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a Role"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a Role"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _rid; + public int Rid + { get { return _rid; } } + public PKCriteria(int rid) + { + _rid = rid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getRole"; + cm.Parameters.AddWithValue("@rID", criteria.Rid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _rid = dr.GetInt32("RID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + // load child objects + dr.NextResult(); + _roleassignments = RoleAssignments.Get(dr); + + // load child objects + dr.NextResult(); + _rolepermissions = RolePermissions.Get(dr); + + } + } + } + } + catch (Exception ex) + { + Database.LogException("Role", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRole"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@name", _name); + cm.Parameters.AddWithValue("@title", _title); + cm.Parameters.AddWithValue("@dTS", _dts); + cm.Parameters.AddWithValue("@usrID", _usrid); + // Output Calculated Columns + SqlParameter param_rid = new SqlParameter("@newRID", SqlDbType.Int); + param_rid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_rid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _rid = (int)cm.Parameters["@newRID"].Value; + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + // update child objects + _roleassignments.Update(this, cn); + + _rolepermissions.Update(this, cn); + + } + + } + catch (Exception ex) + { + Database.LogException("Role", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addRole"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@name", name); + cm.Parameters.AddWithValue("@title", title); + cm.Parameters.AddWithValue("@dTS", dts); + cm.Parameters.AddWithValue("@usrID", usrid); + // Output Calculated Columns + SqlParameter param_rid = new SqlParameter("@newRID", SqlDbType.Int); + param_rid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_rid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + rid = (int)cm.Parameters["@newRID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Role", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRole"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@rID", _rid); + cm.Parameters.AddWithValue("@name", _name); + cm.Parameters.AddWithValue("@title", _title); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + _roleassignments.Update(this, cn); + + _rolepermissions.Update(this, cn); + + } + } + catch (Exception ex) + { + Database.LogException("Role", ex); + } + + } + } + + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int rid, string name, string title, DateTime dts, string usrid, ref byte[] lastchanged) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateRole"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@rID", rid); + cm.Parameters.AddWithValue("@name", name); + cm.Parameters.AddWithValue("@title", title); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("Role", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_rid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRole"; + cm.Parameters.AddWithValue("@rID", criteria.Rid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("Role", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int rid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteRole"; + // Input PK Fields + + cm.Parameters.AddWithValue("@rID", rid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("Role", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int rid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(rid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _rid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int rid) + { + _rid = rid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsRole"; + + cm.Parameters.AddWithValue("@rID", _rid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("Role", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create RoleExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class Role + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/RoleAssignment.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/RoleAssignment.cs index 858ed48f..c618b621 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/RoleAssignment.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/RoleAssignment.cs @@ -17,611 +17,587 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// RoleAssignment Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class RoleAssignment : BusinessBase - { - #region Business Methods - - - private int _aid; - [System.ComponentModel.DataObjectField(true, true)] - public int Aid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _aid; - } - } - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_gid != value) - { - _gid = value; - PropertyHasChanged(); - } - } - } - private int _folderid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folderid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folderid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_folderid != value) - { - _folderid = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private int _folder_parentid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folder_Parentid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_parentid; - } - } - private int _folder_dbid; - [System.ComponentModel.DataObjectField(true, true)] - public int Folder_Dbid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_dbid; - } - } - private string _folder_name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_name; - } - } - private string _folder_title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_title; - } - } - private string _folder_config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_config; - } - } - private DateTime _folder_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Folder_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_dts; - } - } - private string _folder_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Folder_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _folder_usrid; - } - } - private string _group_groupname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_groupname; - } - } - private int _group_grouptype; - [System.ComponentModel.DataObjectField(true, true)] - public int Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_grouptype; - } - } - private string _group_config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_config; - } - } - private DateTime _group_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Group_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_dts; - } - } - private string _group_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_usrid; - } - } - // TODO: Check RoleAssignment.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoleAssignment - protected override object GetIdValue() - { - return _aid; - } - // TODO: Replace base RoleAssignment.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoleAssignment - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: Add other validation rules - } - - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Aid, ""); - //AuthorizationRules.AllowRead(Gid, ""); - //AuthorizationRules.AllowWrite(Gid, ""); - //AuthorizationRules.AllowRead(Folderid, ""); - //AuthorizationRules.AllowWrite(Folderid, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static RoleAssignment New(int gid, int folderid) + /// + /// RoleAssignment Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class RoleAssignment : BusinessBase { - return new RoleAssignment(Volian.Object.Library.Group.Get(gid), Volian.Object.Library.Folder.Get(folderid)); - } + #region Business Methods - internal static RoleAssignment Get(SafeDataReader dr) - { - return new RoleAssignment(dr); - } - private RoleAssignment() - { - MarkAsChild(); - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _aid; + [System.ComponentModel.DataObjectField(true, true)] + public int Aid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _aid; + } + } + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_gid != value) + { + _gid = value; + PropertyHasChanged(); + } + } + } + private int _folderid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folderid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folderid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_folderid != value) + { + _folderid = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private int _folder_parentid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folder_Parentid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_parentid; + } + } + private int _folder_dbid; + [System.ComponentModel.DataObjectField(true, true)] + public int Folder_Dbid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_dbid; + } + } + private string _folder_name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_name; + } + } + private string _folder_title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_title; + } + } + private string _folder_config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_config; + } + } + private DateTime _folder_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Folder_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_dts; + } + } + private string _folder_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Folder_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _folder_usrid; + } + } + private string _group_groupname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_groupname; + } + } + private int _group_grouptype; + [System.ComponentModel.DataObjectField(true, true)] + public int Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_grouptype; + } + } + private string _group_config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_config; + } + } + private DateTime _group_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Group_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_dts; + } + } + private string _group_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_usrid; + } + } + // TODO: Check RoleAssignment.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoleAssignment + protected override object GetIdValue() + { + return _aid; + } + // TODO: Replace base RoleAssignment.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoleAssignment + //public override string ToString() + //{ + // return base.ToString(); + //} - private RoleAssignment(Group group, Folder folder) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _folderid = folder.Folderid; - _folder_parentid = folder.Parentid; - _folder_dbid = folder.Dbid; - _folder_name = folder.Name; - _folder_title = folder.Title; - _folder_config = folder.Config; - _folder_dts = folder.Dts; - _folder_usrid = folder.Usrid; - _gid = group.Gid; - _group_groupname = group.GroupName; - _group_grouptype = group.GroupType; - _group_config = group.Config; - _group_dts = group.Dts; - _group_usrid = group.Usrid; - } + #endregion + #region ValidationRules - private RoleAssignment(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } - - #endregion - #region Data Access Portal + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - private void Fetch(SafeDataReader dr) - { - try{ - _aid = dr.GetInt32("AID"); - _gid = dr.GetInt32("GID"); - _folderid = dr.GetInt32("FolderID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - _folder_parentid = dr.GetInt32("Folders_ParentID"); - _folder_dbid = dr.GetInt32("Folders_DBID"); - _folder_name = dr.GetString("Folders_Name"); - _folder_title = dr.GetString("Folders_Title"); - _folder_config = dr.GetString("Folders_Config"); - _folder_dts = dr.GetDateTime("Folders_DTS"); - _folder_usrid = dr.GetString("Folders_UsrID"); - _group_groupname = dr.GetString("Groups_GroupName"); - _group_grouptype = dr.GetInt32("Groups_GroupType"); - _group_config = dr.GetString("Groups_Config"); - _group_dts = dr.GetDateTime("Groups_DTS"); - _group_usrid = dr.GetString("Groups_UsrID"); - } - catch(Exception ex) - { - Database.LogException("RoleAssignment",ex); - } - MarkOld(); - } + #endregion - internal void Insert(Role role,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Assignment.Add(cn, ref _aid, _gid, role.Rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Aid, ""); + //AuthorizationRules.AllowRead(Gid, ""); + //AuthorizationRules.AllowWrite(Gid, ""); + //AuthorizationRules.AllowRead(Folderid, ""); + //AuthorizationRules.AllowWrite(Folderid, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Update(Role role,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Assignment.Update(cn, ref _aid, _gid, role.Rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void DeleteSelf(Role role,SqlConnection cn) - { - // 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; - Assignment.Remove(cn,_aid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } -// The follwing is a sample Extension File. You can use it to create RoleAssignmentExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanDeleteObject() + { + // TODO: 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; + } -//namespace PatrialClass -//{ -// public partial class RoleAssignment -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods - } // Class + internal static RoleAssignment New(int gid, int folderid) + { + return new RoleAssignment(Volian.Object.Library.Group.Get(gid), Volian.Object.Library.Folder.Get(folderid)); + } + + internal static RoleAssignment Get(SafeDataReader dr) + { + return new RoleAssignment(dr); + } + + private RoleAssignment() + { + MarkAsChild(); + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private RoleAssignment(Group group, Folder folder) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _folderid = folder.Folderid; + _folder_parentid = folder.Parentid; + _folder_dbid = folder.Dbid; + _folder_name = folder.Name; + _folder_title = folder.Title; + _folder_config = folder.Config; + _folder_dts = folder.Dts; + _folder_usrid = folder.Usrid; + _gid = group.Gid; + _group_groupname = group.GroupName; + _group_grouptype = group.GroupType; + _group_config = group.Config; + _group_dts = group.Dts; + _group_usrid = group.Usrid; + } + + private RoleAssignment(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _aid = dr.GetInt32("AID"); + _gid = dr.GetInt32("GID"); + _folderid = dr.GetInt32("FolderID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + _folder_parentid = dr.GetInt32("Folders_ParentID"); + _folder_dbid = dr.GetInt32("Folders_DBID"); + _folder_name = dr.GetString("Folders_Name"); + _folder_title = dr.GetString("Folders_Title"); + _folder_config = dr.GetString("Folders_Config"); + _folder_dts = dr.GetDateTime("Folders_DTS"); + _folder_usrid = dr.GetString("Folders_UsrID"); + _group_groupname = dr.GetString("Groups_GroupName"); + _group_grouptype = dr.GetInt32("Groups_GroupType"); + _group_config = dr.GetString("Groups_Config"); + _group_dts = dr.GetDateTime("Groups_DTS"); + _group_usrid = dr.GetString("Groups_UsrID"); + } + catch (Exception ex) + { + Database.LogException("RoleAssignment", ex); + } + MarkOld(); + } + + internal void Insert(Role role, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Assignment.Add(cn, ref _aid, _gid, role.Rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); + MarkOld(); + } + + internal void Update(Role role, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Assignment.Update(cn, ref _aid, _gid, role.Rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); + } + + internal void DeleteSelf(Role role, SqlConnection cn) + { + // 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; + Assignment.Remove(cn, _aid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create RoleAssignmentExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class RoleAssignment + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/RoleInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/RoleInfo.cs index cc0ca228..cf725ff9 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/RoleInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/RoleInfo.cs @@ -17,115 +17,110 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// RoleInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class RoleInfo : ReadOnlyBase - { - #region Business Methods - - - private int _rid; - [System.ComponentModel.DataObjectField(true, true)] - public int Rid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _rid; - } - } - private string _name=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Name - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _name; - } - } - private string _title=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Title - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _title; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base RoleInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RoleInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check RoleInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RoleInfo - protected override object GetIdValue() - { - return _rid; - } - - - #endregion - #region Factory Methods - private RoleInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal RoleInfo(SafeDataReader dr) + /// + /// RoleInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class RoleInfo : ReadOnlyBase { - try - { - _rid = dr.GetInt32("RID"); - _name = dr.GetString("Name"); - _title = dr.GetString("Title"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("RoleInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _rid; + [System.ComponentModel.DataObjectField(true, true)] + public int Rid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _rid; + } + } + private string _name = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Name + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _name; + } + } + private string _title = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Title + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _title; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base RoleInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RoleInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check RoleInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RoleInfo + protected override object GetIdValue() + { + return _rid; + } + + + #endregion + #region Factory Methods + private RoleInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal RoleInfo(SafeDataReader dr) + { + try + { + _rid = dr.GetInt32("RID"); + _name = dr.GetString("Name"); + _title = dr.GetString("Title"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("RoleInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/RolePermission.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/RolePermission.cs index ee0986bc..a2306570 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/RolePermission.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/RolePermission.cs @@ -17,525 +17,509 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// RolePermission Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class RolePermission : BusinessBase - { - #region Business Methods - - - private int _pid; - [System.ComponentModel.DataObjectField(true, true)] - public int Pid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _pid; - } - } - private int _permlevel; - /// - /// 0 - Security, 1 - System, 2 - RO, 3 - Procdures, 4 - Sections, 5 - Steps, 6 - Comments - /// - [System.ComponentModel.DataObjectField(true, true)] - public int PermLevel - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permlevel; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_permlevel != value) - { - _permlevel = value; - PropertyHasChanged(); - } - } - } - private int _versiontype; - /// - /// 0 - Working Draft, 1 - Temporary Change, 2 Approved - /// - [System.ComponentModel.DataObjectField(true, true)] - public int VersionType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _versiontype; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_versiontype != value) - { - _versiontype = value; - PropertyHasChanged(); - } - } - } - private int _permvalue; - /// - /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) - /// - [System.ComponentModel.DataObjectField(true, true)] - public int PermValue - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permvalue; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_permvalue != value) - { - _permvalue = value; - PropertyHasChanged(); - } - } - } - private int _permad; - /// - /// 0 - Allow, 1 - Deny - /// - [System.ComponentModel.DataObjectField(true, true)] - public int Permad - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _permad; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_permad != value) - { - _permad = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - // TODO: Check RolePermission.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current RolePermission - protected override object GetIdValue() - { - return _pid; - } - // TODO: Replace base RolePermission.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current RolePermission - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: Add other validation rules - } - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Pid, ""); - //AuthorizationRules.AllowRead(PermLevel, ""); - //AuthorizationRules.AllowWrite(PermLevel, ""); - //AuthorizationRules.AllowRead(VersionType, ""); - //AuthorizationRules.AllowWrite(VersionType, ""); - //AuthorizationRules.AllowRead(PermValue, ""); - //AuthorizationRules.AllowWrite(PermValue, ""); - //AuthorizationRules.AllowRead(Permad, ""); - //AuthorizationRules.AllowWrite(Permad, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static RolePermission New(int permlevel, int versiontype, int permvalue) + /// + /// RolePermission Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class RolePermission : BusinessBase { - return new RolePermission(permlevel, versiontype, permvalue); - } + #region Business Methods - internal static RolePermission Get(SafeDataReader dr) - { - return new RolePermission(dr); - } - private RolePermission() - { - MarkAsChild(); - _permad = ext.DefaultPermad; - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _pid; + [System.ComponentModel.DataObjectField(true, true)] + public int Pid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _pid; + } + } + private int _permlevel; + /// + /// 0 - Security, 1 - System, 2 - RO, 3 - Procdures, 4 - Sections, 5 - Steps, 6 - Comments + /// + [System.ComponentModel.DataObjectField(true, true)] + public int PermLevel + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permlevel; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_permlevel != value) + { + _permlevel = value; + PropertyHasChanged(); + } + } + } + private int _versiontype; + /// + /// 0 - Working Draft, 1 - Temporary Change, 2 Approved + /// + [System.ComponentModel.DataObjectField(true, true)] + public int VersionType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _versiontype; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_versiontype != value) + { + _versiontype = value; + PropertyHasChanged(); + } + } + } + private int _permvalue; + /// + /// 1 - Read, 2 - Write, 4 - Create, 8 - Delete (15 - All) + /// + [System.ComponentModel.DataObjectField(true, true)] + public int PermValue + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permvalue; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_permvalue != value) + { + _permvalue = value; + PropertyHasChanged(); + } + } + } + private int _permad; + /// + /// 0 - Allow, 1 - Deny + /// + [System.ComponentModel.DataObjectField(true, true)] + public int Permad + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _permad; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_permad != value) + { + _permad = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + // TODO: Check RolePermission.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current RolePermission + protected override object GetIdValue() + { + return _pid; + } + // TODO: Replace base RolePermission.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current RolePermission + //public override string ToString() + //{ + // return base.ToString(); + //} - private RolePermission(int permlevel, int versiontype, int permvalue) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _permad = ext.DefaultPermad; - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _permlevel = permlevel; - _versiontype = versiontype; - _permvalue = permvalue; - } + #endregion + #region ValidationRules - private RolePermission(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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 Data Access Portal + #endregion - private void Fetch(SafeDataReader dr) - { - try{ - _pid = dr.GetInt32("PID"); - _permlevel = dr.GetInt32("PermLevel"); - _versiontype = dr.GetInt32("VersionType"); - _permvalue = dr.GetInt32("PermValue"); - _permad = dr.GetInt32("PermAD"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - } - catch(Exception ex) - { - Database.LogException("RolePermission",ex); - } - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Pid, ""); + //AuthorizationRules.AllowRead(PermLevel, ""); + //AuthorizationRules.AllowWrite(PermLevel, ""); + //AuthorizationRules.AllowRead(VersionType, ""); + //AuthorizationRules.AllowWrite(VersionType, ""); + //AuthorizationRules.AllowRead(PermValue, ""); + //AuthorizationRules.AllowWrite(PermValue, ""); + //AuthorizationRules.AllowRead(Permad, ""); + //AuthorizationRules.AllowWrite(Permad, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Insert(Role role,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Permission.Add(cn, ref _pid, role.Rid, _permlevel, _versiontype, _permvalue, _permad, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); - MarkOld(); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void Update(Role role,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Permission.Update(cn, ref _pid, role.Rid, _permlevel, _versiontype, _permvalue, _permad, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); - } + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } - internal void DeleteSelf(Role role,SqlConnection cn) - { - // 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; - Permission.Remove(cn,_pid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual int DefaultPermad - { - get { return 0; } - } - public virtual string DefaultStartDate - { - get { return DateTime.Now.ToShortDateString(); } - } - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanDeleteObject() + { + // TODO: 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; + } -// The follwing is a sample Extension File. You can use it to create RolePermissionExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods -//namespace PatrialClass -//{ -// public partial class RolePermission -// { -// partial class Extension : extensionBase -// { -// TODO: Override automatic defaults -// public virtual int DefaultPermad -// { -// get { return 0; } -// } -// 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + internal static RolePermission New(int permlevel, int versiontype, int permvalue) + { + return new RolePermission(permlevel, versiontype, permvalue); + } - } // Class + internal static RolePermission Get(SafeDataReader dr) + { + return new RolePermission(dr); + } + + private RolePermission() + { + MarkAsChild(); + _permad = ext.DefaultPermad; + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private RolePermission(int permlevel, int versiontype, int permvalue) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _permad = ext.DefaultPermad; + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _permlevel = permlevel; + _versiontype = versiontype; + _permvalue = permvalue; + } + + private RolePermission(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _pid = dr.GetInt32("PID"); + _permlevel = dr.GetInt32("PermLevel"); + _versiontype = dr.GetInt32("VersionType"); + _permvalue = dr.GetInt32("PermValue"); + _permad = dr.GetInt32("PermAD"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + } + catch (Exception ex) + { + Database.LogException("RolePermission", ex); + } + MarkOld(); + } + + internal void Insert(Role role, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Permission.Add(cn, ref _pid, role.Rid, _permlevel, _versiontype, _permvalue, _permad, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); + MarkOld(); + } + + internal void Update(Role role, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Permission.Update(cn, ref _pid, role.Rid, _permlevel, _versiontype, _permvalue, _permad, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); + } + + internal void DeleteSelf(Role role, SqlConnection cn) + { + // 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; + Permission.Remove(cn, _pid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual int DefaultPermad + { + get { return 0; } + } + public virtual string DefaultStartDate + { + get { return DateTime.Now.ToShortDateString(); } + } + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create RolePermissionExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class RolePermission + // { + // partial class Extension : extensionBase + // { + // TODO: Override automatic defaults + // public virtual int DefaultPermad + // { + // get { return 0; } + // } + // 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/User.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/User.cs index 4de53432..03b0e1a9 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/User.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/User.cs @@ -17,947 +17,928 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// User Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class User : BusinessBase - { - #region Business Methods - - private int _uid; - [System.ComponentModel.DataObjectField(true, true)] - public int Uid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _uid; - } - } - private string _userid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Userid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _userid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_userid != value) - { - _userid = value; - PropertyHasChanged(); - } - } - } - private string _firstname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _firstname; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_firstname != value) - { - _firstname = value; - PropertyHasChanged(); - } - } - } - private string _middlename=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _middlename; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_middlename != value) - { - _middlename = value; - PropertyHasChanged(); - } - } - } - private string _lastname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _lastname; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_lastname != value) - { - _lastname = value; - PropertyHasChanged(); - } - } - } - private string _suffix=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _suffix; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_suffix != value) - { - _suffix = value; - PropertyHasChanged(); - } - } - } - private string _courtesytitle=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _courtesytitle; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_courtesytitle != value) - { - _courtesytitle = value; - PropertyHasChanged(); - } - } - } - private string _phonenumber=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _phonenumber; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_phonenumber != value) - { - _phonenumber = value; - PropertyHasChanged(); - } - } - } - private string _cfgname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string CfgName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _cfgname; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_cfgname != value) - { - _cfgname = value; - PropertyHasChanged(); - } - } - } - private string _userlogin=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _userlogin; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_userlogin != value) - { - _userlogin = value; - PropertyHasChanged(); - } - } - } - private string _username=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _username; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_username != value) - { - _username = value; - PropertyHasChanged(); - } - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_config != value) - { - _config = value; - PropertyHasChanged(); - } - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private UserMemberships _usermemberships = UserMemberships.New(); - /// - /// Related Field - /// - [System.ComponentModel.DataObjectField(true, true)] - public UserMemberships UserMemberships - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usermemberships; - } - } - public override bool IsDirty - { - get { return base.IsDirty || _usermemberships.IsDirty ; } - } - public override bool IsValid - { - get { return base.IsValid && _usermemberships.IsValid ; } - } - // TODO: Replace base User.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current User - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check User.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current User - protected override object GetIdValue() - { - return _uid; - } - - #endregion - - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Userid", 100)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("FirstName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("MiddleName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("LastName", 50)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Suffix", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("CourtesyTitle", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("PhoneNumber", 30)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("CfgName", 8)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserLogin", 10)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserName", 32)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - ext.AddValidationRules(ValidationRules); - // TODO: Add other validation rules - // ValidationRules.AddRule(StartDateGTEndDate, "Started"); - } - // 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Uid, ""); - //AuthorizationRules.AllowRead(Userid, ""); - //AuthorizationRules.AllowRead(FirstName, ""); - //AuthorizationRules.AllowRead(MiddleName, ""); - //AuthorizationRules.AllowRead(LastName, ""); - //AuthorizationRules.AllowRead(Suffix, ""); - //AuthorizationRules.AllowRead(CourtesyTitle, ""); - //AuthorizationRules.AllowRead(PhoneNumber, ""); - //AuthorizationRules.AllowRead(CfgName, ""); - //AuthorizationRules.AllowRead(UserLogin, ""); - //AuthorizationRules.AllowRead(UserName, ""); - //AuthorizationRules.AllowRead(Config, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Userid, ""); - //AuthorizationRules.AllowWrite(FirstName, ""); - //AuthorizationRules.AllowWrite(MiddleName, ""); - //AuthorizationRules.AllowWrite(LastName, ""); - //AuthorizationRules.AllowWrite(Suffix, ""); - //AuthorizationRules.AllowWrite(CourtesyTitle, ""); - //AuthorizationRules.AllowWrite(PhoneNumber, ""); - //AuthorizationRules.AllowWrite(CfgName, ""); - //AuthorizationRules.AllowWrite(UserLogin, ""); - //AuthorizationRules.AllowWrite(UserName, ""); - //AuthorizationRules.AllowWrite(Config, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - ext.AddAuthorizationRules(AuthorizationRules); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - private User() - {/* require use of factory methods */} - - public static User New() - { - if (!CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a User"); - return DataPortal.Create(); - } - - public static User Get(int _uid) - { - if (!CanGetObject()) - throw new System.Security.SecurityException("User not authorized to view a User"); - return DataPortal.Fetch(new PKCriteria(_uid)); - } - - public static void Delete(int _uid) - { - if (!CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a User"); - DataPortal.Delete(new PKCriteria(_uid)); - } - - public override User Save() - { - if (IsDeleted && !CanDeleteObject()) - throw new System.Security.SecurityException("User not authorized to remove a User"); - else if (IsNew && !CanAddObject()) - throw new System.Security.SecurityException("User not authorized to add a User"); - else if (!CanEditObject()) - throw new System.Security.SecurityException("User not authorized to update a User"); - return base.Save(); - } - - #endregion - - #region Data Access Portal - - [Serializable()] - private class PKCriteria - { - private int _uid; - public int Uid - { get {return _uid;}} - public PKCriteria(int uid) - { - _uid=uid; - } - } - // If Create needs to access DB - It should not be marked RunLocal - [RunLocal()] - private new void DataPortal_Create(object criteria) - { - - // Database Defaults - _userid = ext.DefaultUserid; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - // TODO: Add any defaults that are necessary - ValidationRules.CheckRules(); - } - - private void DataPortal_Fetch(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "getUser"; - cm.Parameters.AddWithValue("@uID", criteria.Uid); - using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) - { - dr.Read(); - _uid = dr.GetInt32("UID"); - _userid = dr.GetString("UserID"); - _firstname = dr.GetString("FirstName"); - _middlename = dr.GetString("MiddleName"); - _lastname = dr.GetString("LastName"); - _suffix = dr.GetString("Suffix"); - _courtesytitle = dr.GetString("CourtesyTitle"); - _phonenumber = dr.GetString("PhoneNumber"); - _cfgname = dr.GetString("CFGName"); - _userlogin = dr.GetString("UserLogin"); - _username = dr.GetString("UserName"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - // load child objects - dr.NextResult(); - _usermemberships = UserMemberships.Get(dr); - - } - } - } - } - catch(Exception ex) - { - Database.LogException("User",ex); - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Insert() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addUser"; - // Input All Fields - Except Calculated Columns - cm.Parameters.AddWithValue("@userID", _userid); - cm.Parameters.AddWithValue("@firstName", _firstname); - cm.Parameters.AddWithValue("@middleName", _middlename); - cm.Parameters.AddWithValue("@lastName", _lastname); - cm.Parameters.AddWithValue("@suffix", _suffix); - cm.Parameters.AddWithValue("@courtesyTitle", _courtesytitle); - cm.Parameters.AddWithValue("@phoneNumber", _phonenumber); - cm.Parameters.AddWithValue("@cFGName", _cfgname); - cm.Parameters.AddWithValue("@userLogin", _userlogin); - cm.Parameters.AddWithValue("@userName", _username); - cm.Parameters.AddWithValue("@config", _config); - cm.Parameters.AddWithValue("@dTS", _dts); - cm.Parameters.AddWithValue("@usrID", _usrid); - // Output Calculated Columns - SqlParameter param_uid = new SqlParameter("@newUID",SqlDbType.Int); - param_uid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_uid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _uid = (int)cm.Parameters["@newUID"].Value; - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - // update child objects - _usermemberships.Update(this,cn); - - } - - } - catch(Exception ex) - { - Database.LogException("User",ex); - }} - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn,ref int uid, string userid, string firstname, string middlename, string lastname, string suffix, string courtesytitle, string phonenumber, string cfgname, string userlogin, string username, string config, DateTime dts, string usrid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "addUser"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@userID", userid); - cm.Parameters.AddWithValue("@firstName", firstname); - cm.Parameters.AddWithValue("@middleName", middlename); - cm.Parameters.AddWithValue("@lastName", lastname); - cm.Parameters.AddWithValue("@suffix", suffix); - cm.Parameters.AddWithValue("@courtesyTitle", courtesytitle); - cm.Parameters.AddWithValue("@phoneNumber", phonenumber); - cm.Parameters.AddWithValue("@cFGName", cfgname); - cm.Parameters.AddWithValue("@userLogin", userlogin); - cm.Parameters.AddWithValue("@userName", username); - cm.Parameters.AddWithValue("@config", config); - cm.Parameters.AddWithValue("@dTS", dts); - cm.Parameters.AddWithValue("@usrID", usrid); - // Output Calculated Columns - SqlParameter param_uid = new SqlParameter("@newUID",SqlDbType.Int); - param_uid.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_uid); - SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp); - param_lastchanged.Direction = ParameterDirection.Output; - cm.Parameters.Add(param_lastchanged); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - uid = (int)cm.Parameters["@newUID"].Value; - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("User",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_Update() - { - if (IsDirty)// If this is dirty - open the connection - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - if(base.IsDirty) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateUser"; - // All Fields including Calculated Fields - cm.Parameters.AddWithValue("@uID", _uid); - cm.Parameters.AddWithValue("@userID", _userid); - cm.Parameters.AddWithValue("@firstName", _firstname); - cm.Parameters.AddWithValue("@middleName", _middlename); - cm.Parameters.AddWithValue("@lastName", _lastname); - cm.Parameters.AddWithValue("@suffix", _suffix); - cm.Parameters.AddWithValue("@courtesyTitle", _courtesytitle); - cm.Parameters.AddWithValue("@phoneNumber", _phonenumber); - cm.Parameters.AddWithValue("@cFGName", _cfgname); - cm.Parameters.AddWithValue("@userLogin", _userlogin); - cm.Parameters.AddWithValue("@userName", _username); - cm.Parameters.AddWithValue("@config", _config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - // use the open connection to update child objects - _usermemberships.Update(this,cn); - } - } - catch(Exception ex) - { - Database.LogException("User",ex); - } - - } - } - - - [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn,ref int uid, string userid, string firstname, string middlename, string lastname, string suffix, string courtesytitle, string phonenumber, string cfgname, string userlogin, string username, string config, DateTime dts, string usrid, ref byte[] lastchanged) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "updateUser"; - // Input All Fields - Except Calculated Columns - - cm.Parameters.AddWithValue("@uID", uid); - cm.Parameters.AddWithValue("@userID", userid); - cm.Parameters.AddWithValue("@firstName", firstname); - cm.Parameters.AddWithValue("@middleName", middlename); - cm.Parameters.AddWithValue("@lastName", lastname); - cm.Parameters.AddWithValue("@suffix", suffix); - cm.Parameters.AddWithValue("@courtesyTitle", courtesytitle); - cm.Parameters.AddWithValue("@phoneNumber", phonenumber); - cm.Parameters.AddWithValue("@cFGName", cfgname); - cm.Parameters.AddWithValue("@userLogin", userlogin); - cm.Parameters.AddWithValue("@userName", username); - cm.Parameters.AddWithValue("@config", config); - 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); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - // Save all values being returned from the Procedure - return (byte[])cm.Parameters["@newLastChanged"].Value; - } - } - catch(Exception ex) - { - Database.LogException("User",ex); - return null; - } - } - [Transactional(TransactionalTypes.TransactionScope)] - protected override void DataPortal_DeleteSelf() - { - DataPortal_Delete(new PKCriteria(_uid)); - } - - - [Transactional(TransactionalTypes.TransactionScope)] - private void DataPortal_Delete(PKCriteria criteria) - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) - { - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteUser"; - cm.Parameters.AddWithValue("@uID", criteria.Uid); - cm.ExecuteNonQuery(); - } - } - } - catch(Exception ex) - { - Database.LogException("User",ex); - } - } - - [Transactional(TransactionalTypes.TransactionScope)] - public static void Remove(SqlConnection cn,int uid) - { - try{ - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "deleteUser"; - // Input PK Fields - - cm.Parameters.AddWithValue("@uID", uid); - // TODO: Define any additional output parameters - cm.ExecuteNonQuery(); - } - } - catch(Exception ex) - { - Database.LogException("User",ex); - } - } - - #endregion - - #region Exists - - - public static bool Exists(int uid) - { - ExistsCommand result; - result = DataPortal.Execute - (new ExistsCommand(uid)); - return result.Exists; - } - + /// + /// User Generated by MyGeneration using the CSLA Object Mapping template + /// [Serializable()] - private class ExistsCommand : CommandBase + public partial class User : BusinessBase { + #region Business Methods - private int _uid; - private bool _exists; - - public bool Exists - { - get { return _exists; } - } - - public ExistsCommand(int uid) - { - _uid=uid; - } - - protected override void DataPortal_Execute() - { - try{ - using (SqlConnection cn = Database.VEPROMS_SqlConnection) + private int _uid; + [System.ComponentModel.DataObjectField(true, true)] + public int Uid { - cn.Open(); - using (SqlCommand cm = cn.CreateCommand()) - { - cm.CommandType = CommandType.StoredProcedure; - cm.CommandText = "existsUser"; - - cm.Parameters.AddWithValue("@uID", _uid); - int count = (int)cm.ExecuteScalar(); - _exists = (count > 0); - } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _uid; + } } - } - catch(Exception ex) - { - Database.LogException("User",ex); - } - } - } + private string _userid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Userid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _userid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_userid != value) + { + _userid = value; + PropertyHasChanged(); + } + } + } + private string _firstname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _firstname; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_firstname != value) + { + _firstname = value; + PropertyHasChanged(); + } + } + } + private string _middlename = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _middlename; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_middlename != value) + { + _middlename = value; + PropertyHasChanged(); + } + } + } + private string _lastname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _lastname; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_lastname != value) + { + _lastname = value; + PropertyHasChanged(); + } + } + } + private string _suffix = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _suffix; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_suffix != value) + { + _suffix = value; + PropertyHasChanged(); + } + } + } + private string _courtesytitle = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _courtesytitle; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_courtesytitle != value) + { + _courtesytitle = value; + PropertyHasChanged(); + } + } + } + private string _phonenumber = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _phonenumber; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_phonenumber != value) + { + _phonenumber = value; + PropertyHasChanged(); + } + } + } + private string _cfgname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string CfgName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _cfgname; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_cfgname != value) + { + _cfgname = value; + PropertyHasChanged(); + } + } + } + private string _userlogin = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _userlogin; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_userlogin != value) + { + _userlogin = value; + PropertyHasChanged(); + } + } + } + private string _username = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _username; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_username != value) + { + _username = value; + PropertyHasChanged(); + } + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_config != value) + { + _config = value; + PropertyHasChanged(); + } + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private UserMemberships _usermemberships = UserMemberships.New(); + /// + /// Related Field + /// + [System.ComponentModel.DataObjectField(true, true)] + public UserMemberships UserMemberships + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usermemberships; + } + } + public override bool IsDirty + { + get { return base.IsDirty || _usermemberships.IsDirty; } + } + public override bool IsValid + { + get { return base.IsValid && _usermemberships.IsValid; } + } + // TODO: Replace base User.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current User + //public override string ToString() + //{ + // return base.ToString(); + //} - #endregion + // TODO: Check User.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current User + protected override object GetIdValue() + { + return _uid; + } -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - class extensionBase - { - // Default Values - public virtual string DefaultUserid - { - get { return Environment.UserName.ToUpper(); } - } - public virtual DateTime DefaultDts - { - get { return DateTime.Now; } - } - public virtual string DefaultUsrid - { - get { return Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + #endregion -// The follwing is a sample Extension File. You can use it to create UserExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + #region ValidationRules -//namespace PatrialClass -//{ -// public partial class User -// { -// partial class Extension : extensionBase -// { -// TODO: Override automatic defaults -// public virtual string DefaultUserid -// { -// get { return Environment.UserName.ToUpper(); } -// } -// 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + protected override void AddBusinessRules() + { + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Userid", 100)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("FirstName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("MiddleName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("LastName", 50)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Suffix", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("CourtesyTitle", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("PhoneNumber", 30)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("CfgName", 8)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserLogin", 10)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserName", 32)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + ext.AddValidationRules(ValidationRules); + // TODO: Add other validation rules + // ValidationRules.AddRule(StartDateGTEndDate, "Started"); + } + // 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; + //} - } // Class + #endregion + + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Uid, ""); + //AuthorizationRules.AllowRead(Userid, ""); + //AuthorizationRules.AllowRead(FirstName, ""); + //AuthorizationRules.AllowRead(MiddleName, ""); + //AuthorizationRules.AllowRead(LastName, ""); + //AuthorizationRules.AllowRead(Suffix, ""); + //AuthorizationRules.AllowRead(CourtesyTitle, ""); + //AuthorizationRules.AllowRead(PhoneNumber, ""); + //AuthorizationRules.AllowRead(CfgName, ""); + //AuthorizationRules.AllowRead(UserLogin, ""); + //AuthorizationRules.AllowRead(UserName, ""); + //AuthorizationRules.AllowRead(Config, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Userid, ""); + //AuthorizationRules.AllowWrite(FirstName, ""); + //AuthorizationRules.AllowWrite(MiddleName, ""); + //AuthorizationRules.AllowWrite(LastName, ""); + //AuthorizationRules.AllowWrite(Suffix, ""); + //AuthorizationRules.AllowWrite(CourtesyTitle, ""); + //AuthorizationRules.AllowWrite(PhoneNumber, ""); + //AuthorizationRules.AllowWrite(CfgName, ""); + //AuthorizationRules.AllowWrite(UserLogin, ""); + //AuthorizationRules.AllowWrite(UserName, ""); + //AuthorizationRules.AllowWrite(Config, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + ext.AddAuthorizationRules(AuthorizationRules); + } + + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } + + public static bool CanDeleteObject() + { + // TODO: 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() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods + + private User() + {/* require use of factory methods */} + + public static User New() + { + if (!CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a User"); + return DataPortal.Create(); + } + + public static User Get(int _uid) + { + if (!CanGetObject()) + throw new System.Security.SecurityException("User not authorized to view a User"); + return DataPortal.Fetch(new PKCriteria(_uid)); + } + + public static void Delete(int _uid) + { + if (!CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a User"); + DataPortal.Delete(new PKCriteria(_uid)); + } + + public override User Save() + { + if (IsDeleted && !CanDeleteObject()) + throw new System.Security.SecurityException("User not authorized to remove a User"); + else if (IsNew && !CanAddObject()) + throw new System.Security.SecurityException("User not authorized to add a User"); + else if (!CanEditObject()) + throw new System.Security.SecurityException("User not authorized to update a User"); + return base.Save(); + } + + #endregion + + #region Data Access Portal + + [Serializable()] + private class PKCriteria + { + private int _uid; + public int Uid + { get { return _uid; } } + public PKCriteria(int uid) + { + _uid = uid; + } + } + // If Create needs to access DB - It should not be marked RunLocal + [RunLocal()] + private new void DataPortal_Create(object criteria) + { + + // Database Defaults + _userid = ext.DefaultUserid; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + // TODO: Add any defaults that are necessary + ValidationRules.CheckRules(); + } + + private void DataPortal_Fetch(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getUser"; + cm.Parameters.AddWithValue("@uID", criteria.Uid); + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + dr.Read(); + _uid = dr.GetInt32("UID"); + _userid = dr.GetString("UserID"); + _firstname = dr.GetString("FirstName"); + _middlename = dr.GetString("MiddleName"); + _lastname = dr.GetString("LastName"); + _suffix = dr.GetString("Suffix"); + _courtesytitle = dr.GetString("CourtesyTitle"); + _phonenumber = dr.GetString("PhoneNumber"); + _cfgname = dr.GetString("CFGName"); + _userlogin = dr.GetString("UserLogin"); + _username = dr.GetString("UserName"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + // load child objects + dr.NextResult(); + _usermemberships = UserMemberships.Get(dr); + + } + } + } + } + catch (Exception ex) + { + Database.LogException("User", ex); + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Insert() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addUser"; + // Input All Fields - Except Calculated Columns + cm.Parameters.AddWithValue("@userID", _userid); + cm.Parameters.AddWithValue("@firstName", _firstname); + cm.Parameters.AddWithValue("@middleName", _middlename); + cm.Parameters.AddWithValue("@lastName", _lastname); + cm.Parameters.AddWithValue("@suffix", _suffix); + cm.Parameters.AddWithValue("@courtesyTitle", _courtesytitle); + cm.Parameters.AddWithValue("@phoneNumber", _phonenumber); + cm.Parameters.AddWithValue("@cFGName", _cfgname); + cm.Parameters.AddWithValue("@userLogin", _userlogin); + cm.Parameters.AddWithValue("@userName", _username); + cm.Parameters.AddWithValue("@config", _config); + cm.Parameters.AddWithValue("@dTS", _dts); + cm.Parameters.AddWithValue("@usrID", _usrid); + // Output Calculated Columns + SqlParameter param_uid = new SqlParameter("@newUID", SqlDbType.Int); + param_uid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_uid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _uid = (int)cm.Parameters["@newUID"].Value; + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + // update child objects + _usermemberships.Update(this, cn); + + } + + } + catch (Exception ex) + { + Database.LogException("User", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Add(SqlConnection cn, ref int uid, string userid, string firstname, string middlename, string lastname, string suffix, string courtesytitle, string phonenumber, string cfgname, string userlogin, string username, string config, DateTime dts, string usrid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "addUser"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@userID", userid); + cm.Parameters.AddWithValue("@firstName", firstname); + cm.Parameters.AddWithValue("@middleName", middlename); + cm.Parameters.AddWithValue("@lastName", lastname); + cm.Parameters.AddWithValue("@suffix", suffix); + cm.Parameters.AddWithValue("@courtesyTitle", courtesytitle); + cm.Parameters.AddWithValue("@phoneNumber", phonenumber); + cm.Parameters.AddWithValue("@cFGName", cfgname); + cm.Parameters.AddWithValue("@userLogin", userlogin); + cm.Parameters.AddWithValue("@userName", username); + cm.Parameters.AddWithValue("@config", config); + cm.Parameters.AddWithValue("@dTS", dts); + cm.Parameters.AddWithValue("@usrID", usrid); + // Output Calculated Columns + SqlParameter param_uid = new SqlParameter("@newUID", SqlDbType.Int); + param_uid.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_uid); + SqlParameter param_lastchanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp); + param_lastchanged.Direction = ParameterDirection.Output; + cm.Parameters.Add(param_lastchanged); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + uid = (int)cm.Parameters["@newUID"].Value; + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("User", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_Update() + { + if (IsDirty)// If this is dirty - open the connection + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + if (base.IsDirty) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateUser"; + // All Fields including Calculated Fields + cm.Parameters.AddWithValue("@uID", _uid); + cm.Parameters.AddWithValue("@userID", _userid); + cm.Parameters.AddWithValue("@firstName", _firstname); + cm.Parameters.AddWithValue("@middleName", _middlename); + cm.Parameters.AddWithValue("@lastName", _lastname); + cm.Parameters.AddWithValue("@suffix", _suffix); + cm.Parameters.AddWithValue("@courtesyTitle", _courtesytitle); + cm.Parameters.AddWithValue("@phoneNumber", _phonenumber); + cm.Parameters.AddWithValue("@cFGName", _cfgname); + cm.Parameters.AddWithValue("@userLogin", _userlogin); + cm.Parameters.AddWithValue("@userName", _username); + cm.Parameters.AddWithValue("@config", _config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + _lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + // use the open connection to update child objects + _usermemberships.Update(this, cn); + } + } + catch (Exception ex) + { + Database.LogException("User", ex); + } + + } + } + + + [Transactional(TransactionalTypes.TransactionScope)] + public static byte[] Update(SqlConnection cn, ref int uid, string userid, string firstname, string middlename, string lastname, string suffix, string courtesytitle, string phonenumber, string cfgname, string userlogin, string username, string config, DateTime dts, string usrid, ref byte[] lastchanged) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "updateUser"; + // Input All Fields - Except Calculated Columns + + cm.Parameters.AddWithValue("@uID", uid); + cm.Parameters.AddWithValue("@userID", userid); + cm.Parameters.AddWithValue("@firstName", firstname); + cm.Parameters.AddWithValue("@middleName", middlename); + cm.Parameters.AddWithValue("@lastName", lastname); + cm.Parameters.AddWithValue("@suffix", suffix); + cm.Parameters.AddWithValue("@courtesyTitle", courtesytitle); + cm.Parameters.AddWithValue("@phoneNumber", phonenumber); + cm.Parameters.AddWithValue("@cFGName", cfgname); + cm.Parameters.AddWithValue("@userLogin", userlogin); + cm.Parameters.AddWithValue("@userName", username); + cm.Parameters.AddWithValue("@config", config); + 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); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + // Save all values being returned from the Procedure + return (byte[])cm.Parameters["@newLastChanged"].Value; + } + } + catch (Exception ex) + { + Database.LogException("User", ex); + return null; + } + } + [Transactional(TransactionalTypes.TransactionScope)] + protected override void DataPortal_DeleteSelf() + { + DataPortal_Delete(new PKCriteria(_uid)); + } + + + [Transactional(TransactionalTypes.TransactionScope)] + private void DataPortal_Delete(PKCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteUser"; + cm.Parameters.AddWithValue("@uID", criteria.Uid); + cm.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + Database.LogException("User", ex); + } + } + + [Transactional(TransactionalTypes.TransactionScope)] + public static void Remove(SqlConnection cn, int uid) + { + try + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "deleteUser"; + // Input PK Fields + + cm.Parameters.AddWithValue("@uID", uid); + // TODO: Define any additional output parameters + cm.ExecuteNonQuery(); + } + } + catch (Exception ex) + { + Database.LogException("User", ex); + } + } + + #endregion + + #region Exists + + + public static bool Exists(int uid) + { + ExistsCommand result; + result = DataPortal.Execute + (new ExistsCommand(uid)); + return result.Exists; + } + + [Serializable()] + private class ExistsCommand : CommandBase + { + + private int _uid; + private bool _exists; + + public bool Exists + { + get { return _exists; } + } + + public ExistsCommand(int uid) + { + _uid = uid; + } + + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + cn.Open(); + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "existsUser"; + + cm.Parameters.AddWithValue("@uID", _uid); + int count = (int)cm.ExecuteScalar(); + _exists = (count > 0); + } + } + } + catch (Exception ex) + { + Database.LogException("User", ex); + } + } + } + + #endregion + + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + class extensionBase + { + // Default Values + public virtual string DefaultUserid + { + get { return Environment.UserName.ToUpper(); } + } + public virtual DateTime DefaultDts + { + get { return DateTime.Now; } + } + public virtual string DefaultUsrid + { + get { return Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create UserExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class User + // { + // partial class Extension : extensionBase + // { + // TODO: Override automatic defaults + // public virtual string DefaultUserid + // { + // get { return Environment.UserName.ToUpper(); } + // } + // 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/UserInfo.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/UserInfo.cs index eb44bc05..a3493665 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/UserInfo.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/UserInfo.cs @@ -17,223 +17,209 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// UserInfo Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class UserInfo : ReadOnlyBase - { - #region Business Methods - - - private int _uid; - [System.ComponentModel.DataObjectField(true, true)] - public int Uid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _uid; - } - } - private string _userid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Userid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _userid; - } - } - private string _firstname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string FirstName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _firstname; - } - } - private string _middlename=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string MiddleName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _middlename; - } - } - private string _lastname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string LastName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _lastname; - } - } - private string _suffix=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Suffix - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _suffix; - } - } - private string _courtesytitle=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string CourtesyTitle - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _courtesytitle; - } - } - private string _phonenumber=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string PhoneNumber - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _phonenumber; - } - } - private string _cfgname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string CfgName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _cfgname; - } - } - private string _userlogin=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string UserLogin - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _userlogin; - } - } - private string _username=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string UserName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _username; - } - } - private string _config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _config; - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - } - // TODO: Replace base UserInfo.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current UserInfo - //public override string ToString() - //{ - // return base.ToString(); - //} - - // TODO: Check UserInfo.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current UserInfo - protected override object GetIdValue() - { - return _uid; - } - - - #endregion - #region Factory Methods - private UserInfo() - { /* require use of factory methods */ } - - #endregion - #region Data Access Portal - - internal UserInfo(SafeDataReader dr) + /// + /// UserInfo Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class UserInfo : ReadOnlyBase { - try - { - _uid = dr.GetInt32("UID"); - _userid = dr.GetString("UserID"); - _firstname = dr.GetString("FirstName"); - _middlename = dr.GetString("MiddleName"); - _lastname = dr.GetString("LastName"); - _suffix = dr.GetString("Suffix"); - _courtesytitle = dr.GetString("CourtesyTitle"); - _phonenumber = dr.GetString("PhoneNumber"); - _cfgname = dr.GetString("CFGName"); - _userlogin = dr.GetString("UserLogin"); - _username = dr.GetString("UserName"); - _config = dr.GetString("Config"); - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - } - catch(Exception ex) - { - Database.LogException("UserInfo",ex); - } - } + #region Business Methods - #endregion - } // Class + + private int _uid; + [System.ComponentModel.DataObjectField(true, true)] + public int Uid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _uid; + } + } + private string _userid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Userid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _userid; + } + } + private string _firstname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string FirstName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _firstname; + } + } + private string _middlename = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string MiddleName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _middlename; + } + } + private string _lastname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string LastName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _lastname; + } + } + private string _suffix = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Suffix + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _suffix; + } + } + private string _courtesytitle = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string CourtesyTitle + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _courtesytitle; + } + } + private string _phonenumber = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string PhoneNumber + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _phonenumber; + } + } + private string _cfgname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string CfgName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _cfgname; + } + } + private string _userlogin = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string UserLogin + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _userlogin; + } + } + private string _username = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string UserName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _username; + } + } + private string _config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _config; + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + } + // TODO: Replace base UserInfo.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current UserInfo + //public override string ToString() + //{ + // return base.ToString(); + //} + + // TODO: Check UserInfo.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current UserInfo + protected override object GetIdValue() + { + return _uid; + } + + + #endregion + #region Factory Methods + private UserInfo() + { /* require use of factory methods */ } + + #endregion + #region Data Access Portal + + internal UserInfo(SafeDataReader dr) + { + try + { + _uid = dr.GetInt32("UID"); + _userid = dr.GetString("UserID"); + _firstname = dr.GetString("FirstName"); + _middlename = dr.GetString("MiddleName"); + _lastname = dr.GetString("LastName"); + _suffix = dr.GetString("Suffix"); + _courtesytitle = dr.GetString("CourtesyTitle"); + _phonenumber = dr.GetString("PhoneNumber"); + _cfgname = dr.GetString("CFGName"); + _userlogin = dr.GetString("UserLogin"); + _username = dr.GetString("UserName"); + _config = dr.GetString("Config"); + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + } + catch (Exception ex) + { + Database.LogException("UserInfo", ex); + } + } + + #endregion + } // Class } // Namespace diff --git a/PROMS/VEPROMS_Security/Volian.Object.Library/UserMembership.cs b/PROMS/VEPROMS_Security/Volian.Object.Library/UserMembership.cs index 257cbe67..89cd4296 100644 --- a/PROMS/VEPROMS_Security/Volian.Object.Library/UserMembership.cs +++ b/PROMS/VEPROMS_Security/Volian.Object.Library/UserMembership.cs @@ -17,496 +17,481 @@ using Csla.Data; namespace Volian.Object.Library { - /// - /// UserMembership Generated by MyGeneration using the CSLA Object Mapping template - /// - [Serializable()] - public partial class UserMembership : BusinessBase - { - #region Business Methods - - - private int _ugid; - [System.ComponentModel.DataObjectField(true, true)] - public int Ugid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _ugid; - } - } - private int _gid; - [System.ComponentModel.DataObjectField(true, true)] - public int Gid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _gid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_gid != value) - { - _gid = value; - PropertyHasChanged(); - } - } - } - private string _startdate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string StartDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _startdate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _startdate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_startdate != tmp.ToShortDateString()) - { - _startdate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private string _enddate=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string EndDate - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _enddate; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - _enddate = value; - try - { - DateTime tmp = SmartDate.StringToDate(value); - if (_enddate != tmp.ToShortDateString()) - { - _enddate = tmp.ToShortDateString(); - // TODO: Any Cross Property Validation - } - } - catch - { - } - PropertyHasChanged(); - } - } - private DateTime _dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _dts; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (_dts != value) - { - _dts = value; - PropertyHasChanged(); - } - } - } - private string _usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _usrid; - } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - set - { - CanWriteProperty(true); - if (value == null) value = string.Empty; - if (_usrid != value) - { - _usrid = value; - PropertyHasChanged(); - } - } - } - private byte[] _lastchanged=new byte[8];//timestamp - private string _group_groupname=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_GroupName - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_groupname; - } - } - private int _group_grouptype; - [System.ComponentModel.DataObjectField(true, true)] - public int Group_GroupType - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_grouptype; - } - } - private string _group_config=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_Config - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_config; - } - } - private DateTime _group_dts=new DateTime(); - [System.ComponentModel.DataObjectField(true, true)] - public DateTime Group_Dts - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_dts; - } - } - private string _group_usrid=string.Empty; - [System.ComponentModel.DataObjectField(true, true)] - public string Group_Usrid - { - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] - get - { - CanReadProperty(true); - return _group_usrid; - } - } - // TODO: Check UserMembership.GetIdValue to assure that the ID returned is unique - /// - /// Overrides Base GetIdValue - Used internally by CSLA to determine equality - /// - /// A Unique ID for the current UserMembership - protected override object GetIdValue() - { - return _ugid; - } - // TODO: Replace base UserMembership.ToString function as necessary - /// - /// Overrides Base ToString - /// - /// A string representation of current UserMembership - //public override string ToString() - //{ - // return base.ToString(); - //} - - #endregion - #region ValidationRules - - protected override void AddBusinessRules() - { - ValidationRules.AddRule(StartDateValid, "StartDate"); - ValidationRules.AddRule(EndDateValid, "EndDate"); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); - // TODO: Add other validation rules - } - - private bool StartDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_startdate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - return true; - } - private bool EndDateValid(object target, Csla.Validation.RuleArgs e) - { - try - { - DateTime tmp = SmartDate.StringToDate(_enddate); - } - catch - { - e.Description="Invalid Date"; - return false; - } - 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() - { - //TODO: Who can read/write which fields - //AuthorizationRules.AllowRead(Ugid, ""); - //AuthorizationRules.AllowRead(Gid, ""); - //AuthorizationRules.AllowWrite(Gid, ""); - //AuthorizationRules.AllowRead(StartDate, ""); - //AuthorizationRules.AllowWrite(StartDate, ""); - //AuthorizationRules.AllowRead(EndDate, ""); - //AuthorizationRules.AllowWrite(EndDate, ""); - //AuthorizationRules.AllowRead(Dts, ""); - //AuthorizationRules.AllowWrite(Dts, ""); - //AuthorizationRules.AllowRead(Usrid, ""); - //AuthorizationRules.AllowWrite(Usrid, ""); - } - - public static bool CanAddObject() - { - // TODO: Can Add Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - - public static bool CanGetObject() - { - // TODO: CanGet Authorization - return true; - } - - public static bool CanDeleteObject() - { - // TODO: 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() - { - // TODO: CanEdit Authorization - //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); - return true; - } - #endregion - #region Factory Methods - - internal static UserMembership New(int gid) + /// + /// UserMembership Generated by MyGeneration using the CSLA Object Mapping template + /// + [Serializable()] + public partial class UserMembership : BusinessBase { - return new UserMembership(Volian.Object.Library.Group.Get(gid)); - } + #region Business Methods - internal static UserMembership Get(SafeDataReader dr) - { - return new UserMembership(dr); - } - private UserMembership() - { - MarkAsChild(); - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - } + private int _ugid; + [System.ComponentModel.DataObjectField(true, true)] + public int Ugid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _ugid; + } + } + private int _gid; + [System.ComponentModel.DataObjectField(true, true)] + public int Gid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _gid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_gid != value) + { + _gid = value; + PropertyHasChanged(); + } + } + } + private string _startdate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string StartDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _startdate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _startdate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_startdate != tmp.ToShortDateString()) + { + _startdate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private string _enddate = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string EndDate + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _enddate; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + _enddate = value; + try + { + DateTime tmp = SmartDate.StringToDate(value); + if (_enddate != tmp.ToShortDateString()) + { + _enddate = tmp.ToShortDateString(); + // TODO: Any Cross Property Validation + } + } + catch + { + } + PropertyHasChanged(); + } + } + private DateTime _dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _dts; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (_dts != value) + { + _dts = value; + PropertyHasChanged(); + } + } + } + private string _usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _usrid; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + if (value == null) value = string.Empty; + if (_usrid != value) + { + _usrid = value; + PropertyHasChanged(); + } + } + } + private byte[] _lastchanged = new byte[8];//timestamp + private string _group_groupname = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_GroupName + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_groupname; + } + } + private int _group_grouptype; + [System.ComponentModel.DataObjectField(true, true)] + public int Group_GroupType + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_grouptype; + } + } + private string _group_config = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_config; + } + } + private DateTime _group_dts = new DateTime(); + [System.ComponentModel.DataObjectField(true, true)] + public DateTime Group_Dts + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_dts; + } + } + private string _group_usrid = string.Empty; + [System.ComponentModel.DataObjectField(true, true)] + public string Group_Usrid + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + return _group_usrid; + } + } + // TODO: Check UserMembership.GetIdValue to assure that the ID returned is unique + /// + /// Overrides Base GetIdValue - Used internally by CSLA to determine equality + /// + /// A Unique ID for the current UserMembership + protected override object GetIdValue() + { + return _ugid; + } + // TODO: Replace base UserMembership.ToString function as necessary + /// + /// Overrides Base ToString + /// + /// A string representation of current UserMembership + //public override string ToString() + //{ + // return base.ToString(); + //} - private UserMembership(Group group) - { - MarkAsChild(); - // TODO: Add any initialization & defaults - _startdate = ext.DefaultStartDate; - _dts = ext.DefaultDts; - _usrid = ext.DefaultUsrid; - _gid = group.Gid; - _group_groupname = group.GroupName; - _group_grouptype = group.GroupType; - _group_config = group.Config; - _group_dts = group.Dts; - _group_usrid = group.Usrid; - } + #endregion + #region ValidationRules - private UserMembership(SafeDataReader dr) - { - MarkAsChild(); - Fetch(dr); - } + protected override void AddBusinessRules() + { + ValidationRules.AddRule(StartDateValid, "StartDate"); + ValidationRules.AddRule(EndDateValid, "EndDate"); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100)); + // TODO: Add other validation rules + } - - #endregion - #region Data Access Portal + private bool StartDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_startdate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + return true; + } + private bool EndDateValid(object target, Csla.Validation.RuleArgs e) + { + try + { + DateTime tmp = SmartDate.StringToDate(_enddate); + } + catch + { + e.Description = "Invalid Date"; + return false; + } + 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; + //} - private void Fetch(SafeDataReader dr) - { - try{ - _ugid = dr.GetInt32("UGID"); - _gid = dr.GetInt32("GID"); - _startdate = dr.GetSmartDate("StartDate").Text; - _enddate = dr.GetSmartDate("EndDate").Text; - _dts = dr.GetDateTime("DTS"); - _usrid = dr.GetString("UsrID"); - dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); - _group_groupname = dr.GetString("Groups_GroupName"); - _group_grouptype = dr.GetInt32("Groups_GroupType"); - _group_config = dr.GetString("Groups_Config"); - _group_dts = dr.GetDateTime("Groups_DTS"); - _group_usrid = dr.GetString("Groups_UsrID"); - } - catch(Exception ex) - { - Database.LogException("UserMembership",ex); - } - MarkOld(); - } + #endregion - internal void Insert(User user,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Membership.Add(cn, ref _ugid, user.Uid, _gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); - MarkOld(); - } + #region Authorization Rules + protected override void AddAuthorizationRules() + { + //TODO: Who can read/write which fields + //AuthorizationRules.AllowRead(Ugid, ""); + //AuthorizationRules.AllowRead(Gid, ""); + //AuthorizationRules.AllowWrite(Gid, ""); + //AuthorizationRules.AllowRead(StartDate, ""); + //AuthorizationRules.AllowWrite(StartDate, ""); + //AuthorizationRules.AllowRead(EndDate, ""); + //AuthorizationRules.AllowWrite(EndDate, ""); + //AuthorizationRules.AllowRead(Dts, ""); + //AuthorizationRules.AllowWrite(Dts, ""); + //AuthorizationRules.AllowRead(Usrid, ""); + //AuthorizationRules.AllowWrite(Usrid, ""); + } - internal void Update(User user,SqlConnection cn) - { - // if we're not dirty then don't update the database - if (!this.IsDirty) return; - _lastchanged=Membership.Update(cn, ref _ugid, user.Uid, _gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); - MarkClean(); - } + public static bool CanAddObject() + { + // TODO: Can Add Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } - internal void DeleteSelf(User user,SqlConnection cn) - { - // 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; - Membership.Remove(cn,_ugid); - MarkNew(); - } - - #endregion -// Standard Default Code - // #region extension - Extension ext = new Extension(); - [Serializable()] - partial class Extension : extensionBase - { - } - [Serializable()] - 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 Environment.UserName.ToUpper(); } - } - // Authorization Rules - public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) - { - // Needs to be overriden to add new authorization rules - } - // Validation Rules - public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) - { - // Needs to be overriden to add new validation rules - } - } - //#endregion + public static bool CanGetObject() + { + // TODO: CanGet Authorization + return true; + } -// The follwing is a sample Extension File. You can use it to create UserMembershipExt.cs -//using System; -//using System.Collections.Generic; -//using System.Text; -//using Csla; + public static bool CanDeleteObject() + { + // TODO: 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; + } -//namespace PatrialClass -//{ -// public partial class UserMembership -// { -// partial class Extension : extensionBase -// { -// TODO: 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, ""); -// } -// public new void AddValidationRules(Csla.Validation.ValidationRules rules) -// { -// rules.AddRule( -// Csla.Validation.CommonRules.StringMaxLength, -// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); -// } -// } -// } -//} + public static bool CanEditObject() + { + // TODO: CanEdit Authorization + //return Csla.ApplicationContext.User.IsInRole("ProjectManager"); + return true; + } + #endregion + #region Factory Methods - } // Class + internal static UserMembership New(int gid) + { + return new UserMembership(Volian.Object.Library.Group.Get(gid)); + } + + internal static UserMembership Get(SafeDataReader dr) + { + return new UserMembership(dr); + } + + private UserMembership() + { + MarkAsChild(); + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + } + + private UserMembership(Group group) + { + MarkAsChild(); + // TODO: Add any initialization & defaults + _startdate = ext.DefaultStartDate; + _dts = ext.DefaultDts; + _usrid = ext.DefaultUsrid; + _gid = group.Gid; + _group_groupname = group.GroupName; + _group_grouptype = group.GroupType; + _group_config = group.Config; + _group_dts = group.Dts; + _group_usrid = group.Usrid; + } + + private UserMembership(SafeDataReader dr) + { + MarkAsChild(); + Fetch(dr); + } + + + #endregion + #region Data Access Portal + + private void Fetch(SafeDataReader dr) + { + try + { + _ugid = dr.GetInt32("UGID"); + _gid = dr.GetInt32("GID"); + _startdate = dr.GetSmartDate("StartDate").Text; + _enddate = dr.GetSmartDate("EndDate").Text; + _dts = dr.GetDateTime("DTS"); + _usrid = dr.GetString("UsrID"); + dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8); + _group_groupname = dr.GetString("Groups_GroupName"); + _group_grouptype = dr.GetInt32("Groups_GroupType"); + _group_config = dr.GetString("Groups_Config"); + _group_dts = dr.GetDateTime("Groups_DTS"); + _group_usrid = dr.GetString("Groups_UsrID"); + } + catch (Exception ex) + { + Database.LogException("UserMembership", ex); + } + MarkOld(); + } + + internal void Insert(User user, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Membership.Add(cn, ref _ugid, user.Uid, _gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid); + MarkOld(); + } + + internal void Update(User user, SqlConnection cn) + { + // if we're not dirty then don't update the database + if (!this.IsDirty) return; + _lastchanged = Membership.Update(cn, ref _ugid, user.Uid, _gid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged); + MarkClean(); + } + + internal void DeleteSelf(User user, SqlConnection cn) + { + // 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; + Membership.Remove(cn, _ugid); + MarkNew(); + } + + #endregion + // Standard Default Code + // #region extension + Extension ext = new Extension(); + [Serializable()] + partial class Extension : extensionBase + { + } + [Serializable()] + 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 Environment.UserName.ToUpper(); } + } + // Authorization Rules + public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules) + { + // Needs to be overriden to add new authorization rules + } + // Validation Rules + public virtual void AddValidationRules(Csla.Validation.ValidationRules rules) + { + // Needs to be overriden to add new validation rules + } + } + //#endregion + + // The follwing is a sample Extension File. You can use it to create UserMembershipExt.cs + //using System; + //using System.Collections.Generic; + //using System.Text; + //using Csla; + + //namespace PatrialClass + //{ + // public partial class UserMembership + // { + // partial class Extension : extensionBase + // { + // TODO: 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, ""); + // } + // public new void AddValidationRules(Csla.Validation.ValidationRules rules) + // { + // rules.AddRule( + // Csla.Validation.CommonRules.StringMaxLength, + // new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); + // } + // } + // } + //} + + } // Class } // Namespace diff --git a/PROMS/Volian.Controls.Library/DisplaySearch.cs b/PROMS/Volian.Controls.Library/DisplaySearch.cs index bd9adf04..9fc5cb6c 100644 --- a/PROMS/Volian.Controls.Library/DisplaySearch.cs +++ b/PROMS/Volian.Controls.Library/DisplaySearch.cs @@ -2712,6 +2712,17 @@ namespace Volian.Controls.Library lstCheckedStepTypes.Remove((int)sd.Index); lstCheckedStepTypesStr.Remove(advTreeStepTypes.SelectedNode.Text); } + + //B2025-012 Find Step Elements + //uncheck the parents if there are any + DevComponents.AdvTree.Node tmp_n = n; + while (tmp_n.Parent != null) + { + tmp_n = tmp_n.Parent; + tmp_n.Checked = false; + } + //uncheck All Types + advTreeStepTypes.Nodes[0].Checked = false; } //C2023-010: Check if the node has children and if we need to process those children as well @@ -2724,6 +2735,37 @@ namespace Volian.Controls.Library advTreeStepTypes_AfterCheck(sender, null); } } + else if (n.Text == "All Types") + { + //B2025-012 Find Step Elements + //if checking / un-checking All Types + //Add Types to type list appropriately + if (n.Checked) + { + foreach (Node child in advTreeStepTypes.Nodes) + { + if (child.Text != "All Types") + { + child.Checked = true; + advTreeStepTypes.SelectedNode = child; + advTreeStepTypes_AfterCheck(sender, null); + } + } + } + else + { + foreach (Node child in advTreeStepTypes.Nodes) + { + if (child.Text != "All Types") + { + child.Checked = false; + advTreeStepTypes.SelectedNode = child; + advTreeStepTypes_AfterCheck(sender, null); + } + } + } + + } buildStepTypePannelTitle();